-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($http): fix response headers with an empty value #7792
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 #7779
@@ -549,6 +549,12 @@ describe('$http', function() { | |||
}); | |||
|
|||
|
|||
it('getter function should allow headers without value', function() { | |||
// I don't know how to fix: 'headersGetter' is not defined. |
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're better off having your test somewhere here. And instead of testing the headersGetter
, try testing something similar to the actual code the user will write, so with $httpBackend and a $http call.
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
I don't think the build failures are related to my changes, but let me know. "grunt test" passes for me. |
@@ -48,7 +48,8 @@ function headersGetter(headers) { | |||
if (!headersObj) headersObj = parseHeaders(headers); | |||
|
|||
if (name) { | |||
return headersObj[lowercase(name)] || null; | |||
name = lowercase(name); | |||
return name in headersObj ? 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.
I don't totally like this form. 'constructor' in {} === true
, and some browsers have weird things in Object.prototype which you wouldn't expect (like watch
, unwatch
in Firefox). These don't frequently hit header names, but they definitely could, so I say use hasOwnProperty.call(headersObj, name)
instead.
02dc2aa
to
fd2d6c0
Compare
cad9560
to
f294244
Compare
e8dc429
to
e83fab9
Compare
4dd5a20
to
998c61c
Compare
While this is not very frequent and kind of corner case it is still a valid issue and a fix is easy so I guess we still should fix it. @jamshid do you still want to put some effort into this one and:
If not I can quickly put together an alternative patch. |
sure, will try to get it done later today |
Closing this one - we are going to merge #10091 |
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