Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Response headers with empty values should return empty string, not null #7779

Closed
jamshid opened this issue Jun 11, 2014 · 2 comments
Closed

Comments

@jamshid
Copy link
Contributor

jamshid commented Jun 11, 2014

If the response to a $http request contains a header but its value is empty, the value should be an empty string, not "null". Right?

I get foo == null even though X-Foo-Meta is in the response headers.

$http.get("/validate")
   .success(function(respBody, status, respHeaders, config) {
   $scope.foo = respHeaders('X-Foo-Meta');
   // it seems foo should be "", not null, here
   ...

The bug seems to be in angular.js v1.2.17

function headersGetter(headers) {
      ...
      return headersObj[lowercase(name)] || null;
@caitp
Copy link
Contributor

caitp commented Jun 11, 2014

The empty string is the only case where this would happen. I'm not sure that it's common for headers to have empty value fields (I'm not actually sure if it's even legal in HTTP, to be honest --- don't feel like studying poorly written technical documents regarding this at the moment!)

However, it should be trivial to make this work, if you want to send a PR for this. I think it would be small and easy to check in

@jamshid
Copy link
Contributor Author

jamshid commented Jul 14, 2014

Hi @caitp is there anything more I need to do to get this minor change in?

jamshid added a commit to jamshid/angular.js that referenced this issue Nov 17, 2014
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
@pkozlowski-opensource pkozlowski-opensource self-assigned this Nov 17, 2014
jamshid added a commit to jamshid/angular.js that referenced this issue Nov 18, 2014
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
jamshid added a commit to jamshid/angular.js that referenced this issue Nov 18, 2014
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
caitp pushed a commit to caitp/angular.js that referenced this issue Nov 18, 2014
Fix response headers with an empty value Empty response header values are legal
(http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html).

The headers getter fn will now only return null if the header property is not an own property.

Closes angular#7779
@caitp caitp closed this as completed in 637c020 Nov 18, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.