Reputation: 357
How can I get raw request headers in django? I am aware of HttpRequest.META dictionary, this is not what I want, I just want the raw headers as string. Is there any way to get it?
Upvotes: 6
Views: 2940
Reputation: 86844
AFAIK, as of the existing django releases (tagged <=1.2.5), there isn't a way to get at the raw HTTP headers from the request
object.
However, looking at the source in the dev trunk (R15523) for django.http.HttpRequests, the base class for the request object exposes a file-like interface which would suggest that one would be able to get the raw headers using something like:
def dump_request_headers(request):
dump = "".join(request.xreadlines())
return HttpResponse("<pre>%s</pre>" % dump)
I have never tried this and have never seen this done before so, chances are, there may be more to it than that. Hope this points you in the right direction.
Upvotes: 2