Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue14721] httplib doesn't specify content-length header for POST requests without data

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

May 4, 2012, 3:06 AM

Post #1 of 13 (208 views)
Permalink
[issue14721] httplib doesn't specify content-length header for POST requests without data

New submission from Arve Knudsen <arve.knudsen [at] gmail>:

httplib doesn't specify the HTTP header 'content-length' for POST requests without data. Conceptually this makes sense, considering the empty content. However, IIS (7.5) servers don't accept such requests and respond with a 411 status code. See this question on StackOverflow for reference: http://stackoverflow.com/questions/5915131/can-i-send-an-empty-http-post-webrequest-object-from-c-sharp-to-iis.

See also issue #223 of the Requests project, https://github.com/kennethreitz/requests/issues/223, which regards this problem in the context of the requests Python library.

The following code makes a data-less POST request to the HTTP sniffer Fiddler running on localhost:
import httplib
conn = httplib.HTTPConnection("localhost", 8888)
conn.request("POST", "/post", "", {})
conn.close()

Fiddler reports that it receives the following headers for the POST request, as you can see 'content-length' is not included:
POST http://localhost:8888/post HTTP/1.1
Host: localhost:8888
Accept-Encoding: identity

----------
components: Library (Lib)
messages: 159915
nosy: Arve.Knudsen
priority: normal
severity: normal
status: open
title: httplib doesn't specify content-length header for POST requests without data
versions: Python 2.7

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 4, 2012, 7:21 AM

Post #2 of 13 (187 views)
Permalink
[issue14721] httplib doesn't specify content-length header for POST requests without data [In reply to]

Jesús Cea Avión <jcea [at] jcea> added the comment:

Could you provide a patch?

Does this affect 3.x too?

----------
nosy: +jcea

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 4, 2012, 7:24 AM

Post #3 of 13 (183 views)
Permalink
[issue14721] httplib doesn't specify content-length header for POST requests without data [In reply to]

Changes by Ezio Melotti <ezio.melotti [at] gmail>:


----------
nosy: +ezio.melotti
stage: -> test needed
type: -> behavior

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 4, 2012, 7:35 AM

Post #4 of 13 (186 views)
Permalink
[issue14721] httplib doesn't specify content-length header for POST requests without data [In reply to]

Arve Knudsen <arve.knudsen [at] gmail> added the comment:

I can look into patch and 3.x tonight I think. Should I provide a test with an eventual patch?

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 4, 2012, 7:42 AM

Post #5 of 13 (183 views)
Permalink
[issue14721] httplib doesn't specify content-length header for POST requests without data [In reply to]

Jesús Cea Avión <jcea [at] jcea> added the comment:

Patch with test, please :-).

I know it is a pain in the ass, but the result is having a higher quality python.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 4, 2012, 8:20 AM

Post #6 of 13 (181 views)
Permalink
[issue14721] httplib doesn't specify content-length header for POST requests without data [In reply to]

Changes by Antoine Pitrou <pitrou [at] free>:


----------
nosy: +orsenthil
stage: test needed -> needs patch
versions: +Python 3.2, Python 3.3

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 4, 2012, 9:01 AM

Post #7 of 13 (181 views)
Permalink
[issue14721] httplib doesn't specify content-length header for POST requests without data [In reply to]

Piotr Dobrogost <pd [at] bugs> added the comment:

> Fiddler reports that it receives the following headers for the POST request

Python 3.2.3 on Windows Vista 64bit gives the same output for

import http.client
conn = http.client.HTTPConnection('localhost',8888)
conn.request("POST", "/post", "", {})
conn.close()

----------
nosy: +piotr.dobrogost

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 4, 2012, 9:37 AM

Post #8 of 13 (181 views)
Permalink
[issue14721] httplib doesn't specify content-length header for POST requests without data [In reply to]

Changes by Éric Araujo <merwok [at] netwok>:


----------
nosy: +eric.araujo

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 4, 2012, 10:23 AM

Post #9 of 13 (186 views)
Permalink
[issue14721] httplib doesn't specify content-length header for POST requests without data [In reply to]

Arve Knudsen <arve.knudsen [at] gmail> added the comment:

Which HTTP methods should we auto-define content-length for? POST and PUT? I noticed that my first attempt at a patch would define content-length also for GET requests, which broke a unit test (test_ipv6host_header).

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 4, 2012, 11:12 AM

Post #10 of 13 (189 views)
Permalink
[issue14721] httplib doesn't specify content-length header for POST requests without data [In reply to]

Arve Knudsen <arve.knudsen [at] gmail> added the comment:

Actually, when inspecting the HTTP requests sent by Chrome for the different methods (a great little Chrome app called Postman let me fire requests manually), I found that content-length would be set for most methods. I could confirm that 'content-length: 0' would be set for the following methods: POST, PUT, PATCH, DELETE and HEAD.

I guess it should be good enough to model that behaviour in httplib?

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 4, 2012, 12:12 PM

Post #11 of 13 (183 views)
Permalink
[issue14721] httplib doesn't specify content-length header for POST requests without data [In reply to]

Jesús Cea Avión <jcea [at] jcea> added the comment:

HEAD?. It doesn't make sense in HEAD if it doesn't make sense in GET.

Looking around, I found this, to mud the water a little bit more: <http://fixunix.com/tcp-ip/66198-http-rfc-related-question-content-length-0-get-request.html>.

Not being explicit about this is a "bug" in the specification, I think.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 4, 2012, 12:34 PM

Post #12 of 13 (187 views)
Permalink
[issue14721] httplib doesn't specify content-length header for POST requests without data [In reply to]

Arve Knudsen <arve.knudsen [at] gmail> added the comment:

Here's my initial proposal for a patch against httplib, based on the 2.7 branch of cpython repository. I've included a couple of tests, which check that when content is empty, content-length is set to 0 for certain methods (POST/PUT etc) and not specified for others.

----------
keywords: +patch
Added file: http://bugs.python.org/file25456/httplib-2.7.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 4, 2012, 12:34 PM

Post #13 of 13 (184 views)
Permalink
[issue14721] httplib doesn't specify content-length header for POST requests without data [In reply to]

Arve Knudsen <arve.knudsen [at] gmail> added the comment:

Yes, I agree it doesn't make much sense for HEAD AFAICT, but Chrome does it. Maybe there's a reason?

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14721>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.