diff --git a/README.md b/README.md index d56cf04c..41e9d77a 100644 --- a/README.md +++ b/README.md @@ -694,6 +694,13 @@ To make a release: - Add the new branch name in the `.github/workflows/rebuild.yaml` and `.github/workflows/audit.yaml` files. +## Pserve + +Pserve will not set the headers in the environment then if you are behind a reverse proxy, you will have +wrong values in client information, you can force them by using the environment variables: +`C2CWSGIUTILS_FORCE_PROTO`, `C2CWSGIUTILS_FORCE_HOST` `C2CWSGIUTILS_FORCE_SERVER_NAME` and +`C2CWSGIUTILS_FORCE_REMOTE_ADDR`. + ## Testing ### Screenshots diff --git a/c2cwsgiutils/client_info.py b/c2cwsgiutils/client_info.py index ae2bbcc7..26e6b7d1 100644 --- a/c2cwsgiutils/client_info.py +++ b/c2cwsgiutils/client_info.py @@ -1,3 +1,4 @@ +import os import re from typing import Any, Callable @@ -22,6 +23,15 @@ def __call__(self, environ: dict[str, str], start_response: Any) -> Any: else: _handle_others(environ) + if "C2CWSGIUTILS_FORCE_PROTO" in os.environ: + environ["wsgi.url_scheme"] = os.environ["C2CWSGIUTILS_FORCE_PROTO"] + if "C2CWSGIUTILS_FORCE_HOST" in os.environ: + environ["HTTP_HOST"] = os.environ["C2CWSGIUTILS_FORCE_HOST"] + if "C2CWSGIUTILS_FORCE_SERVER_NAME" in os.environ: + environ["SERVER_NAME"] = os.environ["C2CWSGIUTILS_FORCE_SERVER_NAME"] + if "C2CWSGIUTILS_FORCE_REMOTE_ADDR" in os.environ: + environ["REMOTE_ADDR"] = os.environ["C2CWSGIUTILS_FORCE_REMOTE_ADDR"] + return self._application(environ, start_response)