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 Oct 14, 2024
1 parent f3183f2 commit 270055c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ A few other environment variables can be used to tune the info sent with each re

# Developer info

You will need `docker` (>=1.12.0), `docker-compose` (>=1.10.0) and
You will need `docker` (>=1.12.0), `docker compose` and
`make` installed on the machine to play with this project.
Check available versions of `docker-engine` with
`apt-get policy docker-engine` and eventually force install the
Expand Down Expand Up @@ -699,6 +699,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:
os.environ["wsgi.url_scheme"] = os.environ.pop("C2CWSGIUTILS_FORCE_PROTO")
if "C2CWSGIUTILS_FORCE_HOST" in os.environ:
os.environ["HTTP_HOST"] = os.environ.pop("C2CWSGIUTILS_FORCE_HOST")
if "C2CWSGIUTILS_FORCE_SERVER_NAME" in os.environ:
os.environ["SERVER_NAME"] = os.environ.pop("C2CWSGIUTILS_FORCE_SERVER_NAME")
if "C2CWSGIUTILS_FORCE_REMOTE_ADDR" in os.environ:
os.environ["REMOTE_ADDR"] = os.environ.pop("C2CWSGIUTILS_FORCE_REMOTE_ADDR")

return self._application(environ, start_response)


Expand Down

0 comments on commit 270055c

Please sign in to comment.