Skip to content

Commit

Permalink
Fix unexpected client_info error
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Oct 24, 2024
1 parent 35eb6f7 commit 4d495b9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion c2cwsgiutils/client_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import logging
import re
from typing import Any, Callable

_LOG = logging.getLogger(__name__)
SEP_RE = re.compile(r", *")


Expand Down Expand Up @@ -67,7 +69,12 @@ def _handle_forwarded(environ: dict[str, str]) -> None:
if "HTTP_" + header in environ:
environ["HTTP_ORIGINAL_" + header] = environ.pop("HTTP_" + header)
forwarded = SEP_RE.split(environ.pop("HTTP_FORWARDED"))[0]
fields = dict(tuple(f.split("=", maxsplit=1)) for f in forwarded.split(";"))
parts = [forwarded.split(";")]
ignored_parts = [part for part in parts if "=" not in part]
if ignored_parts:
_LOG.warning("Some parts of the Forwarded header are ignored: %s", ignored_parts)
parts = [part for part in parts if "=" in part]
fields = dict(tuple(f.split("=", maxsplit=1)) for f in parts)
if "by" in fields:
environ["SERVER_NAME"] = fields["by"]
if "for" in fields:
Expand Down

0 comments on commit 4d495b9

Please sign in to comment.