1
|
/**
|
2
|
* @license
|
3
|
* Copyright Google Inc. All Rights Reserved.
|
4
|
*
|
5
|
* Use of this source code is governed by an MIT-style license that can be
|
6
|
* found in the LICENSE file at https://angular.io/license
|
7
|
*/
|
8
|
import { InjectionToken } from '@angular/core';
|
9
|
import { Observable } from 'rxjs/Observable';
|
10
|
import { HttpHandler } from './backend';
|
11
|
import { HttpRequest } from './request';
|
12
|
import { HttpEvent } from './response';
|
13
|
/**
|
14
|
* Intercepts `HttpRequest` and handles them.
|
15
|
*
|
16
|
* Most interceptors will transform the outgoing request before passing it to the
|
17
|
* next interceptor in the chain, by calling `next.handle(transformedReq)`.
|
18
|
*
|
19
|
* In rare cases, interceptors may wish to completely handle a request themselves,
|
20
|
* and not delegate to the remainder of the chain. This behavior is allowed.
|
21
|
*
|
22
|
* @experimental
|
23
|
*/
|
24
|
export interface HttpInterceptor {
|
25
|
/**
|
26
|
* Intercept an outgoing `HttpRequest` and optionally transform it or the
|
27
|
* response.
|
28
|
*
|
29
|
* Typically an interceptor will transform the outgoing request before returning
|
30
|
* `next.handle(transformedReq)`. An interceptor may choose to transform the
|
31
|
* response event stream as well, by applying additional Rx operators on the stream
|
32
|
* returned by `next.handle()`.
|
33
|
*
|
34
|
* More rarely, an interceptor may choose to completely handle the request itself,
|
35
|
* and compose a new event stream instead of invoking `next.handle()`. This is
|
36
|
* acceptable behavior, but keep in mind further interceptors will be skipped entirely.
|
37
|
*
|
38
|
* It is also rare but valid for an interceptor to return multiple responses on the
|
39
|
* event stream for a single request.
|
40
|
*/
|
41
|
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
|
42
|
}
|
43
|
/**
|
44
|
* `HttpHandler` which applies an `HttpInterceptor` to an `HttpRequest`.
|
45
|
*
|
46
|
* @experimental
|
47
|
*/
|
48
|
export declare class HttpInterceptorHandler implements HttpHandler {
|
49
|
private next;
|
50
|
private interceptor;
|
51
|
constructor(next: HttpHandler, interceptor: HttpInterceptor);
|
52
|
handle(req: HttpRequest<any>): Observable<HttpEvent<any>>;
|
53
|
}
|
54
|
/**
|
55
|
* A multi-provider token which represents the array of `HttpInterceptor`s that
|
56
|
* are registered.
|
57
|
*
|
58
|
* @experimental
|
59
|
*/
|
60
|
export declare const HTTP_INTERCEPTORS: InjectionToken<HttpInterceptor[]>;
|
61
|
export declare class NoopInterceptor implements HttpInterceptor {
|
62
|
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;
|
63
|
}
|