HttpInterceptor
拦截 HttpRequest
并处理它们。
Intercepts HttpRequest
and handles them.
interface HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>
}
说明
大多数拦截器都会在外发的请求由 next.handle(transformedReq)
发给拦截器链中的下一个拦截器之前,对该请求进行转换。
Most interceptors will transform the outgoing request before passing it to the next interceptor in the chain, by calling next.handle(transformedReq)
.
极少量情况下,拦截器也可能希望自己完全处理一个请求,而不再委托给拦截器链中的其它部分。这种行为也是允许的。
In rare cases, interceptors may wish to completely handle a request themselves, and not delegate to the remainder of the chain. This behavior is allowed.
方法
拦截外发的 Intercept an outgoing | ||||||
参数
返回值
| ||||||
通常,拦截器将会在返回 Typically an interceptor will transform the outgoing request before returning 更罕见的情况下,拦截器可以选择完全由自己处理该请求,并合成新的事件流而不是调用 More rarely, an interceptor may choose to completely handle the request itself, and compose a new event stream instead of invoking 另一种同样罕见但是有用的拦截器,会为单个请求在事件流上给出多个响应对象。 It is also rare but valid for an interceptor to return multiple responses on the event stream for a single request. |