Comparing version 5.2.1 to 5.2.2
@@ -117,13 +117,15 @@ /// <reference types="node" /> | ||
_maybeRetry(err: Error): Promise<void>; | ||
_debugRequest(): void; | ||
_debugResponse(): void; | ||
_performRequest(): Promise<http.IncomingMessage>; | ||
_parse(): Promise<void>; | ||
_parseBody(body: object): void; | ||
_getNextRange(): Promise<void>; | ||
_redactedHeaders(headers: http.IncomingHttpHeaders | http.OutgoingHttpHeaders): http.IncomingHttpHeaders | http.OutgoingHttpHeaders; | ||
readonly _responseOK: boolean; | ||
readonly _responseRedirect: boolean; | ||
readonly _shouldParseResponseBody: boolean; | ||
_wait(ms: number): Promise<{}>; | ||
private readonly _chalk; | ||
private _renderStatus; | ||
private _debugRequest; | ||
private _debugResponse; | ||
private _renderHeaders; | ||
private _performRequest; | ||
private _parse; | ||
private _parseBody; | ||
private _getNextRange; | ||
private readonly _responseOK; | ||
private readonly _responseRedirect; | ||
private readonly _shouldParseResponseBody; | ||
private _wait; | ||
} | ||
@@ -130,0 +132,0 @@ export default HTTP; |
@@ -9,3 +9,2 @@ "use strict"; | ||
const debugHeaders = require('debug')('http:headers'); | ||
const debugBody = require('debug')('http:body'); | ||
function concat(stream) { | ||
@@ -256,16 +255,61 @@ return new Promise(resolve => { | ||
} | ||
get _chalk() { | ||
try { | ||
return require('chalk'); | ||
} | ||
catch (err) { | ||
return; | ||
} | ||
} | ||
_renderStatus(code) { | ||
if (code < 200) | ||
return code; | ||
if (code < 300) | ||
return this._chalk.green(code); | ||
if (code < 400) | ||
return this._chalk.bold.cyan(code); | ||
if (code < 500) | ||
return this._chalk.bgYellow(code); | ||
if (code < 600) | ||
return this._chalk.bgRed(code); | ||
return code; | ||
} | ||
_debugRequest() { | ||
if (!debug.enabled) | ||
return; | ||
let output = [`${this._chalk.bold('→')} ${this._chalk.blue.bold(this.options.method)} ${this._chalk.bold(this.url)}`]; | ||
if (this.options.agent) | ||
debug('proxy: %o', this.options.agent); | ||
debug('--> %s %s', this.options.method, this.url); | ||
debugHeaders(this._redactedHeaders(this.options.headers)); | ||
output.push(` proxy: ${util.inspect(this.options.agent)}`); | ||
if (debugHeaders.enabled) | ||
output.push(this._renderHeaders(this.options.headers)); | ||
if (this.options.body) | ||
debugBody(this.options.body); | ||
output.push(' ' + this.options.body); | ||
debug(output.join('\n')); | ||
} | ||
_debugResponse() { | ||
debug('<-- %s %s %s', this.method, this.url, this.statusCode); | ||
debugHeaders(this._redactedHeaders(this.headers)); | ||
if (!debug.enabled) | ||
return; | ||
const chalk = require('chalk'); | ||
let output = [`${this._chalk.white.bold('←')} ${this._chalk.blue.bold(this.method)} ${this._chalk.bold(this.url)} ${this._renderStatus(this.statusCode)}`]; | ||
if (debugHeaders.enabled) | ||
output.push(this._renderHeaders(this.headers)); | ||
if (this.body) | ||
debugBody(this.body); | ||
output.push(' ' + util.inspect(this.body)); | ||
debug(output.join('\n')); | ||
} | ||
_renderHeaders(headers) { | ||
headers = Object.assign({}, headers); | ||
if (process.env.HTTP_CALL_REDACT !== '0' && headers.authorization) | ||
headers.authorization = '[REDACTED]'; | ||
return Object.entries(headers) | ||
.sort(([a], [b]) => { | ||
if (a < b) | ||
return -1; | ||
if (a > b) | ||
return 1; | ||
return 0; | ||
}) | ||
.map(([k, v]) => ` ${this._chalk.dim(k + ':')} ${this._chalk.cyan(util.inspect(v))}`) | ||
.join('\n'); | ||
} | ||
_performRequest() { | ||
@@ -281,3 +325,3 @@ return new Promise((resolve, reject) => { | ||
this.request.setTimeout(this.options.timeout, () => { | ||
debug(`<-- ${this.method} ${this.url} TIMED OUT`); | ||
debug(`← ${this.method} ${this.url} TIMED OUT`); | ||
this.request.abort(); | ||
@@ -326,8 +370,2 @@ }); | ||
} | ||
_redactedHeaders(headers) { | ||
headers = Object.assign({}, headers); | ||
if (process.env.HTTP_CALL_REDACT !== '0' && headers.authorization) | ||
headers.authorization = '[REDACTED]'; | ||
return headers; | ||
} | ||
get _responseOK() { | ||
@@ -334,0 +372,0 @@ if (!this.response) |
{ | ||
"name": "http-call", | ||
"description": "make http requests", | ||
"version": "5.2.1", | ||
"version": "5.2.2", | ||
"author": "Jeff Dickey @jdxcode", | ||
@@ -20,6 +20,6 @@ "bugs": "https://github.com/heroku/http-call/issues", | ||
"@types/nock": "^9.3.0", | ||
"@types/node": "^10.7.1", | ||
"@types/node": "^10.9.3", | ||
"jest": "^23.5.0", | ||
"nock": "^9.6.1", | ||
"ts-jest": "^23.1.3", | ||
"ts-jest": "^23.1.4", | ||
"tslint": "^5.11.0", | ||
@@ -26,0 +26,0 @@ "typescript": "^3.0.1" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39308
1065