Handling HTTP chunked encoding with django

前端 未结 2 1659
说谎
说谎 2021-02-09 03:32

I have a problem handeling http chunked transfer encoding.

I\'m using:

  • apache.
  • mod_wsgi plugin.
  • django.

django, is only

2条回答
  •  南方客
    南方客 (楼主)
    2021-02-09 03:41

    Now everything works smoothly, the problem was in the daemon mode, as it doesn't work with chunked http traffic, may be in mod_wsgi 4 -- as per Graham Dumpleton. So, if you have this problem switch mod_wsgi to embedded mode.

    As a modification to the Graham's code in the wsgi wrapper, there are 2 options where you can read the stream buffered in an environment variable:

    First one:

    try:
        while True:
            data+= stream.next()
    except:
        print 'Done with reading the stream ...'
    

    Second one:

    try:
       data+= stream.read()
    except:
       print 'Done with reading the stream ...' 
    

    the first code stub, was able to read the buffer in daemon mode but stopped somewhere, and the program didn't continue operational (which confused me a bit, as I expected to see it working nicely), while the other code stub, crashed with an IOError, and only worked in embedded mode.

    One more thing to add, upgrading from 3.3 to 3.4 didn't solve the problem, so you have to swtich to embedded mode.

    Those are my results and observations. If you have any comments, additions, or corrections, please don't hesitate.

    Thanks!

提交回复
热议问题