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.

Author Rotkraut
Recipients Rotkraut, demian.brecht, harobed, martin.panter, orsenthil, petri.lehtinen, piotr.dobrogost, pitrou, whitemice
Date 2016-06-15.08:57:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1465981087.66.0.515947090726.issue12319@psf.upfronthosting.co.za>
In-reply-to
Content
Python 3.6.0a2 has been released this week.  I guess, we need to speed up a bit.  I really would like to see this issue fixed in 3.6.0 final.

I updated Demian's patch to match the current Python sources, see the attachment.  I also addressed the issue in urllib.request.  It turned out that this was a little bit more involved then just removing the corresponding if statement from AbstractHTTPHandler.do_request_() as suggested above: if the Content-Length has been added by the lib, a caller of urllib might assume to find that header also to be set in the Request object afterwards.  At least, some tests do.

But I still believe, urllib.request should refrain from trying to calculate the content length itself, but rather rely on http.client for this, because it is crucial that the interpretation of the various body representations (buffer, file, iterable) while calculating this length matches the code in http.client that reads the body when sending it to the server.

So, I amended Demian's patch as follows:

1. change the helper _get_content_length() in http.client to a static method of HTTPConnection in order to allow urllib.request to call it.

2. review get_content_length(), there where a few issues in special cases.

3. add an optional argument encode_chunked to http.client.HTTPConnection.request().  If set to True, HTTPConnection will do the chunk encoding also if the Transfer-Encoding header is set.  This is needed, because urllib.request now sets all required headers in the request, including Transfer-Encoding if needed.  But does not handle the chunk encoding itself.

4. if the request has a non-empty body and Content-Length is not set, urllib.request.AbstractHTTPHandler calls http.client.HTTPConnection.get_content_length to calculate the content length.  If this returns None, it sets the Transfer-Encoding: chunked header.
History
Date User Action Args
2016-06-15 08:58:09Rotkrautsetrecipients: + Rotkraut, orsenthil, pitrou, harobed, petri.lehtinen, martin.panter, piotr.dobrogost, demian.brecht, whitemice
2016-06-15 08:58:07Rotkrautsetmessageid: <1465981087.66.0.515947090726.issue12319@psf.upfronthosting.co.za>
2016-06-15 08:58:07Rotkrautlinkissue12319 messages
2016-06-15 08:58:07Rotkrautcreate