fix(http): convert objects passed to requests into a string (#10124)
This remove a breaking change introduced with commit #e7a8e2757b06d572f614f53b648d2fd75df370d2 where json objects passed to requests were not converted into string. BREAKING CHANGE: The behavior in this commit is the same as before PR 7260 : the objects sent with the request are converted to a string, therefore there is no need for the user to take care of the serialization. Fixes #10073
This commit is contained in:
parent
3f08efa35d
commit
83bc5c97ef
|
@ -128,7 +128,7 @@ export class Request extends Body {
|
||||||
getBody(): any {
|
getBody(): any {
|
||||||
switch (this.contentType) {
|
switch (this.contentType) {
|
||||||
case ContentType.JSON:
|
case ContentType.JSON:
|
||||||
return this.json();
|
return this.text();
|
||||||
case ContentType.FORM:
|
case ContentType.FORM:
|
||||||
return this.text();
|
return this.text();
|
||||||
case ContentType.FORM_DATA:
|
case ContentType.FORM_DATA:
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
import {afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
|
import {afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
|
||||||
import {AsyncTestCompleter, SpyObject} from '@angular/core/testing/testing_internal';
|
import {AsyncTestCompleter, SpyObject} from '@angular/core/testing/testing_internal';
|
||||||
import {BrowserXhr} from '../../src/backends/browser_xhr';
|
import {BrowserXhr} from '../../src/backends/browser_xhr';
|
||||||
|
import {Json} from '../../src/facade/lang';
|
||||||
import {XSRFStrategy} from '../../src/interfaces';
|
import {XSRFStrategy} from '../../src/interfaces';
|
||||||
import {XHRConnection, XHRBackend, CookieXSRFStrategy} from '../../src/backends/xhr_backend';
|
import {XHRConnection, XHRBackend, CookieXSRFStrategy} from '../../src/backends/xhr_backend';
|
||||||
import {provide, Injector, Injectable, ReflectiveInjector} from '@angular/core';
|
import {provide, Injector, Injectable, ReflectiveInjector} from '@angular/core';
|
||||||
|
@ -256,7 +257,7 @@ export function main() {
|
||||||
var connection = new XHRConnection(
|
var connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR());
|
new Request(base.merge(new RequestOptions({body: body}))), new MockBrowserXHR());
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(sendSpy).toHaveBeenCalledWith(body);
|
expect(sendSpy).toHaveBeenCalledWith(Json.stringify(body));
|
||||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'application/json');
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'application/json');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue