1.0.0 • Published 4 years ago

no-authorization-interceptor v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

no-authorization-interceptor

Removes Authorization header if X-No-Authorization will be found.

import { HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Injectable } from '@angular/core';

/**
 * Removes Authorization header if X-No-Authorization will be found.
 */
@Injectable({ providedIn: 'root' })
export class NoAuthorizationInterceptor implements HttpInterceptor {
    intercept(request: HttpRequest<unknown>, next: HttpHandler) {
        if (request.headers.has('X-No-Authorization')) {
            request = request.clone({ headers: request.headers.delete('Authorization') });
        }
        return next.handle(request);
    }
}