Skip to content

Commit 5a895e8

Browse files
elliotschijayphelps
authored andcommitted
fix(ajaxObservable): only set default Content-Type header when no body is sent (#1830)
1 parent 0035583 commit 5a895e8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

spec/observables/dom/ajax-spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ describe('Observable.ajax', () => {
141141
});
142142
});
143143

144+
it('should not set default Content-Type header when no body is sent', () => {
145+
const obj: Rx.AjaxRequest = {
146+
url: '/talk-to-me-goose',
147+
method: 'GET'
148+
};
149+
150+
Rx.Observable.ajax(obj).subscribe();
151+
152+
const request = MockXMLHttpRequest.mostRecent;
153+
154+
expect(request.url).to.equal('/talk-to-me-goose');
155+
expect(request.requestHeaders).to.not.have.keys('Content-Type');
156+
});
157+
144158
it('should error if createXHR throws', () => {
145159
let error;
146160
const obj = {

src/observable/dom/AjaxObservable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class AjaxSubscriber<T> extends Subscriber<Event> {
191191
}
192192

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

0 commit comments

Comments
 (0)