Skip to content

Commit

Permalink
fix(ajaxObservable): only set default Content-Type header when no bod…
Browse files Browse the repository at this point in the history
…y is sent (#1830)
  • Loading branch information
elliotschi authored and jayphelps committed Jul 21, 2016
1 parent 0035583 commit 5a895e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions spec/observables/dom/ajax-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ describe('Observable.ajax', () => {
});
});

it('should not set default Content-Type header when no body is sent', () => {
const obj: Rx.AjaxRequest = {
url: '/talk-to-me-goose',
method: 'GET'
};

Rx.Observable.ajax(obj).subscribe();

const request = MockXMLHttpRequest.mostRecent;

expect(request.url).to.equal('/talk-to-me-goose');
expect(request.requestHeaders).to.not.have.keys('Content-Type');
});

it('should error if createXHR throws', () => {
let error;
const obj = {
Expand Down
2 changes: 1 addition & 1 deletion src/observable/dom/AjaxObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class AjaxSubscriber<T> extends Subscriber<Event> {
}

// ensure content type is set
if (!('Content-Type' in headers) && !(root.FormData && request.body instanceof root.FormData)) {
if (!('Content-Type' in headers) && !(root.FormData && request.body instanceof root.FormData) && typeof request.body !== 'undefined') {
headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
}

Expand Down

0 comments on commit 5a895e8

Please sign in to comment.