refactor(Http): implement Request object parameter for http.request

Fixes #2416
This commit is contained in:
Jeff Cross
2015-06-13 16:44:32 -07:00
parent b68e561c0f
commit 70ffd267f8
2 changed files with 33 additions and 7 deletions

View File

@ -61,8 +61,12 @@ function httpRequest(backend: XHRBackend, request: Request) {
export class Http {
constructor(private backend: XHRBackend, private defaultOptions: BaseRequestOptions) {}
request(url: string, options?: RequestOptions): Rx.Observable<Response> {
return httpRequest(this.backend, new Request(url, this.defaultOptions.merge(options)));
request(url: string|Request, options?: RequestOptions): Rx.Observable<Response> {
if (typeof url === 'string') {
return httpRequest(this.backend, new Request(url, this.defaultOptions.merge(options)));
} else if (url instanceof Request) {
return httpRequest(this.backend, url);
}
}
get(url: string, options?: RequestOptions) {
@ -107,7 +111,11 @@ if (Rx.hasOwnProperty('default')) {
Observable = Rx.Observable;
}
export function HttpFactory(backend: XHRBackend, defaultOptions: BaseRequestOptions) {
return function(url: string, options?: RequestOptions) {
return httpRequest(backend, new Request(url, defaultOptions.merge(options)));
return function(url: string | Request, options?: RequestOptions) {
if (typeof url === 'string') {
return httpRequest(backend, new Request(url, defaultOptions.merge(options)));
} else if (url instanceof Request) {
return httpRequest(backend, url);
}
}
}