Why Does Apache/wsgi Map Head To Get? How To Speed Up Head In Flask?
Solution 1:
As already noted, the issue of why mod_wsgi remaps HEAD to GET is well described in:
In particular, as explained in that blog post, if you have an Apache output filter setup and there is the chance that it therefore requires to see the same output from your WSGI application for either a GET or HEAD against the same URL, then mod_wsgi will not trust that your application does the correct thing and will remap HEAD to GET to ensure that the Apache output filter will work properly.
If you don't care that you are not returning the same response headers for a HEAD request as is for a GET request, and thus breaking the requirement for HEAD specified by the HTTP RFC, then simply ensure that you have no Apache output filters configured and you can break things as much as you like as mod_wsgi will not then remap the request method type.
Solution 2:
To create a complete response from Flask, you want to do something like this:
@app.route('/', methods=['HEAD'])
def head():
response = Response()
response.headers.add('content-length', LENGTH)
return response
That will then result in something like this:
Connected to localhost.
Escape character is'^]'.
HEAD / HTTP/1.1Host: localhost
HTTP/1.0200 OK
Content-Type: text/html; charset=utf-8
content-length: 1000000Server: Werkzeug/0.9.4 Python/2.7.6Date: Sun, 16 Mar 201422:59:16 GMT
This was tested with just the standard runner and not going through wsgi, but it shouldn't make a difference.
As for Apache/WSGI forcing the usage of the get handler, this blog entry has some hints as to why this is happening.
See: Flask/Werkzeug how to attach HTTP content-length header to file download
Post a Comment for "Why Does Apache/wsgi Map Head To Get? How To Speed Up Head In Flask?"