Skip to main content

Set request.META['REMOTE_ADDR'] from request.META['HTTP_X_FORWARDED_FOR']

Project description

https://travis-ci.org/PaesslerAG/django-httpxforwardedfor.svg?branch=master

Quickstart

Install django-httpxforwardedfor:

pip install django-httpxforwardedfor

Configure it in the settings of your django project:

# Make sure it is at the beginning of the list of middle-ware classes.
# Only other middle-ware classes working on the remote address should
# precede it.
MIDDLEWARE = [
    'httpxforwardedfor.middleware.HttpXForwardedForMiddleware',
] + MIDDLEWARE

# Only allow HTTP_X_FORWARDED_FOR, if the request is marked as secure.
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# To only allow change of the REMOTE_ADDR for requests via HTTPS.
# The default is to allow all requests.
TRUST_ONLY_HTTPS_PROXY = True

Release Notes

  • 0.3.1 - dropping support for Python 3.4 as it ran into EOL in March19

  • 0.3.0 - update supported versions according to https://www.djangoproject.com/download/#supported-versions and https://devguide.python.org/#status-of-python-branches

    • dropping support for Django 1.10 and Python 3.2 and 3.3

    • adding support for Python 3.7

    • adding support for Django 2.0

    • adding support for Django 2.1

  • 0.2.0 - futureproof release

    • adapt to new middleware format of django 1.10+

    • drop support for python 3.3, django < 1.10

  • 0.1.2 - initial release

    • supports Django 1.8, 1.9, 1.10, 1.11 on python 2.7, 3.3, 3.4, 3.5, and 3.6 - as per the official django docs

    • configuration to activate forwarding of header only for safe requests and trusting only https requests in general.

Contributing

As an open source project, we welcome contributions.

The code lives on github.

Reporting issues/improvements

Please open an issue on github or provide a pull request whether for code or for the documentation.

For non-trivial changes, we kindly ask you to open an issue, as it might be rejected. However, if the diff of a pull request better illustrates the point, feel free to make it a pull request anyway.

Pull Requests

  • for code changes

    • it must have tests covering the change. You might be asked to cover missing scenarios

    • the latest flake8 will be run and shouldn’t produce any warning

    • if the change is significant enough, documentation has to be provided

Setting up all Python versions

sudo apt-get -y install software-properties-common
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
for version in 3.5 3.6 3.7; do
  py=python$version
  sudo apt-get -y install ${py} ${py}-dev
done

Code of Conduct

As it is a Django extension, it follows Django’s own Code of Conduct. As there is no mailing list yet, please just email one of the main authors (see setup.py file or github contributors)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-httpxforwardedfor-0.3.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

django_httpxforwardedfor-0.3.1-py2.py3-none-any.whl (6.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-httpxforwardedfor-0.3.1.tar.gz.

File metadata

  • Download URL: django-httpxforwardedfor-0.3.1.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.18.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.14.0 CPython/2.7.6

File hashes

Hashes for django-httpxforwardedfor-0.3.1.tar.gz
Algorithm Hash digest
SHA256 029e33a129fa20c98eae40a7720697af2330316cf850c88c2691bde6b80aa93a
MD5 e35ccd6ec0f5c1448ee79e56ccd69064
BLAKE2b-256 651ce6ad03ef00a7f77f84a68b1716d5027d1de6b310184d35680f306bea7c15

See more details on using hashes here.

File details

Details for the file django_httpxforwardedfor-0.3.1-py2.py3-none-any.whl.

File metadata

  • Download URL: django_httpxforwardedfor-0.3.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.18.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.14.0 CPython/2.7.6

File hashes

Hashes for django_httpxforwardedfor-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 526dcff7eaf13215e4a06a72e893850ba5fb3d7a91fdf3e33f2c80cf1bd53cb2
MD5 c6c1e0a44dc24232b58d39944edd625b
BLAKE2b-256 ba5129e9c5ed55fc2ab0649b8258c0df24b1b98d5c651cac5857b5193758c317

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page