mod_wsgi
mod_wsgi copied to clipboard
Broken chunked transfer encoding causes hanging browsers when using apache fallbackresource
Hello, I experience the following bug: libapache2-mod-wsgi 4.3.0-1 apache2 2.4.10-10+deb8u12
Apache configuration:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/files/
<IfModule mpm_itk_module>
AssignUserId spaceone spaceone
</IfModule>
<Directory /var/www/files/>
FallbackResource /python/
</Directory>
WSGIScriptAliasMatch /python(/.*) /var/www/wsgi_test.py$1
</VirtualHost>
wsgi_test.py:
def application(environ, start_response):
status = '200 OK'
output = b'Hello \r\nWorld!'
response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
My HTTP Request:
curl 'http://localhost/asdf' -H 'Connection: keep-alive' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache' -H 'Accept-Encoding: gzip, deflate, br' -i
The returned HTTP response:
HTTP/1.1 200 OK^M
Date: Thu, 20 Dec 2018 17:13:55 GMT^M
Server: Apache/2.4.10 (Debian)^M
Vary: Accept-Encoding^M
Content-Encoding: gzip^M
Keep-Alive: timeout=5, max=100^M
Connection: Keep-Alive^M
Transfer-Encoding: chunked^M
Content-Type: text/plain^M
^M
^_<8b>^H^@^@^@^@^@^@^CòHÍÉÉWàå
Ï/ÊIQ^D^@^@^@ÿÿ^C^@<87>w<93><9d>^N^@^@^@
Error description: It seems either Apache or mod_wsgi removes my Content-Length header and replaces it with Transfer-Encoding: chunked. After this, it gzips all the content but does not wrap it into the chunked-syntax. This causes that a browser hangs forever waiting for data / unable to parse the response, as it never e.g. contains a chunked-terminator.
Ignoring the chunked encoding issue, what exactly is the overall result you are wanting to achieve by using FallbackResource?
I have never recommended to use FallbackResource with mod_wsgi because FallbackResource had various limitations as I recollect due to the way it worked. So I wouldn't trust it.
If you are trying to find a way to mix static or PHP with Python at the root of the site use the recipe at the end of the section here:
- https://modwsgi.readthedocs.io/en/develop/user-guides/configuration-guidelines.html#the-apache-alias-directive
Also, avoid using WSGIScriptAliasMatch, you usually never need it. The line:
WSGIScriptAliasMatch /python(/.*) /var/www/wsgi_test.py$1
is the effectively same as writing:
WSGIScriptAlias /python /var/www/wsgi_test.py
Even then I don't think FallbackResource works properly.
Hello Graham,
thanks for your response!
yes, I want to mix static content with my single WSGI script. Prior I did this with a RewriteCondition !-f. I was suggested to use FallbackResource by the apache support in the freenode IRC channel, so I tried it and experienced this bug. As this is broken and may happen to others, too, I wanted to report it. I think it's worth to have a look at, if it's not a mod-wsgi issue I can fill a bug report upstream.
And regarding the WSGIScriptAlias vs. Match Issue: Oh, In the beginning this didn't work for me. But it seems to work if one leaves out the trailing slash. Thanks!