Total Complexity | 7 |
Complexity/F | 3.5 |
Lines of Code | 23 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { IFilterPermission } from '../../../src'; |
||
2 | import { Injectable } from '@nestjs/common'; |
||
3 | |||
4 | function getRawHeader(name: string, rawHeaders: string[]): string | boolean { |
||
5 | const key = rawHeaders.indexOf(name); |
||
6 | if (key < 0) { |
||
7 | return false; |
||
8 | } |
||
9 | const value = key + 1; |
||
10 | return rawHeaders[value]; |
||
11 | } |
||
12 | |||
13 | @Injectable() |
||
14 | export class RequestAsyncFilter implements IFilterPermission { |
||
15 | |||
16 | async canAsync(params?: any[]): Promise<boolean> { |
||
17 | const name = 'test-header'; |
||
18 | // Fix: missing `headers`, using `rawHeaders` for fixing tests on Node.js 15 |
||
19 | const header = params[0]?.headers?.[name] ?? getRawHeader(name, params[0].rawHeaders); |
||
20 | return Promise.resolve(header === 'test'); |
||
21 | } |
||
22 | } |
||
23 |