Skip to content

Commit

Permalink
feat: added params x-page-url (#2866)
Browse files Browse the repository at this point in the history
* added params x-page-url

* added ut

* fdescribe removed
  • Loading branch information
Suraj Kumar authored and howdysuraj committed Apr 17, 2024
1 parent 246ff2d commit 1809526
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/app/core/interceptors/httpInterceptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,36 @@ describe('HttpConfigInterceptor', () => {
expect(httpInterceptor).toBeTruthy();
});

describe('getUrlWithoutQueryParam:', () => {
it('should return value truncating ;', () => {
const result = httpInterceptor.getUrlWithoutQueryParam(
'https://staging1.fyle.tech/enterprise/add_edit_expense;dataUrl=data:image%2Fjpeg%3Bbase64,%2F9j'
);
expect(result).toEqual('https://staging1.fyle.tech/enterprise/add_edit_expense');
});

it('should return value truncating ?', () => {
const result = httpInterceptor.getUrlWithoutQueryParam(
'https://staging1.fyle.tech/enterprise/add_edit_expense?dataUrl=data:image%2Fjpeg%3Bbase64,%2F9j'
);
expect(result).toEqual('https://staging1.fyle.tech/enterprise/add_edit_expense');
});

it('should return value truncating ;?', () => {
const result = httpInterceptor.getUrlWithoutQueryParam(
'https://staging1.fyle.tech/enterprise/add_edit_expense;?dataUrl=data:image%2Fjpeg%3Bbase64,%2F9j'
);
expect(result).toEqual('https://staging1.fyle.tech/enterprise/add_edit_expense');
});

it('should return value truncating ?;', () => {
const result = httpInterceptor.getUrlWithoutQueryParam(
'https://staging1.fyle.tech/enterprise/add_edit_expense?;dataUrl=data:image%2Fjpeg%3Bbase64,%2F9j'
);
expect(result).toEqual('https://staging1.fyle.tech/enterprise/add_edit_expense');
});
});

describe('secureUrl():', () => {
it('should return true for a secure URL', () => {
const result = httpInterceptor.secureUrl('https://staging1.fyle.tech/app/api/auth/logout');
Expand Down
22 changes: 21 additions & 1 deletion src/app/core/interceptors/httpInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ export class HttpConfigInterceptor implements HttpInterceptor {
);
}

getUrlWithoutQueryParam(url: string): string {
const queryIndex = Math.min(
url.indexOf('?') !== -1 ? url.indexOf('?') : url.length,
url.indexOf(';') !== -1 ? url.indexOf(';') : url.length
);
if (queryIndex !== url.length) {
url = url.substring(0, queryIndex);
}
if (url.length > 200) {
url = url.substring(0, 200);
}
return url;
}

intercept(request: HttpRequest<string>, next: HttpHandler): Observable<HttpEvent<string>> {
return forkJoin({
token: iif(() => this.secureUrl(request.url), this.getAccessToken(), of(null)),
Expand All @@ -128,7 +142,13 @@ export class HttpConfigInterceptor implements HttpInterceptor {
const osVersion = deviceInfo.osVersion;
const operatingSystem = deviceInfo.operatingSystem;
const mobileModifiedappVersion = `fyle-mobile::${appVersion}::${operatingSystem}::${osVersion}`;
request = request.clone({ headers: request.headers.set('X-App-Version', mobileModifiedappVersion) });
request = request.clone({
setHeaders: {
'X-App-Version': mobileModifiedappVersion,
'X-Page-Url': this.getUrlWithoutQueryParam(window.location.href),
'X-Source-Identifier': 'mobile_app',
},
});

return next.handle(request).pipe(
catchError((error) => {
Expand Down

0 comments on commit 1809526

Please sign in to comment.