-
Notifications
You must be signed in to change notification settings - Fork 185
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
atensoftware
wants to merge
1
commit into
bigcommerce:master
Choose a base branch
from
atensoftware:patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
2 similar comments
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. |
You could do that, but then any functions that rely on getHeaders()
returning an array with the header names with case preserved would
break. Another option is to create a second header array, like
responseHeadersLowercase, with all-lower-case keys.
…On 4/14/17 12:47 PM, Jeff Hubbard wrote:
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.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#196 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ATYoR3D8kHb4xoAxxI8rsh_zyULV_nqoks5rv6MmgaJpZM4M9sa7>.
|
If headers are always case-insensitive anyway, I don't see a problem with breaking the behavior of |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)