Skip to content

Commit e165f1e

Browse files
authored
Merge pull request #6 from catenax-ng/TRACEFOSS-908-fix-OAST
fix: added check that compares response and request url
2 parents 516469c + 5c54f47 commit e165f1e

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/app/modules/core/api/api.interceptor.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,24 @@
1919
* SPDX-License-Identifier: Apache-2.0
2020
********************************************************************************/
2121

22-
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
23-
import { Observable } from 'rxjs';
22+
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http';
23+
import { Observable, of, throwError } from 'rxjs';
24+
import { switchMap } from 'rxjs/operators';
2425

2526
export class ApiInterceptor implements HttpInterceptor {
2627
public intercept(req: HttpRequest<string>, next: HttpHandler): Observable<HttpEvent<string>> {
2728
const requestUrl = req.url;
2829
req = req.clone({ url: requestUrl });
29-
return next.handle(req);
30+
return next.handle(req).pipe(
31+
switchMap(response => {
32+
if (!(response instanceof HttpResponse)) return of(response);
33+
34+
const { url } = response;
35+
if (url.indexOf(requestUrl) === -1)
36+
return throwError(() => new Error('Request and response url do not match!'));
37+
38+
return of(response);
39+
}),
40+
);
3041
}
3142
}

0 commit comments

Comments
 (0)