This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: wsgiref sets Content-Length: 0 on 304 Not Modified
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: cheryl.sabella, flox, pitrou, pje, r.david.murray
Priority: normal Keywords: patch

Created on 2013-05-30 10:33 by flox, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
125e080bbe15.diff ctheune, 2014-04-15 19:01 review
762d11a72249.diff ctheune, 2014-04-15 19:02 review
Pull Requests
URL Status Linked Edit
PR 12955 open berker.peksag, 2019-04-25 22:18
Repositories containing patches
https://bitbucket.org/ctheune/cpython#3.4-18099
https://bitbucket.org/ctheune/cpython#2.7-18099
Messages (3)
msg190352 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2013-05-30 10:33
While testing wsgiref w.r.t RFC2616, I noticed that it sets the Content-Length to 0 when the application returns 304 Not Modified.

This is a violation of RFC 2616 section 10.3.5.

And the net effect is a weird bug with some browsers (tested with Chrome 27) where the resource is truncated on 304 Not Modified.
(the resource was a CSS file in that case)

This is loosely related to http://bugs.python.org/issue3839.


# How to reproduce:

def test_304():
    import time
    from email.utils import formatdate
    from wsgiref.simple_server import make_server

    def demo_app(environ, start_response):
        if 'HTTP_IF_MODIFIED_SINCE' in environ:
            start_response("304 Not Modified", [])
            return []
        headers = [('Content-Type', 'text/html; charset=utf-8'),
                   ('Last-Modified', formatdate(time.time(), usegmt=True))]
        start_response("200 OK", headers)
        return ["Hello World!"]

    httpd = make_server('127.0.0.1', 8000, demo_app)
    sa = httpd.socket.getsockname()
    print("Serving HTTP on %s port %s ..." % sa)
    httpd.serve_forever()

if __name__ == '__main__':
    test_304()
msg222146 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2014-07-02 23:12
The patch proposed by Christian addresses the issue. Good to merge.
msg317138 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-05-19 21:41
@flox declared this as 'good to merge' in 2014, but I don't believe the merge happened.

Should a PR be created for this patch?

Thanks!
History
Date User Action Args
2022-04-11 14:57:46adminsetgithub: 62299
2019-04-25 22:18:27berker.peksagsetpull_requests: + pull_request12881
2018-05-19 21:41:39cheryl.sabellasetnosy: + cheryl.sabella
messages: + msg317138
2014-07-02 23:12:09floxsetmessages: + msg222146
2014-04-15 19:06:34r.david.murraysetnosy: + r.david.murray
2014-04-15 19:06:06r.david.murraysetstage: patch review
2014-04-15 19:02:30ctheunesetfiles: + 762d11a72249.diff
2014-04-15 19:01:55ctheunesetfiles: + 125e080bbe15.diff
keywords: + patch
2014-04-15 18:58:47ctheunesethgrepos: + hgrepo236
2014-04-15 18:58:26ctheunesethgrepos: + hgrepo235
2014-04-15 15:39:19ctheunesetversions: + Python 3.5, - Python 3.3
2013-05-30 19:08:29berker.peksagsetversions: - Python 3.2
2013-05-30 10:33:28floxcreate