Muhammed Altuğ
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
19 additions and
2 deletions
-
npm/ng-packs/packages/core/src/lib/services/rest.service.ts
-
npm/ng-packs/packages/core/src/lib/tests/rest.service.spec.ts
|
|
|
@ -38,9 +38,9 @@ export class RestService { |
|
|
|
api = api || this.getApiFromStore(config.apiName); |
|
|
|
const { method, params, ...options } = request; |
|
|
|
const { observe = Rest.Observe.Body, skipHandleError } = config; |
|
|
|
|
|
|
|
const url = this.removeDuplicateSlashes(api + request.url); |
|
|
|
return this.http |
|
|
|
.request<R>(method, api + request.url, { |
|
|
|
.request<R>(method, url, { |
|
|
|
observe, |
|
|
|
...(params && { |
|
|
|
params: this.getParams(params, config.httpParamEncoder), |
|
|
|
@ -62,4 +62,8 @@ export class RestService { |
|
|
|
? new HttpParams({ encoder, fromObject: filteredParams }) |
|
|
|
: new HttpParams({ fromObject: filteredParams }); |
|
|
|
} |
|
|
|
|
|
|
|
private removeDuplicateSlashes(url: string): string { |
|
|
|
return url.replace(/([^:]\/)\/+/g, '$1'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -120,4 +120,17 @@ describe('HttpClient testing', () => { |
|
|
|
const req = spectator.expectOne(api + '/test', HttpMethod.GET); |
|
|
|
spectator.flushAll([req], [throwError('Testing error')]); |
|
|
|
}); |
|
|
|
|
|
|
|
test('should remove the duplicate slashes', () => { |
|
|
|
spectator.service |
|
|
|
.request({ method: HttpMethod.GET, url: '//test', params: { id: 1 } }) |
|
|
|
.subscribe(); |
|
|
|
spectator.expectOne(api + '/test?id=1', HttpMethod.GET); |
|
|
|
}); |
|
|
|
test('should remove the duplicate slashes multiple', () => { |
|
|
|
spectator.service |
|
|
|
.request({ method: HttpMethod.GET, url: '//test//my//endpoint', params: { id: 1 } }) |
|
|
|
.subscribe(); |
|
|
|
spectator.expectOne(api + '/test/my/endpoint?id=1', HttpMethod.GET); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|