mirror of https://github.com/abpframework/abp
Merge pull request #15491 from abpframework/issue/15380
Add HttpContext variable and skip it http interceptor logic when it i…pull/15495/head
commit
cfd66fbe3c
@ -0,0 +1,30 @@
|
||||
import { HttpClient, HttpContext, HttpRequest } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { IS_EXTERNAL_REQUEST } from '../tokens/http-context.token';
|
||||
|
||||
// source : https://github.com/armanozak/demo-angular-server-specific-interceptors
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ExternalHttpClient extends HttpClient {
|
||||
override request(
|
||||
first: string | HttpRequest<any>,
|
||||
url?: string,
|
||||
options: RequestOptions = {},
|
||||
): Observable<any> {
|
||||
if (typeof first === 'string') {
|
||||
this.#setPlaceholderContext(options);
|
||||
return super.request(first, url, options);
|
||||
}
|
||||
|
||||
this.#setPlaceholderContext(first);
|
||||
return super.request(first);
|
||||
}
|
||||
#setPlaceholderContext(optionsOrRequest: { context?: HttpContext }) {
|
||||
optionsOrRequest.context ??= new HttpContext();
|
||||
optionsOrRequest.context.set(IS_EXTERNAL_REQUEST, true);
|
||||
}
|
||||
}
|
||||
|
||||
type RequestOptions = Parameters<HttpClient['request']>[2];
|
@ -0,0 +1 @@
|
||||
export * from './http.client';
|
@ -0,0 +1,3 @@
|
||||
import { HttpContextToken } from '@angular/common/http';
|
||||
|
||||
export const IS_EXTERNAL_REQUEST = new HttpContextToken<boolean>(() => false);
|
Loading…
Reference in new issue