cobrateam / django-htmlmin

HTML minifier for Python frameworks (not only Django, despite the name).
http://pypi.python.org/pypi/django-htmlmin
BSD 2-Clause "Simplified" License
542 stars 73 forks source link

Strange issue with content length when using django cache #129

Closed dpetrov closed 5 years ago

dpetrov commented 6 years ago

I have a wagtail project which I've tested to deploy behind a nginx with both uwsgi/gunicorn. It seems like, that when the django-html is enabled either the wrong content-length is sent or somehow the clients closes the connection.

My middlewares are:

MIDDLEWARE = [
    'django.middleware.cache.UpdateCacheMiddleware',
    'htmlmin.middleware.HtmlMinifyMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',

    'wagtail.core.middleware.SiteMiddleware',
    'wagtail.contrib.redirects.middleware.RedirectMiddleware',

    'django.middleware.cache.FetchFromCacheMiddleware',
    'htmlmin.middleware.MarkRequestMiddleware',
]

when I am using uwsgi_pass and uwsgi:

curl http://myapp shows curl: (18) transfer closed with 8218 bytes remaining to read

and into the nginx.log

*372440 client closed connection while waiting for request,
... and also..
Failed (111: Connection refused) while connecting to upstream,

If I removed the caching middlewares and move htmlmin to the end, everything seems to be working as expected. Is there anything I might be missing?

Thanks

andrewsmedina commented 5 years ago

I believe that the last version (0.11) fix this problem. I will close this issue but if this problem happens with 0.11+ fell free to reopen this issue