Comparing version 4.0.8 to 5.0.0
@@ -24,2 +24,4 @@ /// <reference types="node" /> | ||
export declare class HTTP { | ||
static defaults: HTTPRequestOptions; | ||
static create(options?: HTTPRequestOptions): typeof HTTP; | ||
/** | ||
@@ -99,4 +101,2 @@ * make an http GET request | ||
static request(url: string, options?: HTTPRequestOptions): Promise<HTTP>; | ||
static defaults(options?: HTTPRequestOptions): typeof HTTP; | ||
static readonly defaultOptions: HTTPRequestOptions; | ||
response: http.IncomingMessage; | ||
@@ -103,0 +103,0 @@ request: http.ClientRequest; |
@@ -54,2 +54,20 @@ "use strict"; | ||
class HTTP { | ||
constructor(url, options = {}) { | ||
const userAgent = (global['http-call'] && global['http-call'].userAgent && global['http-call'].userAgent) || | ||
`${pjson.name}/${pjson.version} node-${process.version}`; | ||
this.options = Object.assign({}, this.ctor.defaults, options, { headers: lowercaseHeaders(Object.assign({ 'user-agent': userAgent }, this.ctor.defaults.headers, options.headers)) }); | ||
if (!url) | ||
throw new Error('no url provided'); | ||
this.url = url; | ||
if (this.options.body) | ||
this._parseBody(this.options.body); | ||
} | ||
static create(options = {}) { | ||
const defaults = this.defaults; | ||
return _a = class CustomHTTP extends HTTP { | ||
}, | ||
_a.defaults = Object.assign({}, defaults, options), | ||
_a; | ||
var _a; | ||
} | ||
/** | ||
@@ -151,22 +169,2 @@ * make an http GET request | ||
} | ||
static defaults(options = {}) { | ||
return class CustomHTTP extends HTTP { | ||
static get defaultOptions() { | ||
return Object.assign({}, super.defaultOptions, options); | ||
} | ||
}; | ||
} | ||
static get defaultOptions() { | ||
return { | ||
method: 'GET', | ||
host: 'localhost', | ||
protocol: 'https:', | ||
path: '/', | ||
raw: false, | ||
partial: false, | ||
headers: { | ||
'user-agent': `${pjson.name}/${pjson.version} node-${process.version}`, | ||
}, | ||
}; | ||
} | ||
get method() { | ||
@@ -189,6 +187,6 @@ return this.options.method || 'GET'; | ||
this.options.protocol = u.protocol || this.options.protocol; | ||
this.options.host = u.hostname || this.ctor.defaultOptions.host || 'localhost'; | ||
this.options.host = u.hostname || this.ctor.defaults.host || 'localhost'; | ||
this.options.path = u.path || '/'; | ||
this.options.agent = this.options.agent || deps_1.deps.proxy.agent(this.secure); | ||
this.options.port = u.port || this.ctor.defaultOptions.port || (this.secure ? 443 : 80); | ||
this.options.port = u.port || (this.secure ? 443 : 80); | ||
} | ||
@@ -208,10 +206,2 @@ get headers() { | ||
} | ||
constructor(url, options = {}) { | ||
this.options = Object.assign({}, this.ctor.defaultOptions, options, { headers: lowercaseHeaders(Object.assign({}, this.ctor.defaultOptions.headers, options.headers)) }); | ||
if (!url) | ||
throw new Error('no url provided'); | ||
this.url = url; | ||
if (this.options.body) | ||
this._parseBody(this.options.body); | ||
} | ||
_request() { | ||
@@ -369,2 +359,11 @@ return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
} | ||
HTTP.defaults = { | ||
method: 'GET', | ||
host: 'localhost', | ||
protocol: 'https:', | ||
path: '/', | ||
raw: false, | ||
partial: false, | ||
headers: {}, | ||
}; | ||
exports.HTTP = HTTP; | ||
@@ -371,0 +370,0 @@ class HTTPError extends Error { |
{ | ||
"name": "http-call", | ||
"description": "make http requests", | ||
"version": "4.0.8", | ||
"version": "5.0.0", | ||
"author": "Jeff Dickey @jdxcode", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/heroku/http-call/issues", |
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
21835
626