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.

Title: Lib/http/, inconsistent header casing
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.4
Status: closed Resolution: duplicate
Dependencies: Superseder: urllib2 forces title() on header names, breaking some requests
View: 12455
Assigned To: Nosy List: DS6, orsenthil, r.david.murray
Priority: normal Keywords:

Created on 2014-09-23 05:20 by DS6, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (8)
msg227324 - (view) Author: (DS6) Date: 2014-09-23 05:20
Inconsistent casing, such as "Content-type" vs "Content-Type", "Content-Length" vs "Content-length", while technically not breaking any RFC or other HTTP-related rules (headers are case-insensitive, after all), can occasionally cause problems when attempting to retrieve already-set headers from http.server.BaseHTTPRequestHandler._headers_buffer (in my situation specifically, trying to retrie the Content-Type header in the sendfile method in an extended BaseHTTPRequestHandler class). This happens a lot in the file and I wouldn't be surprised if the problem were to crop up in other places as well.
I'm a new user of Python, so despite having searched for an answer to this problem, if there's a case-insensitive way to obtain items from a list and I'm just daft, please feel free to point me in the right direction, though I feel that the casing should be corrected regardless for consistency and optimization sake.

(Aside: I would try to publish a patch along with this issue report with the casing issues fixed, but I'm not too knowledgeable about versioning and stuff and would have no idea where to start.)
msg227325 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2014-09-23 05:24
First thing (and the easiest is), if you find inconsistent casing in http/ itself, then make it consistent in your patch against cpython default branch (from Make it Content-Length and Content-Type in your patch.

Next part is while receiving the request with these headers, the client and server should store it in case-insensitive dict (there is open request and patch, which can churn up again and we can fix it as part of that issue).
msg227326 - (view) Author: (DS6) Date: 2014-09-23 05:34
Erp, *retrieve, and I meant copyfile, not sendfile. I'm tired.

Very quick reply, by the way.

I suppose I forgot to mention that _headers_buffer is for sending headers, not for receiving them. As far as I can read, the received header information is already case-insensitive, due to email.message.Message being used.

It also occurs to me that the _headers_buffer field probably wasn't designed to be directly accessed, seeing as how it's usually flushed immediately after being modified...
msg227366 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-09-23 15:22
It also has a leading underscore, which means it is a "private" interface and you use it at your own risk.

To the extent that there is an actionable issue here, it is a duplicate of issue 12455.  email.message already provides case insensitive header retrieval, by the way.
msg227376 - (view) Author: (DS6) Date: 2014-09-23 19:29
Whoa, I thought " - no selection - " would not change the set values, but I guess I was wrong. I have no idea what I'm doing, sorry.
msg227377 - (view) Author: (DS6) Date: 2014-09-23 19:31
Yeah, I was aware it's used for getting the request headers. It's strange that it's not used for setting reply headers, though the casing really doesn't cause any problems for the current implementation and really only affects fringe cases like mine and that fellow in issue #12455.
I suppose it would simply be wiser to rewrite my own code a bit instead of relying on private fields, since I am actually extending with my own classes instead of wholly relying on the std libs.

I appreciate the post, David, I was not aware this issue had been brought up before; I did actually search for related issues but I guess I didn't see that one.

Whoa, I thought " - no selection - " would not change the set values, but I guess I was wrong.
...And apparently duplicate messages are pruned.
I have no idea what I'm doing, sorry.
msg227378 - (view) Author: (DS6) Date: 2014-09-23 19:34
Oh... It showed that the message had been created but it really hadn't, because I had the Status field set to " - no selection - " so now I've posted two (three) times.

Good lord I am sickeningly bad at this. I'll just stop posting now.
msg227382 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-09-23 19:46
Don't worry about it :)  The roundup UI isn't terrible, but it is far from perfect.
Date User Action Args
2022-04-11 14:58:08adminsetgithub: 66657
2014-09-23 19:46:37r.david.murraysetmessages: + msg227382
2014-09-23 19:34:36DS6setmessages: + msg227378
2014-09-23 19:31:40DS6setmessages: + msg227377
2014-09-23 19:29:58DS6setmessages: + msg227376
2014-09-23 15:22:40r.david.murraysetstatus: open -> closed

superseder: urllib2 forces title() on header names, breaking some requests

nosy: + r.david.murray
messages: + msg227366
resolution: duplicate
stage: resolved
2014-09-23 05:34:35DS6setmessages: + msg227326
2014-09-23 05:24:25orsenthilsetnosy: + orsenthil
messages: + msg227325
2014-09-23 05:20:15DS6create