UNPKG

af-consul

Version:

A highly specialized function library

24 lines 936 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const getHttpRequestText = (request) => { const { req: { hostname, port, path, method, headers }, body } = request; let res = `###\n${method} ${request.req.agent.protocol}//${hostname}${port ? `:${port}` : ''}${path}`; // let res = `###\n${method} ${request._client._opts.baseUrl.protocol}//${hostname}${port ? `:${port}` : ''}${path}`; Object.entries(headers) .forEach(([headerName, value]) => { if (headerName !== 'content-length') { res += `\n${headerName}: ${value}`; } }); if ((method === 'POST' || method === 'PUT') && body) { try { res += `\n\n${JSON.stringify(JSON.parse(body.toString()), undefined, 2)}`; } catch (err) { // } } return res; }; exports.default = getHttpRequestText; //# sourceMappingURL=http-request-text.js.map