@n1k1t/mock-server
Version:
The ultimate toolkit to intercept, transform, and simulate HTTP/WS traffic with type-safe expectations
35 lines • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SystemHttpRequestContext = void 0;
const models_1 = require("../../../models");
const reply_1 = require("./reply");
const logger_1 = require("../../../../logger");
const logger = logger_1.Logger.build('Transports.System.Http.Context');
class SystemHttpRequestContext extends models_1.RequestContext {
constructor(server, incoming, request, response) {
super(server.providers.default, { transport: 'http' });
this.server = server;
this.incoming = incoming;
this.request = request;
this.response = response;
this.snapshot = this.compileSnapshot();
this.reply = reply_1.SystemHttpReply.build(this);
logger.info('Incoming request', `[${incoming.method} ${incoming.path}]`);
}
complete() {
logger.info(`Incoming request [${this.incoming.method} ${this.incoming.path}] has finished`, `with status [${this.outgoing?.status ?? 200}] in [${Date.now() - this.timestamp}ms]`);
return super.complete();
}
compileHistory() {
return models_1.History.build({
group: this.provider.group,
snapshot: this.compileSnapshot(),
});
}
static async build(server, request, response) {
const incoming = await (0, models_1.extractHttpIncommingContext)(request);
return new SystemHttpRequestContext(server, incoming, request, response);
}
}
exports.SystemHttpRequestContext = SystemHttpRequestContext;
//# sourceMappingURL=context.js.map