fix(http): respect custom Content-Type header in XHRConnection (#9131)
Fix a bug due to which setting a custom Content-Type header in the Request led to multiple Content-Types being set on the sent XMLHttpRequest: first the detected content type based on the request body, followed by the custom set content type. Fix #9130.
This commit is contained in:
parent
e1fcab777c
commit
537e99b4ea
@ -108,7 +108,7 @@ export class XHRConnection implements Connection {
|
|||||||
|
|
||||||
setDetectedContentType(req: any /** TODO #9100 */, _xhr: any /** TODO #9100 */) {
|
setDetectedContentType(req: any /** TODO #9100 */, _xhr: any /** TODO #9100 */) {
|
||||||
// Skip if a custom Content-Type header is provided
|
// Skip if a custom Content-Type header is provided
|
||||||
if (isPresent(req.headers) && isPresent(req.headers['Content-Type'])) {
|
if (isPresent(req.headers) && isPresent(req.headers.get('Content-Type'))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,6 +212,18 @@ export function main() {
|
|||||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('X-Multi', 'a,b');
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('X-Multi', 'a,b');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should skip content type detection if custom content type header is set', () => {
|
||||||
|
let headers = new Headers({'Content-Type': 'text/plain'});
|
||||||
|
let body = {test: 'val'};
|
||||||
|
let base = new BaseRequestOptions();
|
||||||
|
let connection = new XHRConnection(
|
||||||
|
new Request(base.merge(new RequestOptions({body: body, headers: headers}))),
|
||||||
|
new MockBrowserXHR());
|
||||||
|
connection.response.subscribe();
|
||||||
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/plain');
|
||||||
|
expect(setRequestHeaderSpy).not.toHaveBeenCalledWith('Content-Type', 'application/json');
|
||||||
|
});
|
||||||
|
|
||||||
it('should use object body and detect content type header to the request', () => {
|
it('should use object body and detect content type header to the request', () => {
|
||||||
var body = {test: 'val'};
|
var body = {test: 'val'};
|
||||||
var base = new BaseRequestOptions();
|
var base = new BaseRequestOptions();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user