@@ -104,7 +104,7 @@ export class HttpClient {
104104 fetch ( input : Request | string , init ?: RequestInit ) : Promise < Response > {
105105 this ::trackRequestStart ( ) ;
106106
107- let request = this :: buildRequest ( input , init , this . defaults ) ;
107+ let request = this . buildRequest ( input , init ) ;
108108 return processRequest ( request , this . interceptors )
109109 . then ( result => {
110110 let response = null ;
@@ -122,13 +122,46 @@ export class HttpClient {
122122 } )
123123 . then ( result => {
124124 if ( Request . prototype . isPrototypeOf ( result ) ) {
125- debugger ;
126125 return this . fetch ( result ) ;
127126 }
128127 this ::trackRequestEnd ( ) ;
129128 return result ;
130129 } ) ;
131130 }
131+
132+ buildRequest ( input : string , init : RequestInit ) : Request {
133+ let defaults = this . defaults || { } ;
134+ let request ;
135+ let body ;
136+ let requestContentType ;
137+
138+ let parsedDefaultHeaders = parseHeaderValues ( defaults . headers ) ;
139+ if ( Request . prototype . isPrototypeOf ( input ) ) {
140+ request = input ;
141+ requestContentType = new Headers ( request . headers ) . get ( 'Content-Type' ) ;
142+ } else {
143+ init || ( init = { } ) ;
144+ body = init . body ;
145+ let bodyObj = body ? { body } : null ;
146+ let requestInit = Object . assign ( { } , defaults , { headers : { } } , init , bodyObj ) ;
147+ requestContentType = new Headers ( requestInit . headers ) . get ( 'Content-Type' ) ;
148+ request = new Request ( getRequestUrl ( this . baseUrl , input ) , requestInit ) ;
149+ }
150+ if ( ! requestContentType ) {
151+ if ( new Headers ( parsedDefaultHeaders ) . has ( 'content-type' ) ) {
152+ request . headers . set ( 'Content-Type' , new Headers ( parsedDefaultHeaders ) . get ( 'content-type' ) ) ;
153+ } else if ( body && isJSON ( body ) ) {
154+ request . headers . set ( 'Content-Type' , 'application/json' ) ;
155+ }
156+ }
157+ setDefaultHeaders ( request . headers , parsedDefaultHeaders ) ;
158+ if ( body && Blob . prototype . isPrototypeOf ( body ) && body . type ) {
159+ // work around bug in IE & Edge where the Blob type is ignored in the request
160+ // https://connect.microsoft.com/IE/feedback/details/2136163
161+ request . headers . set ( 'Content-Type' , body . type ) ;
162+ }
163+ return request ;
164+ }
132165}
133166
134167const absoluteUrlRegexp = / ^ ( [ a - z ] [ a - z0 - 9 + \-. ] * :) ?\/\// i ;
@@ -157,40 +190,6 @@ function parseHeaderValues(headers) {
157190 return parsedHeaders ;
158191}
159192
160- function buildRequest ( input , init ) {
161- let defaults = this . defaults || { } ;
162- let request ;
163- let body ;
164- let requestContentType ;
165-
166- let parsedDefaultHeaders = parseHeaderValues ( defaults . headers ) ;
167- if ( Request . prototype . isPrototypeOf ( input ) ) {
168- request = input ;
169- requestContentType = new Headers ( request . headers ) . get ( 'Content-Type' ) ;
170- } else {
171- init || ( init = { } ) ;
172- body = init . body ;
173- let bodyObj = body ? { body } : null ;
174- let requestInit = Object . assign ( { } , defaults , { headers : { } } , init , bodyObj ) ;
175- requestContentType = new Headers ( requestInit . headers ) . get ( 'Content-Type' ) ;
176- request = new Request ( getRequestUrl ( this . baseUrl , input ) , requestInit ) ;
177- }
178- if ( ! requestContentType ) {
179- if ( new Headers ( parsedDefaultHeaders ) . has ( 'content-type' ) ) {
180- request . headers . set ( 'Content-Type' , new Headers ( parsedDefaultHeaders ) . get ( 'content-type' ) ) ;
181- } else if ( body && isJSON ( body ) ) {
182- request . headers . set ( 'Content-Type' , 'application/json' ) ;
183- }
184- }
185- setDefaultHeaders ( request . headers , parsedDefaultHeaders ) ;
186- if ( body && Blob . prototype . isPrototypeOf ( body ) && body . type ) {
187- // work around bug in IE & Edge where the Blob type is ignored in the request
188- // https://connect.microsoft.com/IE/feedback/details/2136163
189- request . headers . set ( 'Content-Type' , body . type ) ;
190- }
191- return request ;
192- }
193-
194193function getRequestUrl ( baseUrl , url ) {
195194 if ( absoluteUrlRegexp . test ( url ) ) {
196195 return url ;
0 commit comments