Skip to content

Commit

Permalink
Be able to force the client information
Browse files Browse the repository at this point in the history
To be able to generate correct URL when we debug with pserve behind a
reverse proxy.
  • Loading branch information
sbrunner committed Nov 12, 2024
1 parent e933c46 commit 7279c07
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions c2cwsgiutils/client_info.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import re
from typing import Any, Callable

Expand All @@ -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)


Expand Down

0 comments on commit 7279c07

Please sign in to comment.