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

Ensure getResponseHeader is case insensitive #16

Closed
gasi opened this issue Apr 30, 2014 · 3 comments
Closed

Ensure getResponseHeader is case insensitive #16

gasi opened this issue Apr 30, 2014 · 3 comments
Labels

Comments

@gasi
Copy link

gasi commented Apr 30, 2014

First of all, thanks for all the great work in XHook and XDomain 😄 I am using it with superagent and ran into a bug where superagent can’t automatically decode the response body because the response content-type is undefined. I tracked it down to a small bug in XHook as outlined below.

The getResponseHeader method should not treat headers as case sensitive. I’d suggest [normalizing, e.g. lowercasing, all response headers](:

xhook/src/xhook.coffee

Lines 121 to 134 in bb38b1e

convertHeaders = xhook.headers = (h, dest = {}) ->
switch typeof h
when "object"
headers = []
for k,v of h
headers.push "#{k}:\t#{v}"
return headers.join '\n'
when "string"
headers = h.split '\n'
for header in headers
if /([^:]+):\s*(.+)/.test(header)
dest[RegExp.$1] = RegExp.$2 if not dest[RegExp.$1]
return dest
return
) before storing them in headers.

W3C compatibility tests: https://github.com/w3c/web-platform-tests/blob/master/XMLHttpRequest/getresponseheader-case-insensitive.htm

Let me know if you need any more info and have a great day!

@jpillora
Copy link
Owner

ah yep thanks - definitely a bug - will fix when i can

@jpillora jpillora added the bug label Apr 30, 2014
@gasi
Copy link
Author

gasi commented Apr 30, 2014

Never mind, let me give it a shot 😄

gasi pushed a commit to WeTransferArchive/xhook that referenced this issue Apr 30, 2014
chore(bower): adding bower.json to fix bower installs
@gasi
Copy link
Author

gasi commented Apr 30, 2014

Pull request: #17

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

No branches or pull requests

2 participants