@Injectable() classAnHttpInterceptorimplementsHttpInterceptor { intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { // we can set a new Header req.headers.set({"MyHeader": 789}) // we can modify a Header req.headers.append({"Content-Type": null}) // we can delete a Header req.headers.delete("Content-Type") return next.handle(req); } }
@Injectable() classAnHttpInterceptor implemenss HttpInterceptor { intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { const reqCopy = req.clone() // we can set a new Header reqCopy.headers.set({"MyHeader": 789}) // we can modify a Header reqCopy.headers.append({"Content-Type": null}) // we can delete a Header reqCopy.headers.delete("Content-Type") return next.handle(reqCopy); } }
classHttpRequest { /** * The request body, or `null` if one isn't set. * * Bodies are not enforced to be immutable, as they can include a reference to any * user-defined data type. However, interceptors should take care to preserve * idempotence by treating them as such. */ readonlybody: T|null = null; /** * Outgoing headers for this request. */ // TODO(issue/24571): remove '!'. readonly headers !: HttpHeaders; /** * Whether this request should be made in a way that exposes progress events. * * Progress events are expensive (change detection runs on each event) and so * they should only be requested if the consumer intends to monitor them. */ readonlyreportProgress: boolean = false; /** * Whether this request should be sent with outgoing credentials (cookies). */ readonlywithCredentials: boolean = false; /** * The expected response type of the server. * * This is used to parse the response appropriately before returning it to * the requestee. */ readonlyresponseType: 'arraybuffer'|'blob'|'json'|'text' = 'json'; /** * The outgoing HTTP request method. */ readonlymethod: string; /** * Outgoing URL parameters. */ // TODO(issue/24571): remove '!'. readonly params !: HttpParams; /** * The outgoing URL with all URL parameters set. */ readonlyurlWithParams: string; }
exportdeclareclassHttpErrorResponseextendsHttpResponseBaseimplementsError { readonly name = "HttpErrorResponse"; readonlymessage: string; readonlyerror: any | null; /** * Errors are never okay, even when the status code is in the 2xx success range. */ readonly ok = false; constructor(init: { error?: any; headers?: HttpHeaders; status?: number; statusText?: string; url?: string; }); }