id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 20147 Provide an alternative to request.META for accessing HTTP headers Luke Plant Santiago Basulto "From the docs: > `HttpRequest.META` > A standard Python dictionary containing all available HTTP headers... > > With the exception of CONTENT_LENGTH and CONTENT_TYPE, as given above, any HTTP headers in the request are converted to META keys by converting all characters to uppercase, replacing any hyphens with underscores and adding an HTTP_ prefix to the name. So, for example, a header called X-Bender would be mapped to the META key HTTP_X_BENDER. The question is, why? Why do we have this ridiculous transform? It is pure silliness, whose only explanation is a quirk of CGI, which is now totally irrelevant. You should be able to look up a header in the HTTP spec and do something very simple to get it from the HTTP request. How about this API: {{{ request.HEADERS['Host'] }}} (for consistency with GET/POST/FILES etc.), or even {{{ request['Host'] }}} Dictionary access should obey HTTP rules about case-sensitivity of the header names. This also would has the advantage that `repr(request)` wouldn't have lots of junk you don't need i.e. the entire content of `os.environ`, which, on a developer machine especially, can have a '''lot''' of noise (mine does). It also future-proofs us for when WSGI is replaced with something more sensible, and the whole silly round trip to `os.environ` can be removed completely, or if we want to support something else parallel to WSGI and client code wants to access HTTP headers in the same way for both. This leaves a few things in META that are not derived from an HTTP header, and do not have a way of accessing them from the request object. I think these are just: * SCRIPT_NAME - this is a CGI leftover, that is only useful in constructing other things, AFAICS * QUERY_STRING - this can be easily constructed from `request.get_full_path()` for the rare times that you need the raw query string rather than request.GET * SERVER_NAME - should use get_host() instead * SERVER_PORT - use get_host() * SERVER_PROTOCOL - could use is_secure(), but perhaps it would be nice to have a convenience `get_protocol()` method. (see http://wsgi.readthedocs.org/en/latest/definitions.html) " New feature closed HTTP handling dev Normal fixed marc.tamlyn@… tom@… ben@… Zach Borboa Santiago Basulto Accepted 1 0 0 0 0 0