Comparing version 1.1.2 to 1.2.0
@@ -27,8 +27,10 @@ 'use strict'; | ||
var _proxyUtil = require('./proxy-util'); | ||
var _proxy = require('./proxy'); | ||
var _proxyUtil2 = _interopRequireDefault(_proxyUtil); | ||
var _proxy2 = _interopRequireDefault(_proxy); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const debug = require('debug')('http-call'); | ||
function concat(stream) { | ||
@@ -47,2 +49,3 @@ return new Promise(resolve => { | ||
* @property {(string)} body - request body. Sets content-type to application/json and stringifies when object | ||
* @property {(boolean)} partial - do not make continuous requests while receiving a Next-Range header for GET requests | ||
* @property {(number)} port - port to use | ||
@@ -72,3 +75,3 @@ */ | ||
await http.request(); | ||
return http.body; | ||
return this._getNextBody(http); | ||
} | ||
@@ -94,2 +97,56 @@ | ||
/** | ||
* make an http PUT request | ||
* @param {string} url - url or path to call | ||
* @param {HTTPRequestOptions} options | ||
* @returns {Promise} | ||
* @example | ||
* ```js | ||
* const http = require('http-call') | ||
* await http.put('https://google.com') | ||
* ``` | ||
*/ | ||
static async put(url, options = {}) { | ||
options.method = 'PUT'; | ||
let http = new this(url, options); | ||
await http.request(); | ||
return http.body; | ||
} | ||
/** | ||
* make an http PATCH request | ||
* @param {string} url - url or path to call | ||
* @param {HTTPRequestOptions} options | ||
* @returns {Promise} | ||
* @example | ||
* ```js | ||
* const http = require('http-call') | ||
* await http.patch('https://google.com') | ||
* ``` | ||
*/ | ||
static async patch(url, options = {}) { | ||
options.method = 'PATCH'; | ||
let http = new this(url, options); | ||
await http.request(); | ||
return http.body; | ||
} | ||
/** | ||
* make an http DELETE request | ||
* @param {string} url - url or path to call | ||
* @param {HTTPRequestOptions} options | ||
* @returns {Promise} | ||
* @example | ||
* ```js | ||
* const http = require('http-call') | ||
* await http.delete('https://google.com') | ||
* ``` | ||
*/ | ||
static async delete(url, options = {}) { | ||
options.method = 'DELETE'; | ||
let http = new this(url, options); | ||
await http.request(); | ||
return http.body; | ||
} | ||
parseBody(body) { | ||
@@ -135,2 +192,3 @@ if (!this.headers['Content-Type']) { | ||
this.raw = false; | ||
this.partial = false; | ||
this.headers = { | ||
@@ -149,2 +207,3 @@ 'user-agent': `${_package2.default.name}/${_package2.default.version} node-${process.version}` | ||
if (!url) throw new Error('no url provided'); | ||
this.options = options; | ||
let headers = Object.assign(this.headers, options.headers); | ||
@@ -160,7 +219,9 @@ Object.assign(this, options); | ||
this.body = undefined; | ||
if (_proxyUtil2.default.usingProxy) this.agent = _proxyUtil2.default.agent(u); | ||
if (_proxy2.default.usingProxy) this.agent = _proxy2.default.agent(u); | ||
} | ||
async request() { | ||
debug(`--> ${this.method} ${this.url}`); | ||
this.response = await this.performRequest(); | ||
debug(`<-- ${this.method} ${this.url} ${this.response.statusCode}`); | ||
if (this.response.statusCode >= 200 && this.response.statusCode < 300) { | ||
@@ -193,3 +254,12 @@ if (!this.raw) this.body = await this.parse(this.response); | ||
static async _getNextBody(http) { | ||
if (http.partial || !http.response.headers['next-range'] || !(http.body instanceof Array)) return http.body; | ||
let opts = { headers: {} }; | ||
opts = Object.assign(opts, http.options); | ||
opts.headers['range'] = http.response.headers['next-range']; | ||
let next = await this.get(http.url, opts); | ||
return http.body.concat(next); | ||
} | ||
} | ||
exports.default = HTTP; |
{ | ||
"name": "http-call", | ||
"description": "make http requests", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"author": "Jeff Dickey @dickeyxxx", | ||
"bugs": "https://github.com/dickeyxxx/http-call/issues", | ||
"dependencies": { | ||
"debug": "^2.x", | ||
"tunnel-agent": "^0.6.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.24.0", | ||
"babel-core": "^6.24.0", | ||
"babel-eslint": "7.1.1", | ||
"babel-jest": "^19.0.0", | ||
"babel-plugin-transform-class-properties": "^6.23.0", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.0", | ||
"babel-cli": "6.24.1", | ||
"babel-core": "6.24.1", | ||
"babel-eslint": "7.2.3", | ||
"babel-jest": "20.0.3", | ||
"babel-plugin-transform-class-properties": "6.24.1", | ||
"babel-plugin-transform-es2015-modules-commonjs": "6.24.1", | ||
"babel-plugin-transform-flow-strip-types": "6.22.0", | ||
"codecov": "^2.0.1", | ||
"flow-bin": "^0.41.0", | ||
"flow-bin": "0.47.0", | ||
"flow-copy-source": "1.1.0", | ||
"flow-typed": "2.0.0", | ||
"jest": "^19.0.2", | ||
"flow-typed": "2.1.2", | ||
"jest": "20.0.4", | ||
"jsdoc-babel": "0.3.0", | ||
"jsdoc-to-markdown": "3.0.0", | ||
"nock": "^9.0.9", | ||
"nock": "9.0.13", | ||
"rimraf": "^2.6.1", | ||
"standard": "^9.0.1" | ||
"standard": "10.0.2" | ||
}, | ||
@@ -29,2 +32,5 @@ "engines": { | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"homepage": "https://github.com/dickeyxxx/http-call", | ||
@@ -51,3 +57,3 @@ "jest": { | ||
"test": "jest && flow && standard", | ||
"watch": "babel --watch src -d lib --ignore '*.test.js'" | ||
"watch": "nodemon -e js -i lib --exec \"npm run prepare\"" | ||
}, | ||
@@ -67,6 +73,3 @@ "standard": { | ||
] | ||
}, | ||
"dependencies": { | ||
"tunnel-agent": "^0.6.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 6 instances in 1 package
20426
16
296
3
2
6
+ Addeddebug@^2.x
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)