File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed
Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -399,6 +399,9 @@ describe('Observable.ajax', () => {
399399
400400 expect ( MockXMLHttpRequest . mostRecent . url ) . to . equal ( '/flibbertyJibbet' ) ;
401401 expect ( MockXMLHttpRequest . mostRecent . data ) . to . deep . equal ( body ) ;
402+ expect ( MockXMLHttpRequest . mostRecent . requestHeaders ) . to . deep . equal ( {
403+ 'X-Requested-With' : 'XMLHttpRequest' ,
404+ } ) ;
402405 } ) ;
403406
404407 it ( 'should not fail when FormData is undefined' , ( ) => {
@@ -552,4 +555,3 @@ describe('Observable.ajax', () => {
552555 } ) ;
553556 } ) ;
554557} ) ;
555-
Original file line number Diff line number Diff line change @@ -198,7 +198,7 @@ export class AjaxSubscriber<T> extends Subscriber<Event> {
198198 }
199199
200200 // ensure content type is set
201- if ( ! ( 'Content-Type' in headers ) ) {
201+ if ( ! ( 'Content-Type' in headers ) && ! ( root . FormData && request . body instanceof root . FormData ) ) {
202202 headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded; charset=UTF-8' ;
203203 }
204204
@@ -271,23 +271,27 @@ export class AjaxSubscriber<T> extends Subscriber<Event> {
271271 }
272272 }
273273
274- private serializeBody ( body : any , contentType : string ) {
274+ private serializeBody ( body : any , contentType ? : string ) {
275275 if ( ! body || typeof body === 'string' ) {
276276 return body ;
277277 } else if ( root . FormData && body instanceof root . FormData ) {
278278 return body ;
279279 }
280280
281- const splitIndex = contentType . indexOf ( ';' ) ;
282- if ( splitIndex !== - 1 ) {
283- contentType = contentType . substring ( 0 , splitIndex ) ;
281+ if ( contentType ) {
282+ const splitIndex = contentType . indexOf ( ';' ) ;
283+ if ( splitIndex !== - 1 ) {
284+ contentType = contentType . substring ( 0 , splitIndex ) ;
285+ }
284286 }
285287
286288 switch ( contentType ) {
287289 case 'application/x-www-form-urlencoded' :
288290 return Object . keys ( body ) . map ( key => `${ encodeURI ( key ) } =${ encodeURI ( body [ key ] ) } ` ) . join ( '&' ) ;
289291 case 'application/json' :
290292 return JSON . stringify ( body ) ;
293+ default :
294+ return body ;
291295 }
292296 }
293297
You can’t perform that action at this time.
0 commit comments