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

Fix getHeader to be case-insensitive #196

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

atensoftware
Copy link
Contributor

What?

www.campman.com returns the "X-BC-ApiLimit-Remaining" header in all lower-case, like "x-bc-apilimit-remaining". The getRequestsRemaining API can not find the header, and always returns 0. I patched the getHeader function so it will look for the header key using a case-insensitive search, if it can't find an exact match using the hash lookup. Now, getRequestsRemaining returns the expected number of API requests remaining. Note that RFC2616 states that field names in the HTTP header are case-insensitive, so this is the correct thing to do.

Tickets / Documentation

Screenshots (if appropriate)

www.campman.com returns the  "X-BC-ApiLimit-Remaining" header in all lower-case, like "x-bc-apilimit-remaining".   The getRequestsRemaining can not find the header, and returns 0 as the limit every time.  I patched the getHeader function so it will look for the header key using a case-insensitive search, if it can't find an exact match using the hash lookup.  Now, getRequestsRemaining returns the expected number of API requests remaining.  Note that RFC2616 states that field names in the HTTP header are case-insensitive, so this is the correct thing to do.
@coveralls
Copy link

coveralls commented Apr 14, 2017

Coverage Status

Coverage decreased (-0.6%) to 67.703% when pulling 86ac739 on atensoftware:patch-1 into 7d1504f on bigcommerce:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 67.703% when pulling 86ac739 on atensoftware:patch-1 into 7d1504f on bigcommerce:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 67.703% when pulling 86ac739 on atensoftware:patch-1 into 7d1504f on bigcommerce:master.

@lord2800
Copy link
Contributor

Can we simply lowercase the header as it comes in before we insert it into the header map, and lowercase the input before we check for the key's existence? That way we save a loop and the code retains its simple clarity.

@atensoftware
Copy link
Contributor Author

atensoftware commented Apr 18, 2017 via email

@lord2800
Copy link
Contributor

If headers are always case-insensitive anyway, I don't see a problem with breaking the behavior of getHeaders returning case-sensitive. We should fix up those places anyway.

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

Successfully merging this pull request may close these issues.

4 participants