UNPKG

request-mocking-protocol

Version:
23 lines 786 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HeadersMatcher = void 0; class HeadersMatcher { schema; expectedHeaders; constructor(schema) { this.schema = schema; this.expectedHeaders = this.schema.headers || {}; } match(ctx) { return Object.keys(this.expectedHeaders).every((key) => this.matchHeader(ctx, key)); } matchHeader(ctx, name) { const expectedValue = this.expectedHeaders[name] ?? null; const actualValue = ctx.req.headers.get(name); const result = actualValue === expectedValue; ctx.log(result, `header "${name}"`, expectedValue, actualValue); return result; } } exports.HeadersMatcher = HeadersMatcher; //# sourceMappingURL=headers.js.map