Fix getHeader to be case-insensitive
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)
Coverage decreased (-0.6%) to 67.703% when pulling 86ac739ef086baf7ea10eb7b593c64fde8a290b4 on atensoftware:patch-1 into 7d1504fd6a88e3d8ce4c2a928e1428dc5269a0c9 on bigcommerce:master.
Coverage decreased (-0.6%) to 67.703% when pulling 86ac739ef086baf7ea10eb7b593c64fde8a290b4 on atensoftware:patch-1 into 7d1504fd6a88e3d8ce4c2a928e1428dc5269a0c9 on bigcommerce:master.
Coverage decreased (-0.6%) to 67.703% when pulling 86ac739ef086baf7ea10eb7b593c64fde8a290b4 on atensoftware:patch-1 into 7d1504fd6a88e3d8ce4c2a928e1428dc5269a0c9 on bigcommerce:master.
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 https://github.com/bigcommerce/bigcommerce-api-php/pull/196#issuecomment-294188918, 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 getHeaders returning case-sensitive. We should fix up those places anyway.