bear
bear

Reputation: 123

Get raw request headers in django

Is there any way to get the full unprocessed HTTP request headers in django (hosted on elastic beanstalk?)

I would like to be able to analyze the ordering of the headers in particular, so unfortunately HttpRequest.META does not suffice for my use case.

Upvotes: 4

Views: 2615

Answers (1)

solarissmoke
solarissmoke

Reputation: 31404

No - you cannot do this at the Django level. The contents of HttpRequest.META are obtained directly from the WSGI handler. The structure of this object is defined in the WSGI specification.

The request headers are a dict even before Django gets anywhere near them - your WSGI handler (uwsgi/gunicorn/weurkzeug in development) is what parses the headers and passes the dict to your Django application. Django has no knowledge of the original, raw, request headers.

The only place to get the raw request would be at web server (Nginx/Apache etc) level. I know you can log these with Nginx - although you would be logging a substantial amount of data.

Upvotes: 6

Related Questions