Passed
Push — master ( 8c8975...cf384e )
by Sergey
03:18
created

request.filter.ts ➔ getRawHeader   A

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
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 RequestFilter implements IFilterPermission {
15
16
  can(params?: any[]): 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 header === 'test';
21
  }
22
23
}
24