mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
change header interceptor in hello-world e2e to take multiple headers if needed.
This commit is contained in:
@@ -44,12 +44,16 @@ export class StatusInterceptor {
|
||||
@Injectable()
|
||||
export class HeaderInterceptor {
|
||||
|
||||
constructor(private authorization: string){}
|
||||
constructor(private headers: object){}
|
||||
|
||||
intercept(context: ExecutionContext, next: CallHandler) {
|
||||
const ctx = context.switchToHttp();
|
||||
const res = ctx.getResponse();
|
||||
res.header('Authorization', this.authorization);
|
||||
for (const key in this.headers) {
|
||||
if (this.headers.hasOwnProperty(key)) {
|
||||
res.header(key, this.headers[key]);
|
||||
}
|
||||
}
|
||||
return next.handle().pipe(map(data => ({ data })));
|
||||
}
|
||||
}
|
||||
@@ -125,8 +129,12 @@ describe('Interceptors', () => {
|
||||
});
|
||||
|
||||
it(`should modify Authorization header`, async () => {
|
||||
const customHeaders = {
|
||||
Authorization: 'jwt',
|
||||
};
|
||||
|
||||
app = (await createTestModule(
|
||||
new HeaderInterceptor('jwt'),
|
||||
new HeaderInterceptor(customHeaders),
|
||||
)).createNestApplication();
|
||||
|
||||
await app.init();
|
||||
|
||||
0
scripts/test.sh
Normal file → Executable file
0
scripts/test.sh
Normal file → Executable file
Reference in New Issue
Block a user