-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($http): fix response headers with an empty value #10091
Conversation
Empty response header values are legal (http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html). Return an empty string instead of null, which is returned when the header does not exist. Closes angular#7779
expect(callback).toHaveBeenCalledOnce(); | ||
expect(callback.mostRecentCall.args[2]('custom-empty-response-Header')).toBe(''); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this change uses hasOwnProperty
, add a test for header values in the object prototype, like ToString
or Constructor
, too.
Do you mean adding a test like this?
I see, the Constructor test is failing. How do I make headersObject['Constructor'] return the header value, not the Constructor function itself?
|
Empty response header values are legal (http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html). Return an empty string instead of null, which is returned when the header does not exist. The "Constructor" test is failing, not sure how to fix. Closes angular#7779
I didn't, but I'll take another look at this (you can just ping me with PTAL in the message, it works) |
@@ -63,7 +63,8 @@ function headersGetter(headers) { | |||
if (!headersObj) headersObj = parseHeaders(headers); | |||
|
|||
if (name) { | |||
return headersObj[lowercase(name)] || null; | |||
name = lowercase(name); | |||
return Object.prototype.hasOwnProperty.call(headersObj, name) ? headersObj[name] : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use just hasOwnProperty.call()
, it's fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the test is failing on the Constructor
header --- I think the reason is we need to fix the parseHeaders
function so that it uses createMap()
instead of {}
when initializing parsed
.
EG:
parsed = createMap(); // rather than `parsed = {}`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure that will fix it and help us merge it.
Empty response header values are legal (http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html). Return an empty string instead of null, which is returned when the header does not exist. Closes angular#7779
Thanks, createMap() fixed it. Now I need to squash these 3 commits but don't know how. I did not create a "feature" branch when I first forked and made the changes, is that a necessary step? Not very familiar with git, any tips appreciated. |
you should be good with |
Did I do this right, it doesn't seem like the single squashed commit is showing up here.
|
@jamshid you would have to force-push to see your single commit here: git push origin master --force But don't worry about this too much, we can always sqash commits when merging. |
Anyways, LGTM, will land |
@jamshid I made some very minor changes to it because the |
Empty response header values are legal (http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html).
Return an empty string instead of null, which is returned when the header does not exist.
Closes #7779