All files / rpc-server/src/http1 Http1ConnectionContext.ts

100% Statements 17/17
100% Branches 0/0
100% Functions 2/2
100% Lines 17/17

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 281x 1x         1x   9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x       2x 2x 2x      
import {getBody} from './util';
import {listToUint8} from '@jsonjoy.com/buffers/lib/concat';
import type * as http from 'http';
import type {JsonValueCodec} from '@jsonjoy.com/json-pack/lib/codecs/types';
import type {RpcMessageCodec, ConnectionContext} from '../types';
 
export class Http1ConnectionContext<Meta = Record<string, unknown>> implements ConnectionContext<Meta> {
  constructor(
    public readonly req: http.IncomingMessage,
    public readonly res: http.ServerResponse,
    public path: string,
    public query: string,
    public readonly ip: string,
    public token: string,
    public readonly params: string[] | null,
    public readonly meta: Meta,
    public reqCodec: JsonValueCodec,
    public resCodec: JsonValueCodec,
    public msgCodec: RpcMessageCodec,
  ) {}
 
  public async body(maxPayload: number): Promise<Uint8Array> {
    const list = await getBody(this.req, maxPayload);
    const bodyUint8 = listToUint8(list);
    return bodyUint8;
  }
}