libs/nx/src/executors/shared/metadata-utils/__test/my-team-plugin-lib/src/lib/language-interceptor/language-interceptor.ts
Methods |
constructor(locale: string, options?: LanguageInterceptorPluginOptions)
|
|||||||||
Parameters :
|
intercept | |||||||||
intercept(request: HttpRequest<>, next: HttpHandler)
|
|||||||||
Parameters :
Returns :
Observable<HttpEvent<>>
|
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Inject, Injectable, LOCALE_ID } from '@angular/core';
import { Observable } from 'rxjs';
import { LanguageInterceptorPluginOptions } from './language-interceptor.module';
import { LANGUAGE_INTERCEPTOR_PLUGIN_OPTIONS } from './tokens';
@Injectable()
export class LanguageInterceptor implements HttpInterceptor {
constructor(
@Inject(LOCALE_ID) private locale: string,
@Inject(LANGUAGE_INTERCEPTOR_PLUGIN_OPTIONS) private options?: LanguageInterceptorPluginOptions
) {}
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
const clonedRequest = request.clone({
headers: request.headers.set('Language', this.options?.language || this.locale)
});
console.log('LanguageInterceptor::LanguageInterceptorPluginOptions', this.options);
// send the cloned request with the Language header to the next handler
return next.handle(clonedRequest);
}
}