# All files / src/lib streamProxy.ts

0% Statements 0/19
0% Branches 0/32
0% Functions 0/3
0% Lines 0/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40

     export type StreamHeaderOverrides = {
      origin?: string | null;
      userAgent?: string | null;
      user_agent?: string | null;
      referer?: string | null;
      customHeaders?: string | null;
      custom_headers?: string | null;
    };

    export type NormalizedStreamHeaders = {
      origin?: string;
      user_agent?: string;
      referer?: string;
      custom_headers?: string;
    };

    export function normalizeStreamHeaders(overrides?: StreamHeaderOverrides | null): NormalizedStreamHeaders {
      if (!overrides) return {};
      const origin = (overrides.origin ?? '').trim();
      const userAgent = (overrides.user_agent ?? overrides.userAgent ?? '').trim();
      const referer = (overrides.referer ?? '').trim();
      const customHeaders = (overrides.custom_headers ?? overrides.customHeaders ?? '').trim();
      return {
        origin: origin || undefined,
        user_agent: userAgent || undefined,
        referer: referer || undefined,
        custom_headers: customHeaders || undefined};
    }

    export function hasStreamHeaderOverrides(headers: NormalizedStreamHeaders): boolean {
      return !!(headers.origin || headers.user_agent || headers.referer || headers.custom_headers);
    }

    export function appendStreamHeaderParams(params: URLSearchParams, headers: NormalizedStreamHeaders): void {
      if (headers.origin) params.set('origin', headers.origin);
      if (headers.user_agent) params.set('user_agent', headers.user_agent);
      if (headers.referer) params.set('referer', headers.referer);
      if (headers.custom_headers) params.set('custom_headers', headers.custom_headers);
    }