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

$http ignores HTTP headers with falsy values #2984

Closed
romario333 opened this issue Jun 17, 2013 · 5 comments
Closed

$http ignores HTTP headers with falsy values #2984

romario333 opened this issue Jun 17, 2013 · 5 comments

Comments

@romario333
Copy link

$http does not send HTTP headers if they have falsy values. For example following code does not work, header is not sent.

$http(..., headers: {'Content-Version', 0})

This issue occurs at minimum in the unstable version of Angular and master.

Here is a failing test-case for $httpBackend which demonstrates the issue:

  it('should set requested headers even if they have falsy values', function() {
    $backend('POST', 'URL', null, noop, {'X-header1': 0, 'X-header2': '', 'X-header3': false});
    xhr = MockXhr.$$lastInstance;

    expect(xhr.$$reqHeaders).toEqual({
      'X-header1': 0,
      'X-header2': '',
      'X-header3': false
    });
  });
@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

@romario333
Copy link
Author

This issue persists on 1.2.0-rc1.

@btford btford reopened this Aug 28, 2013
@btford
Copy link
Contributor

btford commented Aug 28, 2013

Thanks for verifying!

@jlaine
Copy link

jlaine commented Oct 24, 2013

Before this commit you could let the browser set the Content-Type header by passing {'Content-Type': false}, but this no longer works. This is problematic when submitting FormData as multipart/form-data, because the boundary is not known in advance.

EDIT: the answer seems to be to pass {'Content-Type': undefined}

@anjianshi
Copy link

@jlaine Thank you! I just ran into this problem

jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
This is a breaking change. To migrate to the new behavior,
delete or set headers to `undefined` to avoid having them sent.
To restore the old behavior, override `$httpBackendProvider`
with the old implementation.

Closes angular#2984
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
This is a breaking change. To migrate to the new behavior,
delete or set headers to `undefined` to avoid having them sent.
To restore the old behavior, override `$httpBackendProvider`
with the old implementation.

Closes angular#2984
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants