feat(common): two missing features in HttpClient (#17996)

- Add params to HttpRequest API
- Add optional description to testing APIs
This commit is contained in:
Alex Rickabaugh 2017-07-07 14:56:36 -07:00 committed by Jason Aden
parent 37797e2b4e
commit c81ad9d19d
14 changed files with 487 additions and 198 deletions

View File

@ -12,7 +12,7 @@ export {HttpHeaders} from './src/headers';
export {HTTP_INTERCEPTORS, HttpInterceptor} from './src/interceptor';
export {JsonpClientBackend, JsonpInterceptor} from './src/jsonp';
export {HttpClientJsonpModule, HttpClientModule, interceptingHandler as ɵinterceptingHandler} from './src/module';
export {HttpParameterCodec, HttpParams, HttpUrlEncodingCodec} from './src/params';
export {HttpRequest} from './src/request';
export {HttpDownloadProgressEvent, HttpErrorResponse, HttpEvent, HttpEventType, HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpResponseBase, HttpSentEvent, HttpUserEvent} from './src/response';
export {HttpStandardUrlParameterCodec, HttpUrlEncodedBody, HttpUrlParameterCodec} from './src/url_encoded_body';
export {HttpXhrBackend, XhrFactory} from './src/xhr';
export {HttpXhrBackend, XhrFactory} from './src/xhr';

View File

@ -15,6 +15,7 @@ import {map} from 'rxjs/operator/map';
import {HttpHandler} from './backend';
import {HttpHeaders} from './headers';
import {HttpParams} from './params';
import {HttpRequest} from './request';
import {HttpEvent, HttpEventType, HttpResponse} from './response';
@ -27,6 +28,7 @@ function addBody<T>(
options: {
headers?: HttpHeaders,
observe?: HttpObserve,
params?: HttpParams,
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text',
withCredentials?: boolean,
},
@ -35,6 +37,7 @@ function addBody<T>(
body,
headers: options.headers,
observe: options.observe,
params: options.params,
responseType: options.responseType,
withCredentials: options.withCredentials,
};
@ -59,70 +62,75 @@ export class HttpClient {
body?: any,
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<ArrayBuffer>;
request(method: string, url: string, options: {
body?: any,
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<Blob>;
request(method: string, url: string, options: {
body?: any,
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<string>;
request(method: string, url: string, options: {
body?: any,
headers?: HttpHeaders,
params?: HttpParams,
observe: 'events',
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpEvent<ArrayBuffer>>;
request(method: string, url: string, options: {
body?: any,
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpEvent<Blob>>;
request(method: string, url: string, options: {
body?: any,
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpEvent<string>>;
request<R>(method: string, url: string, options: {
body?: any,
headers?: HttpHeaders,
observe: 'events', responseType?: 'json', withCredentials?: boolean,
observe: 'events', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpEvent<R>>;
request(method: string, url: string, options: {
body?: any,
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpResponse<ArrayBuffer>>;
request(method: string, url: string, options: {
body?: any,
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpResponse<Blob>>;
request(method: string, url: string, options: {
body?: any,
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpResponse<string>>;
request<R>(method: string, url: string, options: {
body?: any,
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<R>>;
request(method: string, url: string, options?: {
body?: any,
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<Object>;
@ -130,12 +138,14 @@ export class HttpClient {
body?: any,
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<R>;
request(method: string, url: string, options?: {
body?: any,
headers?: HttpHeaders,
params?: HttpParams,
observe?: HttpObserve,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
@ -175,6 +185,7 @@ export class HttpClient {
body?: any,
headers?: HttpHeaders,
observe?: HttpObserve,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
} = {}): Observable<any> {
@ -190,6 +201,7 @@ export class HttpClient {
// provided.
req = new HttpRequest(first, url !, options.body || null, {
headers: options.headers,
params: options.params,
// By default, JSON is assumed to be returned for all calls.
responseType: options.responseType || 'json',
withCredentials: options.withCredentials,
@ -266,73 +278,78 @@ export class HttpClient {
delete (url: string, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<ArrayBuffer>;
delete (url: string, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<Blob>;
delete (url: string, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<string>;
delete (url: string, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpEvent<ArrayBuffer>>;
delete (url: string, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpEvent<Blob>>;
delete (url: string, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpEvent<string>>;
delete (url: string, options: {
headers?: HttpHeaders,
observe: 'events', responseType?: 'json', withCredentials?: boolean,
observe: 'events', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpEvent<Object>>;
delete<T>(url: string, options: {
headers?: HttpHeaders,
observe: 'events', responseType?: 'json', withCredentials?: boolean,
observe: 'events', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpEvent<T>>;
delete (url: string, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpResponse<ArrayBuffer>>;
delete (url: string, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpResponse<Blob>>;
delete (url: string, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpResponse<string>>;
delete (url: string, options: {
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<Object>>;
delete<T>(url: string, options: {
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<T>>;
delete (url: string, options?: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<Object>;
delete<T>(url: string, options?: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<T>;
@ -344,6 +361,7 @@ export class HttpClient {
delete (url: string, options: {
headers?: HttpHeaders,
observe?: HttpObserve,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
} = {}): Observable<any> {
@ -353,73 +371,78 @@ export class HttpClient {
get(url: string, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<ArrayBuffer>;
get(url: string, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<Blob>;
get(url: string, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<string>;
get(url: string, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpEvent<ArrayBuffer>>;
get(url: string, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpEvent<Blob>>;
get(url: string, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpEvent<string>>;
get(url: string, options: {
headers?: HttpHeaders,
observe: 'events', responseType?: 'json', withCredentials?: boolean,
observe: 'events', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpEvent<Object>>;
get<T>(url: string, options: {
headers?: HttpHeaders,
observe: 'events', responseType?: 'json', withCredentials?: boolean,
observe: 'events', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpEvent<T>>;
get(url: string, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpResponse<ArrayBuffer>>;
get(url: string, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpResponse<Blob>>;
get(url: string, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpResponse<string>>;
get(url: string, options: {
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<Object>>;
get<T>(url: string, options: {
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<T>>;
get(url: string, options?: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<Object>;
get<T>(url: string, options?: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<T>;
@ -431,6 +454,7 @@ export class HttpClient {
get(url: string, options: {
headers?: HttpHeaders,
observe?: HttpObserve,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
} = {}): Observable<any> {
@ -440,73 +464,78 @@ export class HttpClient {
head(url: string, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<ArrayBuffer>;
head(url: string, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<Blob>;
head(url: string, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<string>;
head(url: string, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpEvent<ArrayBuffer>>;
head(url: string, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpEvent<Blob>>;
head(url: string, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpEvent<string>>;
head(url: string, options: {
headers?: HttpHeaders,
observe: 'events', responseType?: 'json', withCredentials?: boolean,
observe: 'events', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpEvent<Object>>;
head<T>(url: string, options: {
headers?: HttpHeaders,
observe: 'events', responseType?: 'json', withCredentials?: boolean,
observe: 'events', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpEvent<T>>;
head(url: string, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpResponse<ArrayBuffer>>;
head(url: string, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpResponse<Blob>>;
head(url: string, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpResponse<string>>;
head(url: string, options: {
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<Object>>;
head<T>(url: string, options: {
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<T>>;
head(url: string, options?: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<Object>;
head<T>(url: string, options?: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<T>;
@ -518,14 +547,15 @@ export class HttpClient {
head(url: string, options: {
headers?: HttpHeaders,
observe?: HttpObserve,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
} = {}): Observable<any> {
return this.request<any>('HEAD', url, options as any);
}
jsonp(url: string): Observable<any>;
jsonp<T>(url: string): Observable<T>;
jsonp(url: string, callbackParam: string): Observable<any>;
jsonp<T>(url: string, callbackParam: string): Observable<T>;
/**
* Constructs an `Observable` which, when subscribed, will cause a request
* with the special method `JSONP` to be dispatched via the interceptor pipeline.
@ -534,8 +564,9 @@ export class HttpClient {
* If no such interceptor is reached, then the `JSONP` request will likely be
* rejected by the configured backend.
*/
jsonp<T>(url: string): Observable<T> {
jsonp<T>(url: string, callbackParam: string): Observable<T> {
return this.request<any>('JSONP', url, {
params: new HttpParams().append(callbackParam, 'JSONP_CALLBACK'),
observe: 'body',
responseType: 'json',
});
@ -544,73 +575,78 @@ export class HttpClient {
options(url: string, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<ArrayBuffer>;
options(url: string, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<Blob>;
options(url: string, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<string>;
options(url: string, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpEvent<ArrayBuffer>>;
options(url: string, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpEvent<Blob>>;
options(url: string, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpEvent<string>>;
options(url: string, options: {
headers?: HttpHeaders,
observe: 'events', responseType?: 'json', withCredentials?: boolean,
observe: 'events', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpEvent<Object>>;
options<T>(url: string, options: {
headers?: HttpHeaders,
observe: 'events', responseType?: 'json', withCredentials?: boolean,
observe: 'events', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpEvent<T>>;
options(url: string, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpResponse<ArrayBuffer>>;
options(url: string, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpResponse<Blob>>;
options(url: string, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpResponse<string>>;
options(url: string, options: {
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<Object>>;
options<T>(url: string, options: {
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<T>>;
options(url: string, options?: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<Object>;
options<T>(url: string, options?: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<T>;
@ -622,6 +658,7 @@ export class HttpClient {
options(url: string, options: {
headers?: HttpHeaders,
observe?: HttpObserve,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
} = {}): Observable<any> {
@ -631,73 +668,78 @@ export class HttpClient {
patch(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<ArrayBuffer>;
patch(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<Blob>;
patch(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<string>;
patch(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpEvent<ArrayBuffer>>;
patch(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpEvent<Blob>>;
patch(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpEvent<string>>;
patch(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'events', responseType?: 'json', withCredentials?: boolean,
observe: 'events', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpEvent<Object>>;
patch<T>(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'events', responseType?: 'json', withCredentials?: boolean,
observe: 'events', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpEvent<T>>;
patch(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpResponse<ArrayBuffer>>;
patch(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpResponse<Blob>>;
patch(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpResponse<string>>;
patch(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<Object>>;
patch<T>(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<T>>;
patch(url: string, body: any|null, options?: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<Object>;
patch<T>(url: string, body: any|null, options?: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<T>;
@ -709,6 +751,7 @@ export class HttpClient {
patch(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe?: HttpObserve,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
} = {}): Observable<any> {
@ -718,73 +761,78 @@ export class HttpClient {
post(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<ArrayBuffer>;
post(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<Blob>;
post(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<string>;
post(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpEvent<ArrayBuffer>>;
post(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpEvent<Blob>>;
post(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpEvent<string>>;
post(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'events', responseType?: 'json', withCredentials?: boolean,
observe: 'events', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpEvent<Object>>;
post<T>(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'events', responseType?: 'json', withCredentials?: boolean,
observe: 'events', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpEvent<T>>;
post(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpResponse<ArrayBuffer>>;
post(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpResponse<Blob>>;
post(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpResponse<string>>;
post(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<Object>>;
post<T>(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<T>>;
post(url: string, body: any|null, options?: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<Object>;
post<T>(url: string, body: any|null, options?: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<T>;
@ -796,6 +844,7 @@ export class HttpClient {
post(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe?: HttpObserve,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
} = {}): Observable<any> {
@ -805,36 +854,39 @@ export class HttpClient {
put(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<ArrayBuffer>;
put(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<Blob>;
put(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<string>;
put(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpEvent<ArrayBuffer>>;
put(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpEvent<Blob>>;
put(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'events',
observe: 'events', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpEvent<string>>;
put(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'events', responseType?: 'json', withCredentials?: boolean,
observe: 'events', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpEvent<Object>>;
put<T>(url: string, body: any|null, options: {
headers?: HttpHeaders,
@ -842,36 +894,38 @@ export class HttpClient {
}): Observable<HttpEvent<T>>;
put(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'arraybuffer', withCredentials?: boolean,
}): Observable<HttpResponse<ArrayBuffer>>;
put(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'blob', withCredentials?: boolean,
}): Observable<HttpResponse<Blob>>;
put(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response',
observe: 'response', params?: HttpParams,
responseType: 'text', withCredentials?: boolean,
}): Observable<HttpResponse<string>>;
put(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<Object>>;
put<T>(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe: 'response', responseType?: 'json', withCredentials?: boolean,
observe: 'response', params?: HttpParams, responseType?: 'json', withCredentials?: boolean,
}): Observable<HttpResponse<T>>;
put(url: string, body: any|null, options?: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<Object>;
put<T>(url: string, body: any|null, options?: {
headers?: HttpHeaders,
observe?: 'body',
params?: HttpParams,
responseType?: 'json',
withCredentials?: boolean,
}): Observable<T>;
@ -883,6 +937,7 @@ export class HttpClient {
put(url: string, body: any|null, options: {
headers?: HttpHeaders,
observe?: HttpObserve,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
} = {}): Observable<any> {

View File

@ -73,7 +73,7 @@ export class JsonpClientBackend implements HttpBackend {
// callback placeholder in the URL with the name. Care has to be taken here to ensure
// a trailing &, if matched, gets inserted back into the URL in the correct place.
const callback = this.nextCallback();
const url = req.url.replace(/=JSONP_CALLBACK(&|$)/, `=${callback}$1`);
const url = req.urlWithParams.replace(/=JSONP_CALLBACK(&|$)/, `=${callback}$1`);
// Construct the <script> tag and point it at the URL.
const node = this.document.createElement('script');

View File

@ -9,11 +9,11 @@
/**
* A codec for encoding and decoding parameters in URLs.
*
* Used by `HttpUrlEncodedBody`.
* Used by `HttpParams`.
*
* @experimental
**/
export interface HttpUrlParameterCodec {
export interface HttpParameterCodec {
encodeKey(key: string): string;
encodeValue(value: string): string;
@ -22,12 +22,12 @@ export interface HttpUrlParameterCodec {
}
/**
* A `HttpUrlParameterCodec` that uses `encodeURIComponent` and `decodeURIComponent` to
* A `HttpParameterCodec` that uses `encodeURIComponent` and `decodeURIComponent` to
* serialize and parse URL parameter keys and values.
*
* @experimental
*/
export class HttpStandardUrlParameterCodec implements HttpUrlParameterCodec {
export class HttpUrlEncodingCodec implements HttpParameterCodec {
encodeKey(k: string): string { return standardEncoding(k); }
encodeValue(v: string): string { return standardEncoding(v); }
@ -38,7 +38,7 @@ export class HttpStandardUrlParameterCodec implements HttpUrlParameterCodec {
}
function paramParser(rawParams: string, codec: HttpUrlParameterCodec): Map<string, string[]> {
function paramParser(rawParams: string, codec: HttpParameterCodec): Map<string, string[]> {
const map = new Map<string, string[]>();
if (rawParams.length > 0) {
const params: string[] = rawParams.split('&');
@ -74,25 +74,24 @@ interface Update {
}
/**
* An HTTP request/response body that represents serialized parameters in urlencoded form,
* An HTTP request/response body that represents serialized parameters,
* per the MIME type `application/x-www-form-urlencoded`.
*
* This class is immuatable - all mutation operations return a new instance.
*
* @experimental
*/
export class HttpUrlEncodedBody {
export class HttpParams {
private map: Map<string, string[]>|null;
private encoder: HttpUrlParameterCodec;
private encoder: HttpParameterCodec;
private updates: Update[]|null = null;
private cloneFrom: HttpUrlEncodedBody|null = null;
private cloneFrom: HttpParams|null = null;
constructor(options: {
fromString?: string,
encoder?: HttpUrlParameterCodec,
encoder?: HttpParameterCodec,
} = {}) {
(this as any)['__HttpUrlEncodedBody'] = true;
this.encoder = options.encoder || new HttpStandardUrlParameterCodec();
this.encoder = options.encoder || new HttpUrlEncodingCodec();
this.map = !!options.fromString ? paramParser(options.fromString, this.encoder) : null;
}
@ -124,7 +123,7 @@ export class HttpUrlEncodedBody {
/**
* Get all the parameter names for this body.
*/
params(): string[] {
keys(): string[] {
this.init();
return Array.from(this.map !.keys());
}
@ -132,25 +131,19 @@ export class HttpUrlEncodedBody {
/**
* Construct a new body with an appended value for the given parameter name.
*/
append(param: string, value: string): HttpUrlEncodedBody {
return this.clone({param, value, op: 'a'});
}
append(param: string, value: string): HttpParams { return this.clone({param, value, op: 'a'}); }
/**
* Construct a new body with a new value for the given parameter name.
*/
set(param: string, value: string): HttpUrlEncodedBody {
return this.clone({param, value, op: 's'});
}
set(param: string, value: string): HttpParams { return this.clone({param, value, op: 's'}); }
/**
* Construct a new body with either the given value for the given parameter
* removed, if a value is given, or all values for the given parameter removed
* if not.
*/
delete (param: string, value?: string): HttpUrlEncodedBody {
return this.clone({param, value, op: 'd'});
}
delete (param: string, value?: string): HttpParams { return this.clone({param, value, op: 'd'}); }
/**
* Serialize the body to an encoded string, where key-value pairs (separated by `=`) are
@ -158,7 +151,7 @@ export class HttpUrlEncodedBody {
*/
toString(): string {
this.init();
return this.params()
return this.keys()
.map(key => {
const eKey = this.encoder.encodeKey(key);
return this.map !.get(key) !.map(value => eKey + '=' + this.encoder.encodeValue(value))
@ -167,8 +160,8 @@ export class HttpUrlEncodedBody {
.join('&');
}
private clone(update: Update): HttpUrlEncodedBody {
const clone = new HttpUrlEncodedBody({encoder: this.encoder});
private clone(update: Update): HttpParams {
const clone = new HttpParams({encoder: this.encoder});
clone.cloneFrom = this.cloneFrom || this;
clone.updates = (this.updates || []).concat([update]);
return clone;
@ -180,8 +173,7 @@ export class HttpUrlEncodedBody {
}
if (this.cloneFrom !== null) {
this.cloneFrom.init();
this.cloneFrom.params().forEach(
key => this.map !.set(key, this.cloneFrom !.map !.get(key) !));
this.cloneFrom.keys().forEach(key => this.map !.set(key, this.cloneFrom !.map !.get(key) !));
this.updates !.forEach(update => {
switch (update.op) {
case 'a':

View File

@ -7,6 +7,7 @@
*/
import {HttpHeaders} from './headers';
import {HttpParams} from './params';
/**
* Construction interface for `HttpRequest`s.
@ -14,7 +15,7 @@ import {HttpHeaders} from './headers';
* All values are optional and will override default values if provided.
*/
interface HttpRequestInit {
headers?: HttpHeaders, reportProgress?: boolean,
headers?: HttpHeaders, reportProgress?: boolean, params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text', withCredentials?: boolean,
}
@ -61,10 +62,6 @@ function isFormData(value: any): value is FormData {
return typeof FormData !== 'undefined' && value instanceof FormData;
}
function isUrlEncodedBody(value: any): value is Object {
return typeof value === 'object' && value['__HttpUrlEncodedBody'];
}
/**
* An outgoing HTTP request with an optional typed body.
*
@ -116,34 +113,49 @@ export class HttpRequest<T> {
*/
readonly method: string;
/**
* Outgoing URL parameters.
*/
readonly params: HttpParams;
/**
* The outgoing URL with all URL parameters set.
*/
readonly urlWithParams: string;
constructor(method: 'DELETE'|'GET'|'HEAD'|'JSONP'|'OPTIONS', url: string, init?: {
headers?: HttpHeaders,
reportProgress?: boolean,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
});
constructor(method: 'POST'|'PUT'|'PATCH', url: string, body: T|null, init?: {
headers?: HttpHeaders,
reportProgress?: boolean,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
});
constructor(method: string, url: string, body: T|null, init?: {
headers?: HttpHeaders,
reportProgress?: boolean,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
});
constructor(
method: string, public url: string, third?: T|{
method: string, readonly url: string, third?: T|{
headers?: HttpHeaders,
reportProgress?: boolean,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
}|null,
fourth?: {
headers?: HttpHeaders,
reportProgress?: boolean,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
}) {
@ -178,12 +190,41 @@ export class HttpRequest<T> {
if (!!options.headers) {
this.headers = options.headers;
}
if (!!options.params) {
this.params = options.params;
}
}
// If no headers have been passed in, construct a new HttpHeaders instance.
if (!this.headers) {
this.headers = new HttpHeaders();
}
// If no parameters have been passed in, construct a new HttpUrlEncodedParams instance.
if (!this.params) {
this.params = new HttpParams();
this.urlWithParams = url;
} else {
// Encode the parameters to a string in preparation for inclusion in the URL.
const params = this.params.toString();
if (params.length === 0) {
// No parameters, the visible URL is just the URL given at creation time.
this.urlWithParams = url;
} else {
// Does the URL already have query parameters? Look for '?'.
const qIdx = url.indexOf('?');
// There are 3 cases to handle:
// 1) No existing parameters -> append '?' followed by params.
// 2) '?' exists and is followed by existing query string ->
// append '&' followed by params.
// 3) '?' exists at the end of the url -> append params directly.
// This basically amounts to determining the character, if any, with
// which to join the URL and parameters.
const sep: string = qIdx === -1 ? '?' : (qIdx < url.length - 1 ? '&' : '');
this.urlWithParams = url + sep + params;
}
}
}
/**
@ -201,9 +242,8 @@ export class HttpRequest<T> {
typeof this.body === 'string') {
return this.body;
}
// Check whether the body is an instance of HttpUrlEncodedBody, avoiding any direct
// references to the class in order to permit it being tree-shaken.
if (isUrlEncodedBody(this.body)) {
// Check whether the body is an instance of HttpUrlEncodedParams.
if (this.body instanceof HttpParams) {
return this.body.toString();
}
// Check whether the body is an object or array, and serialize with JSON if so.
@ -244,9 +284,8 @@ export class HttpRequest<T> {
if (typeof this.body === 'string') {
return 'text/plain';
}
// `HttpUrlEncodedBody` is detected specially so as to allow it to be
// tree-shaken.
if (isUrlEncodedBody(this.body)) {
// `HttpUrlEncodedParams` has its own content-type.
if (this.body instanceof HttpParams) {
return 'application/x-www-form-urlencoded;charset=UTF-8';
}
// Arrays, objects, and numbers will be encoded as JSON.
@ -262,28 +301,38 @@ export class HttpRequest<T> {
clone(update: {
headers?: HttpHeaders,
reportProgress?: boolean,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
body?: T|null,
method?: string,
url?: string,
setHeaders?: {[name: string]: string | string[]},
setParams?: {[param: string]: string},
}): HttpRequest<T>;
clone<V>(update: {
headers?: HttpHeaders,
reportProgress?: boolean,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
body?: V|null,
method?: string,
url?: string,
setHeaders?: {[name: string]: string | string[]},
setParams?: {[param: string]: string},
}): HttpRequest<V>;
clone(update: {
headers?: HttpHeaders,
reportProgress?: boolean,
params?: HttpParams,
responseType?: 'arraybuffer'|'blob'|'json'|'text',
withCredentials?: boolean,
body?: any|null,
method?: string,
url?: string,
setHeaders?: {[name: string]: string | string[]},
setParams?: {[param: string]: string};
} = {}): HttpRequest<any> {
// For method, url, and responseType, take the current value unless
// it is overridden in the update hash.
@ -304,9 +353,10 @@ export class HttpRequest<T> {
const reportProgress =
(update.reportProgress !== undefined) ? update.reportProgress : this.reportProgress;
// Headers may need to be cloned later if they're sealed, but being
// appended to.
// Headers and params may be appended to if `setHeaders` or
// `setParams` are used.
let headers = update.headers || this.headers;
let params = update.params || this.params;
// Check whether the caller has asked to add headers.
if (update.setHeaders !== undefined) {
@ -316,10 +366,17 @@ export class HttpRequest<T> {
.reduce((headers, name) => headers.set(name, update.setHeaders ![name]), headers);
}
// Check whether the caller has asked to set params.
if (update.setParams) {
// Set every requested param.
params = Object.keys(update.setParams)
.reduce((params, param) => params.set(param, update.setParams ![param]), params);
}
// Finally, construct the new HttpRequest using the pieces from above.
return new HttpRequest(
method, url, body, {
headers, reportProgress, responseType, withCredentials,
params, headers, reportProgress, responseType, withCredentials,
});
}
}

View File

@ -83,7 +83,7 @@ export class HttpXhrBackend implements HttpBackend {
return new Observable((observer: Observer<HttpEvent<any>>) => {
// Start by setting up the XHR object with request method, URL, and withCredentials flag.
const xhr = this.xhrFactory.build();
xhr.open(req.method, req.url);
xhr.open(req.method, req.urlWithParams);
if (!!req.withCredentials) {
xhr.withCredentials = true;
}

View File

@ -110,5 +110,12 @@ export function main() {
testReq.flush('hello world');
});
});
describe('makes a JSONP request', () => {
it('with properly set method and callback', (done: DoneFn) => {
client.jsonp('/test', 'myCallback').subscribe(() => done());
backend.expectOne({method: 'JSONP', url: '/test?myCallback=JSONP_CALLBACK'})
.flush('hello world');
});
});
});
}

View File

@ -6,18 +6,18 @@
* found in the LICENSE file at https://angular.io/license
*/
import {HttpUrlEncodedBody} from '../src/url_encoded_body';
import {HttpParams} from '../src/params';
export function main() {
describe('HttpUrlEncodedBody', () => {
describe('HttpUrlEncodedParams', () => {
describe('initialization', () => {
it('should be empty at construction', () => {
const body = new HttpUrlEncodedBody();
const body = new HttpParams();
expect(body.toString()).toEqual('')
});
it('should parse an existing url', () => {
const body = new HttpUrlEncodedBody({fromString: 'a=b&c=d&c=e'});
const body = new HttpParams({fromString: 'a=b&c=d&c=e'});
expect(body.getAll('a')).toEqual(['b']);
expect(body.getAll('c')).toEqual(['d', 'e']);
});
@ -25,31 +25,31 @@ export function main() {
describe('lazy mutation', () => {
it('should allow setting parameters', () => {
const body = new HttpUrlEncodedBody({fromString: 'a=b'});
const body = new HttpParams({fromString: 'a=b'});
const mutated = body.set('a', 'c');
expect(mutated.toString()).toEqual('a=c');
});
it('should allow appending parameters', () => {
const body = new HttpUrlEncodedBody({fromString: 'a=b'});
const body = new HttpParams({fromString: 'a=b'});
const mutated = body.append('a', 'c');
expect(mutated.toString()).toEqual('a=b&a=c');
});
it('should allow deletion of parameters', () => {
const body = new HttpUrlEncodedBody({fromString: 'a=b&c=d&e=f'});
const body = new HttpParams({fromString: 'a=b&c=d&e=f'});
const mutated = body.delete('c');
expect(mutated.toString()).toEqual('a=b&e=f');
});
it('should allow chaining of mutations', () => {
const body = new HttpUrlEncodedBody({fromString: 'a=b&c=d&e=f'});
const body = new HttpParams({fromString: 'a=b&c=d&e=f'});
const mutated = body.append('e', 'y').delete('c').set('a', 'x').append('e', 'z');
expect(mutated.toString()).toEqual('a=x&e=f&e=y&e=z');
});
it('should allow deletion of one value of a parameter', () => {
const body = new HttpUrlEncodedBody({fromString: 'a=1&a=2&a=3&a=4&a=5'});
const body = new HttpParams({fromString: 'a=1&a=2&a=3&a=4&a=5'});
const mutated = body.delete('a', '2').delete('a', '4');
expect(mutated.getAll('a')).toEqual(['1', '3', '5']);
});
@ -57,20 +57,15 @@ export function main() {
describe('read operations', () => {
it('should give null if parameter is not set', () => {
const body = new HttpUrlEncodedBody({fromString: 'a=b&c=d'});
const body = new HttpParams({fromString: 'a=b&c=d'});
expect(body.get('e')).toBeNull();
expect(body.getAll('e')).toBeNull();
});
it('should give an accurate list of keys', () => {
const body = new HttpUrlEncodedBody({fromString: 'a=1&b=2&c=3&d=4'});
expect(body.params()).toEqual(['a', 'b', 'c', 'd']);
const body = new HttpParams({fromString: 'a=1&b=2&c=3&d=4'});
expect(body.keys()).toEqual(['a', 'b', 'c', 'd']);
});
});
it('should have a magic Symbol-like property', () => {
const body = new HttpUrlEncodedBody() as any;
expect(body['__HttpUrlEncodedBody']).toEqual(true);
});
});
}

View File

@ -9,6 +9,7 @@
import {ddescribe, describe, it} from '@angular/core/testing/src/testing_internal';
import {HttpHeaders} from '../src/headers';
import {HttpParams} from '../src/params';
import {HttpRequest} from '../src/request';
const TEST_URL = 'http://angular.io';
@ -131,6 +132,33 @@ export function main() {
const req = baseReq.clone({body: {data: 'test data'}});
expect(req.serializeBody()).toBe('{"data":"test data"}');
});
it('serializes parameters as urlencoded', () => {
const params = new HttpParams().append('first', 'value').append('second', 'other');
const withParams = baseReq.clone({body: params});
expect(withParams.serializeBody()).toEqual('first=value&second=other');
expect(withParams.detectContentTypeHeader())
.toEqual('application/x-www-form-urlencoded;charset=UTF-8');
});
});
describe('parameter handling', () => {
const baseReq = new HttpRequest('GET', '/test', null);
const params = new HttpParams({fromString: 'test=true'});
it('appends parameters to a base URL', () => {
const req = baseReq.clone({params});
expect(req.urlWithParams).toEqual('/test?test=true');
});
it('appends parameters to a URL with an empty query string', () => {
const req = baseReq.clone({params, url: '/test?'});
expect(req.urlWithParams).toEqual('/test?test=true');
});
it('appends parameters to a URL with a query string', () => {
const req = baseReq.clone({params, url: '/test?other=false'});
expect(req.urlWithParams).toEqual('/test?other=false&test=true');
});
it('sets parameters via setParams', () => {
const req = baseReq.clone({setParams: {'test': 'false'}});
expect(req.urlWithParams).toEqual('/test?test=false');
});
});
});
}

View File

@ -33,16 +33,16 @@ export abstract class HttpTestingController {
abstract match(match: string|RequestMatch|((req: HttpRequest<any>) => boolean)): TestRequest[];
// Expect that exactly one request matches the given parameter.
abstract expectOne(url: string): TestRequest;
abstract expectOne(params: RequestMatch): TestRequest;
abstract expectOne(matchFn: ((req: HttpRequest<any>) => boolean)): TestRequest;
abstract expectOne(match: string|RequestMatch|((req: HttpRequest<any>) => boolean)): TestRequest;
abstract expectOne(url: string, description?: string): TestRequest;
abstract expectOne(params: RequestMatch, description?: string): TestRequest;
abstract expectOne(matchFn: ((req: HttpRequest<any>) => boolean), description?: string): TestRequest;
abstract expectOne(match: string|RequestMatch|((req: HttpRequest<any>) => boolean), description?: string): TestRequest;
// Assert that no requests match the given parameter.
abstract expectNone(url: string): void;
abstract expectNone(params: RequestMatch): void;
abstract expectNone(matchFn: ((req: HttpRequest<any>) => boolean)): void;
abstract expectNone(match: string|RequestMatch|((req: HttpRequest<any>) => boolean)): void;
abstract expectNone(url: string, description?: string): void;
abstract expectNone(params: RequestMatch, description?: string): void;
abstract expectNone(matchFn: ((req: HttpRequest<any>) => boolean), description?: string): void;
abstract expectNone(match: string|RequestMatch|((req: HttpRequest<any>) => boolean), description?: string): void;
// Validate that all requests which were issued were flushed.
abstract verify(opts?: {ignoreCancelled?: boolean}): void;

View File

@ -51,13 +51,13 @@ export class HttpClientTestingBackend implements HttpBackend, HttpTestingControl
*/
private _match(match: string|RequestMatch|((req: HttpRequest<any>) => boolean)): TestRequest[] {
if (typeof match === 'string') {
return this.open.filter(testReq => testReq.request.url === match);
return this.open.filter(testReq => testReq.request.urlWithParams === match);
} else if (typeof match === 'function') {
return this.open.filter(testReq => match(testReq.request));
} else {
return this.open.filter(
testReq => (!match.method || testReq.request.method === match.method.toUpperCase()) &&
(!match.url || testReq.request.url === match.url));
(!match.url || testReq.request.urlWithParams === match.url));
}
}
@ -83,13 +83,14 @@ export class HttpClientTestingBackend implements HttpBackend, HttpTestingControl
* Requests returned through this API will no longer be in the list of open requests,
* and thus will not match twice.
*/
expectOne(match: string|RequestMatch|((req: HttpRequest<any>) => boolean)): TestRequest {
expectOne(match: string|RequestMatch|((req: HttpRequest<any>) => boolean), description?: string): TestRequest {
description = description || this.descriptionFromMatcher(match);
const matches = this.match(match);
if (matches.length > 1) {
throw new Error(`Expected one matching request, found ${matches.length} requests.`);
throw new Error(`Expected one matching request for criteria "${description}", found ${matches.length} requests.`);
}
if (matches.length === 0) {
throw new Error(`Expected one matching request, found none.`);
throw new Error(`Expected one matching request for criteria "${description}", found none.`);
}
return matches[0];
}
@ -98,10 +99,11 @@ export class HttpClientTestingBackend implements HttpBackend, HttpTestingControl
* Expect that no outstanding requests match the given matcher, and throw an error
* if any do.
*/
expectNone(match: string|RequestMatch|((req: HttpRequest<any>) => boolean)): void {
expectNone(match: string|RequestMatch|((req: HttpRequest<any>) => boolean), description?: string): void {
description = description || this.descriptionFromMatcher(match);
const matches = this.match(match);
if (matches.length > 0) {
throw new Error(`Expected zero matching requests, found ${matches.length}.`);
throw new Error(`Expected zero matching requests for criteria "${description}", found ${matches.length}.`);
}
}
@ -116,9 +118,25 @@ export class HttpClientTestingBackend implements HttpBackend, HttpTestingControl
open = open.filter(testReq => !testReq.cancelled);
}
if (open.length > 0) {
// Show the URLs of open requests in the error, for convenience.
const urls = open.map(testReq => testReq.request.url.split('?')[0]).join(', ');
throw new Error(`Expected no open requests, found ${open.length}: ${urls}`);
// Show the methods and URLs of open requests in the error, for convenience.
const requests = open.map(testReq => {
const url = testReq.request.urlWithParams.split('?')[0];
const method = testReq.request.method;
return `${method} ${url}`
}).join(', ');
throw new Error(`Expected no open requests, found ${open.length}: ${requests}`);
}
}
private descriptionFromMatcher(matcher: string|RequestMatch|((req: HttpRequest<any>) => boolean)): string {
if (typeof matcher === 'string') {
return `Match URL: ${matcher}`;
} else if (typeof matcher === 'object') {
const method = matcher.method || '(any)';
const url = matcher.url || '(any)';
return `Match method: ${method}, URL: ${url}`;
} else {
return `Match by function: ${matcher.name}`;
}
}
}

View File

@ -39,7 +39,7 @@ export class TestRequest {
if (this.cancelled) {
throw new Error(`Cannot flush a cancelled request.`);
}
const url = this.request.url;
const url = this.request.urlWithParams;
const headers =
(opts.headers instanceof HttpHeaders) ? opts.headers : new HttpHeaders(opts.headers);
body = _maybeConvertBody(this.request.responseType, body);
@ -83,7 +83,7 @@ export class TestRequest {
headers,
status: opts.status || 0,
statusText: opts.statusText || '',
url: this.request.url,
url: this.request.urlWithParams,
}));
}

View File

@ -12,578 +12,674 @@ export declare class HttpClient {
delete<T>(url: string, options?: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<T>;
delete(url: string, options?: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<Object>;
delete<T>(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<T>>;
delete(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<Object>>;
delete(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpResponse<string>>;
delete(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpResponse<Blob>>;
delete(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpResponse<ArrayBuffer>>;
delete<T>(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpEvent<T>>;
delete(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpEvent<Object>>;
delete(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpEvent<string>>;
delete(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpEvent<Blob>>;
delete(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpEvent<ArrayBuffer>>;
delete(url: string, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<string>;
delete(url: string, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<ArrayBuffer>;
delete(url: string, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<Blob>;
get<T>(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpEvent<T>>;
get(url: string, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<string>;
get(url: string, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<Blob>;
get(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpEvent<ArrayBuffer>>;
get(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpEvent<Blob>>;
get(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpEvent<string>>;
get(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpEvent<Object>>;
get(url: string, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<ArrayBuffer>;
get(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpResponse<ArrayBuffer>>;
get(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpResponse<Blob>>;
get(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpResponse<string>>;
get(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<Object>>;
get<T>(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<T>>;
get(url: string, options?: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<Object>;
get<T>(url: string, options?: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<T>;
head(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpEvent<ArrayBuffer>>;
head(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpEvent<string>>;
head(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpEvent<Object>>;
head<T>(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpEvent<T>>;
head(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpResponse<ArrayBuffer>>;
head(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpResponse<Blob>>;
head(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpResponse<string>>;
head(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<Object>>;
head<T>(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<T>>;
head(url: string, options?: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<Object>;
head<T>(url: string, options?: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<T>;
head(url: string, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<string>;
head(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpEvent<Blob>>;
head(url: string, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<ArrayBuffer>;
head(url: string, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<Blob>;
jsonp(url: string): Observable<any>;
jsonp<T>(url: string): Observable<T>;
jsonp(url: string, callbackParam: string): Observable<any>;
jsonp<T>(url: string, callbackParam: string): Observable<T>;
options(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpResponse<ArrayBuffer>>;
options(url: string, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<ArrayBuffer>;
options(url: string, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<string>;
options(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpEvent<ArrayBuffer>>;
options(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpEvent<Blob>>;
options(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpEvent<string>>;
options(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpEvent<Object>>;
options<T>(url: string, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpEvent<T>>;
options(url: string, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<Blob>;
options(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpResponse<Blob>>;
options(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpResponse<string>>;
options(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<Object>>;
options<T>(url: string, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<T>>;
options(url: string, options?: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<Object>;
options<T>(url: string, options?: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<T>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpEvent<Object>>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<ArrayBuffer>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<Blob>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<string>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpEvent<ArrayBuffer>>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpEvent<Blob>>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpEvent<string>>;
patch<T>(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpEvent<T>>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpResponse<ArrayBuffer>>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpResponse<Blob>>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpResponse<string>>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<Object>>;
patch<T>(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<T>>;
patch(url: string, body: any | null, options?: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<Object>;
patch<T>(url: string, body: any | null, options?: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<T>;
post<T>(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpEvent<T>>;
post(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<ArrayBuffer>;
post(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<string>;
post(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpEvent<ArrayBuffer>>;
post(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpEvent<Blob>>;
post(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpEvent<string>>;
post(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpEvent<Object>>;
post(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<Blob>;
post(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpResponse<ArrayBuffer>>;
post(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpResponse<Blob>>;
post(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpResponse<string>>;
post(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<Object>>;
post<T>(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<T>>;
post(url: string, body: any | null, options?: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<Object>;
post<T>(url: string, body: any | null, options?: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<T>;
put(url: string, body: any | null, options?: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<Object>;
put<T>(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<T>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<Object>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpResponse<string>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpResponse<Blob>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpResponse<ArrayBuffer>>;
@ -596,48 +692,56 @@ export declare class HttpClient {
put(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<ArrayBuffer>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpEvent<Object>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpEvent<string>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpEvent<Blob>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpEvent<ArrayBuffer>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<string>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<Blob>;
put<T>(url: string, body: any | null, options?: {
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<T>;
@ -645,6 +749,7 @@ export declare class HttpClient {
body?: any;
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpEvent<string>>;
@ -652,6 +757,7 @@ export declare class HttpClient {
body?: any;
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<R>;
@ -659,6 +765,7 @@ export declare class HttpClient {
body?: any;
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<ArrayBuffer>;
@ -666,6 +773,7 @@ export declare class HttpClient {
body?: any;
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<Blob>;
@ -673,12 +781,14 @@ export declare class HttpClient {
body?: any;
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<string>;
request(method: string, url: string, options: {
body?: any;
headers?: HttpHeaders;
params?: HttpParams;
observe: 'events';
responseType: 'arraybuffer';
withCredentials?: boolean;
@ -687,6 +797,7 @@ export declare class HttpClient {
body?: any;
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpEvent<Blob>>;
@ -695,6 +806,7 @@ export declare class HttpClient {
body?: any;
headers?: HttpHeaders;
observe: 'events';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpEvent<R>>;
@ -702,6 +814,7 @@ export declare class HttpClient {
body?: any;
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'arraybuffer';
withCredentials?: boolean;
}): Observable<HttpResponse<ArrayBuffer>>;
@ -709,6 +822,7 @@ export declare class HttpClient {
body?: any;
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'blob';
withCredentials?: boolean;
}): Observable<HttpResponse<Blob>>;
@ -716,6 +830,7 @@ export declare class HttpClient {
body?: any;
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType: 'text';
withCredentials?: boolean;
}): Observable<HttpResponse<string>>;
@ -723,6 +838,7 @@ export declare class HttpClient {
body?: any;
headers?: HttpHeaders;
observe: 'response';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<HttpResponse<R>>;
@ -730,12 +846,14 @@ export declare class HttpClient {
body?: any;
headers?: HttpHeaders;
observe?: 'body';
params?: HttpParams;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<Object>;
request(method: string, url: string, options?: {
body?: any;
headers?: HttpHeaders;
params?: HttpParams;
observe?: HttpObserve;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
@ -825,6 +943,30 @@ export interface HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
}
/** @experimental */
export interface HttpParameterCodec {
decodeKey(key: string): string;
decodeValue(value: string): string;
encodeKey(key: string): string;
encodeValue(value: string): string;
}
/** @experimental */
export declare class HttpParams {
constructor(options?: {
fromString?: string;
encoder?: HttpParameterCodec;
});
append(param: string, value: string): HttpParams;
delete(param: string, value?: string): HttpParams;
get(param: string): string | null;
getAll(param: string): string[] | null;
has(param: string): boolean;
keys(): string[];
set(param: string, value: string): HttpParams;
toString(): string;
}
/** @experimental */
export interface HttpProgressEvent {
loaded: number;
@ -837,25 +979,30 @@ export declare class HttpRequest<T> {
readonly body: T | null;
readonly headers: HttpHeaders;
readonly method: string;
readonly params: HttpParams;
readonly reportProgress: boolean;
readonly responseType: 'arraybuffer' | 'blob' | 'json' | 'text';
url: string;
readonly url: string;
readonly urlWithParams: string;
readonly withCredentials: boolean;
constructor(method: 'DELETE' | 'GET' | 'HEAD' | 'JSONP' | 'OPTIONS', url: string, init?: {
headers?: HttpHeaders;
reportProgress?: boolean;
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
});
constructor(method: 'POST' | 'PUT' | 'PATCH', url: string, body: T | null, init?: {
headers?: HttpHeaders;
reportProgress?: boolean;
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
});
constructor(method: string, url: string, body: T | null, init?: {
headers?: HttpHeaders;
reportProgress?: boolean;
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
});
@ -863,12 +1010,23 @@ export declare class HttpRequest<T> {
clone(update: {
headers?: HttpHeaders;
reportProgress?: boolean;
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
body?: T | null;
method?: string;
url?: string;
setHeaders?: {
[name: string]: string | string[];
};
setParams?: {
[param: string]: string;
};
}): HttpRequest<T>;
clone<V>(update: {
headers?: HttpHeaders;
reportProgress?: boolean;
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
body?: V | null;
@ -877,6 +1035,9 @@ export declare class HttpRequest<T> {
setHeaders?: {
[name: string]: string | string[];
};
setParams?: {
[param: string]: string;
};
}): HttpRequest<V>;
detectContentTypeHeader(): string | null;
serializeBody(): ArrayBuffer | Blob | FormData | string | null;
@ -931,37 +1092,13 @@ export interface HttpSentEvent {
}
/** @experimental */
export declare class HttpStandardUrlParameterCodec implements HttpUrlParameterCodec {
export declare class HttpUrlEncodingCodec implements HttpParameterCodec {
decodeKey(k: string): string;
decodeValue(v: string): string;
encodeKey(k: string): string;
encodeValue(v: string): string;
}
/** @experimental */
export declare class HttpUrlEncodedBody {
constructor(options?: {
fromString?: string;
encoder?: HttpUrlParameterCodec;
});
append(param: string, value: string): HttpUrlEncodedBody;
delete(param: string, value?: string): HttpUrlEncodedBody;
get(param: string): string | null;
getAll(param: string): string[] | null;
has(param: string): boolean;
params(): string[];
set(param: string, value: string): HttpUrlEncodedBody;
toString(): string;
}
/** @experimental */
export interface HttpUrlParameterCodec {
decodeKey(key: string): string;
decodeValue(value: string): string;
encodeKey(key: string): string;
encodeValue(value: string): string;
}
/** @experimental */
export interface HttpUserEvent<T> {
type: HttpEventType.User;

View File

@ -4,14 +4,14 @@ export declare class HttpClientTestingModule {
/** @experimental */
export declare abstract class HttpTestingController {
abstract expectNone(url: string): void;
abstract expectNone(params: RequestMatch): void;
abstract expectNone(matchFn: ((req: HttpRequest<any>) => boolean)): void;
abstract expectNone(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean)): void;
abstract expectOne(url: string): TestRequest;
abstract expectOne(params: RequestMatch): TestRequest;
abstract expectOne(matchFn: ((req: HttpRequest<any>) => boolean)): TestRequest;
abstract expectOne(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean)): TestRequest;
abstract expectNone(url: string, description?: string): void;
abstract expectNone(params: RequestMatch, description?: string): void;
abstract expectNone(matchFn: ((req: HttpRequest<any>) => boolean), description?: string): void;
abstract expectNone(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean), description?: string): void;
abstract expectOne(url: string, description?: string): TestRequest;
abstract expectOne(params: RequestMatch, description?: string): TestRequest;
abstract expectOne(matchFn: ((req: HttpRequest<any>) => boolean), description?: string): TestRequest;
abstract expectOne(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean), description?: string): TestRequest;
abstract match(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean)): TestRequest[];
abstract verify(opts?: {
ignoreCancelled?: boolean;