Skip to content
Snippets Groups Projects
Commit 2cf4c87b authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2574 remove condition on adding header

parent 1043ca5c
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,6 @@ ...@@ -21,6 +21,6 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen * Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
export * from './lib/environment.model';
export * from './lib/environment.module'; export * from './lib/environment.module';
export * from './lib/environment.service'; export * from './lib/environment.service';
...@@ -22,44 +22,27 @@ ...@@ -22,44 +22,27 @@
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
import { HttpRequest } from '@angular/common/http'; import { HttpRequest } from '@angular/common/http';
import { Environment } from '@goofy-client/environment-shared'; import { faker } from '@faker-js/faker';
import { HttpMethod } from '../tech.model';
import { XhrInterceptor } from './xhr.interceptor'; import { XhrInterceptor } from './xhr.interceptor';
describe('XhrInterceptor', () => { describe('XhrInterceptor', () => {
let interceptor: XhrInterceptor; let interceptor: XhrInterceptor;
const apiHost: string = 'http://kop/api' const url: string = faker.internet.url();
const apiUrl: string = apiHost + '/vorgaenge';
const nonApiUrl: string = 'http://kop/vorgang/123';
const envConfig: Environment = {
remoteHost: apiHost,
authServer: '',
clientId: '',
realm: '',
production: false
};
beforeEach(() => { beforeEach(() => {
interceptor = new XhrInterceptor(envConfig); interceptor = new XhrInterceptor();
}) })
it('should be created', () => { it('should be created', () => {
expect(interceptor).toBeTruthy(); expect(interceptor).toBeTruthy();
}); });
describe('isApiRequest', () => {
it('should return true for API URL', () => {
expect(interceptor.isApiRequest(apiUrl)).toBeTruthy()
})
it('should return false for non-API URL', () => {
expect(interceptor.isApiRequest(nonApiUrl)).toBeFalsy()
})
})
describe('addHeader', () => { describe('addHeader', () => {
it('should add X-Requested-With header', () => { it('should add X-Requested-With header', () => {
const request: HttpRequest<unknown> = new HttpRequest('GET', apiUrl); const request: HttpRequest<unknown> = new HttpRequest(HttpMethod.GET, url);
const result: HttpRequest<unknown> = interceptor.addHeader(request); const result: HttpRequest<unknown> = interceptor.addHeader(request);
......
...@@ -22,27 +22,15 @@ ...@@ -22,27 +22,15 @@
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Inject, Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Environment, ENVIRONMENT_CONFIG } from '@goofy-client/environment-shared';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
@Injectable() @Injectable()
export class XhrInterceptor implements HttpInterceptor { export class XhrInterceptor implements HttpInterceptor {
constructor(@Inject(ENVIRONMENT_CONFIG) private envConfig: Environment) {
}
intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> { intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
if (this.isApiRequest(req.url)) {
return next.handle(this.addHeader(req)); return next.handle(this.addHeader(req));
} }
return next.handle(req);
}
isApiRequest(url: string): boolean {
const urlObject: URL = new URL(url);
return urlObject.pathname.startsWith('/api');
}
addHeader(req: HttpRequest<unknown>): HttpRequest<unknown> { addHeader(req: HttpRequest<unknown>): HttpRequest<unknown> {
return req.clone({ return req.clone({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment