﻿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
15613	django.views.static.serve gives incorrect Content-Length with non-regular files	James Aylett	nobody	"Because of changes introduced related to #15281, Content-Length is currently calculated using `statobj.st_size`. This fails if serving from eg a named pipe, since st_size will be 0; user agents may then close the connection while Django is still sending the actual response data, causing a broken pipe in runserver and of course no useful data being provided to the user agent.

(Named pipes are useful during development if you're using anything that automatically preprocesses CSS or Javascript, for instance.)

The following tiny patch fixes things:

{{{

--- Django-1.3-rc-1/django/views/static.py      2011-03-02 10:40:48.000000000 +0000
+++ ENV/lib/python2.6/site-packages/django/views/static.py      2011-03-14 14:27:25.000000000 +0000
@@ -5,6 +5,7 @@
 
 import mimetypes
 import os
+import stat
 import posixpath
 import re
 import urllib
@@ -58,7 +59,8 @@
         return HttpResponseNotModified(mimetype=mimetype)
     response = HttpResponse(open(fullpath, 'rb').read(), mimetype=mimetype)
     response[""Last-Modified""] = http_date(statobj.st_mtime)
-    response[""Content-Length""] = statobj.st_size
+    if stat.S_ISREG(statobj.st_mode):
+        response[""Content-Length""] = statobj.st_size
     if encoding:
         response[""Content-Encoding""] = encoding
     return response
}}}"	Bug	closed	Uncategorized	1.3-beta	Normal	fixed			Accepted	1	0	0	0	0	0
