2018-07-12 14:11:31 +02:00
|
|
|
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
|
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interceptor class for HTTP requests. Replaces all 'httpOptions' in all http.get or http.post requests.
|
|
|
|
*
|
|
|
|
* Should not need further adjustment.
|
|
|
|
*/
|
|
|
|
export class AddHeaderInterceptor implements HttpInterceptor {
|
|
|
|
/**
|
|
|
|
* Normal HttpInterceptor usage
|
|
|
|
*
|
|
|
|
* @param req Will clone the request and intercept it with our desired headers
|
|
|
|
* @param next HttpHandler will catch the response and forwards it to the original instance
|
|
|
|
*/
|
2018-08-29 13:21:25 +02:00
|
|
|
public intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
2018-07-12 14:11:31 +02:00
|
|
|
const clonedRequest = req.clone({
|
|
|
|
withCredentials: true,
|
|
|
|
headers: req.headers.set('Content-Type', 'application/json')
|
|
|
|
});
|
|
|
|
|
|
|
|
return next.handle(clonedRequest);
|
|
|
|
}
|
|
|
|
}
|