Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header case-sensitivity? #90

Closed
hartsock opened this issue Jul 29, 2014 · 6 comments
Closed

Header case-sensitivity? #90

hartsock opened this issue Jul 29, 2014 · 6 comments

Comments

@hartsock
Copy link
Contributor

cookie = resp.getheader('Set-Cookie') versus cookie = resp.getheader('set-cookie')

My HTTP client library under python 2 used getheader('set-cookie') this returns None when using VCRpy. Practical testing seems to indicate that in production the getheader method is case insensitive.

Is this a bug?

@kevin1024
Copy link
Owner

Is this a bug?

Afraid not.

From RFC 2616 - "Hypertext Transfer Protocol -- HTTP/1.1", paragraph 4.2, "Message Headers":

Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive.

@kevin1024
Copy link
Owner

It occurs to me when rereading this I may have misunderstood your issue, in which case feel free to reopen with some code to reproduce the issue.

@hartsock
Copy link
Contributor Author

I have a unique server that transmits set-cookie in all lower case as the header field, after doing some research, it looks like the bug is on the server not the client ... since the standard is Set-Cookie as described in documentation. I only notice this in test because some how the case gets fixed in VCRpy.

Edit:
The phrase set-cookie (all lower case) only occurs once in documentation rfc2109 ...

EDIT 2:
Note documentation....

Attributes (names) (attr) are case-insensitive. White space is
permitted between tokens. Note that while the above syntax
description shows value as optional, most attrs require them.

I think this means values such as set-cookie and Set-Cookie should be treated the same. This source thinks so tracing the source...

http/client.py#L755
headers.py#L90

It looks like at least one version of getheader may be case insensitive.

@kevin1024
Copy link
Owner

Yeah, VCR is treating headers as case-insensitive (in accordance with RFC2616) and is normalizing them (by lowercasing them) before storing them in the cassette. That's why it's "fixing" the problem for you.

@hartsock
Copy link
Contributor Author

hartsock commented Aug 1, 2014

I wrote a test that's currently failing to illustrate why this might be an issue: hartsock@a86a3f7 ... I'm not 100% certain what the correct behavior should be in this circumstance but it looks like based on the headers.py#L90 reference above vcrpy might need to lower case the name used with getheader.

@kevin1024
Copy link
Owner

I think you're right. I'll try to look into it more this weekend, but I would like VCR to be as transparent as possible when patching out httplib, including the behavior of getheader().

On Aug 1, 2014, at 12:14 PM, Shawn Hartsock notifications@github.com wrote:

I wrote a test that's currently failing to illustrate why this might be an issue: hartsock/vcrpy@a86a3f7 ... I'm not 100% certain what the correct behavior should be in this circumstance but it looks like based on the headers.py#L90 reference above vcrpy might need to lower case the name used with getheader.


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants