parent
25c2141991
commit
986abbe0b2
|
@ -109,9 +109,13 @@ export class XHRConnection implements Connection {
|
|||
|
||||
this.setDetectedContentType(req, _xhr);
|
||||
|
||||
if (req.headers != null) {
|
||||
req.headers.forEach((values, name) => _xhr.setRequestHeader(name, values.join(',')));
|
||||
if (req.headers == null) {
|
||||
req.headers = new Headers();
|
||||
}
|
||||
if (!req.headers.has('Accept')) {
|
||||
req.headers.append('Accept', 'application/json, text/plain, */*');
|
||||
}
|
||||
req.headers.forEach((values, name) => _xhr.setRequestHeader(name, values.join(',')));
|
||||
|
||||
// Select the correct buffer type to store the response
|
||||
if (req.responseType != null && _xhr.responseType != null) {
|
||||
|
|
|
@ -237,6 +237,25 @@ export function main() {
|
|||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('X-Multi', 'a,b');
|
||||
});
|
||||
|
||||
it('should attach default Accept header', () => {
|
||||
const headers = new Headers();
|
||||
const base = new BaseRequestOptions();
|
||||
const connection = new XHRConnection(
|
||||
new Request(base.merge(new RequestOptions({headers}))), new MockBrowserXHR());
|
||||
connection.response.subscribe();
|
||||
expect(setRequestHeaderSpy)
|
||||
.toHaveBeenCalledWith('Accept', 'application/json, text/plain, */*');
|
||||
});
|
||||
|
||||
it('should not override user provided Accept header', () => {
|
||||
const headers = new Headers({'Accept': 'text/xml'});
|
||||
const base = new BaseRequestOptions();
|
||||
const connection = new XHRConnection(
|
||||
new Request(base.merge(new RequestOptions({headers}))), new MockBrowserXHR());
|
||||
connection.response.subscribe();
|
||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Accept', 'text/xml');
|
||||
});
|
||||
|
||||
it('should skip content type detection if custom content type header is set', () => {
|
||||
const headers = new Headers({'Content-Type': 'text/plain'});
|
||||
const body = {test: 'val'};
|
||||
|
|
Loading…
Reference in New Issue