falcon icon indicating copy to clipboard operation
falcon copied to clipboard

set_headers(header) update case-sensitively

Open lichray opened this issue 13 years ago • 5 comments

[('date', 'Wed, 18 Sep 2013 16:18:17 GMT'),
 ('content-length', '0'),
 ('Content-Length', '0'),
 ('location', '/v1/queues/gumshoe'),
 ('server', 'WSGIServer/0.1 Python/2.7.3')]

A correct approach (I think) should be to use a CaseInsensitiveDict.

lichray avatar Sep 18 '13 18:09 lichray

Seems requests packages a sweet implementation - at least one we might be able to use as a reference.

+1 for the case-insensitive dict idea.

queertypes avatar Sep 18 '13 20:09 queertypes

I have a feeling that to enforce the stored _headers have This-Form might be a better choice; Case insensitive dict sometimes gives user unexpected behavior. We can normalize things in set_header and set_headers.

lichray avatar Sep 20 '13 22:09 lichray

So, this is only an issue when trying to overwrite a heade, correct?

If people use the helper properties (e.g., resp.content_range) then this is a non-issue. If they set things manually and make a typo i am not convinced it is Falcon's job to fix it for them. The one place this might be useful is when you have a hook or something that may be setting a header and doesn't have control over what the app is doing (maybe the hook is 3rd-party or something). In that case, it would be nice to have a way to clobber any spelling of the header, but it would need to be performant of course.

Basically, I don't think Falcon should need to do extra checks/transformations for some edge cases when most of the time it isn't a problem.

kgriffs avatar Sep 23 '13 21:09 kgriffs

If we want to do this, we could do something ala Node.js and just lowercase all the headers. So set header would simply lowercase before setting and then the case would be normalized.

kgriffs avatar Sep 24 '13 13:09 kgriffs

If we lower-case the headers, it breaks user code :(

lichray avatar Sep 30 '13 20:09 lichray