fix(http): correctly handle response body for 204 status code
closes #12830 fixes #12393
This commit is contained in:

committed by
Victor Berchet

parent
d3eff6c483
commit
a0c58a6b5c
@ -9,7 +9,6 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {AsyncTestCompleter, SpyObject, afterEach, beforeEach, beforeEachProviders, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
||||
import {__platform_browser_private__} from '@angular/platform-browser';
|
||||
|
||||
import {BrowserXhr} from '../../src/backends/browser_xhr';
|
||||
import {CookieXSRFStrategy, XHRBackend, XHRConnection} from '../../src/backends/xhr_backend';
|
||||
import {BaseRequestOptions, RequestOptions} from '../../src/base_request_options';
|
||||
@ -486,6 +485,7 @@ export function main() {
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
|
||||
it('should normalize IE\'s 1223 status code into 204',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const statusCode = 1223;
|
||||
@ -502,6 +502,22 @@ export function main() {
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
|
||||
it('should ignore response body for 204 status code',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const statusCode = 204;
|
||||
const connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.text()).toBe('');
|
||||
async.done();
|
||||
});
|
||||
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
existingXHRs[0].setResponseText('Doge');
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
|
||||
it('should normalize responseText and response',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const responseBody = 'Doge';
|
||||
|
Reference in New Issue
Block a user