简体   繁体   中英

How to get raw request headers in django?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM