Http.request doesn't care about params when url is of type Request and not string in Angular

I noticed that when calling http.request

request(url: string|Request, options?: RequestOptionsArgs): Observable<Response>

      

The parameter options?: RequestOptionsArgs

seems to be ignored if the parameter url: string|Request

is of type Request and not string. If it is of type Request, this overrides any headers set in the additional options parameter.

Angular version: 2.4.2

Can anyone confirm this? Is this intended behavior or a bug?

+3


source to share


1 answer


It seems right

 request(url: string|Request, options?: RequestOptionsArgs): Observable<Response> {
    let responseObservable: any;
    if (typeof url === 'string') {
      responseObservable = httpRequest(
          this._backend,
          new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Get, <string>url)));
    } else if (url instanceof Request) {
      responseObservable = httpRequest(this._backend, url);
    } else {
      throw new Error('First argument must be a url string or Request instance.');
    }
    return responseObservable;
  }

      



Source Code: https://github.com/angular/angular/blob/master/packages/http/src/http.ts#L113

+1


source







All Articles