Comparing version 0.1.2 to 0.2.0
@@ -8,6 +8,6 @@ const { parse } = require('url'); | ||
let out = ''; | ||
let o = { method }; | ||
let headers = opts.headers || {}; | ||
let { protocol, hostname, port, path } = parse(uri); | ||
let o = { protocol, path, method, hostname, port, headers }; | ||
if (protocol === 'http:') o.agent = globalAgent; | ||
Object.assign(o, typeof uri === 'string' ? parse(uri) : uri); | ||
if (o.protocol === 'http:') o.agent = globalAgent; | ||
@@ -27,3 +27,12 @@ let req = request(o, r => { | ||
r.data = out; | ||
(r.statusCode >= 400 ? rej : res)(r); | ||
if (r.statusCode >= 400) { | ||
let err = new Error(r.statusMessage); | ||
err.statusMessage = r.statusMessage; | ||
err.statusCode = r.statusCode; | ||
err.headers = r.headers; | ||
err.data = r.data; | ||
rej(err); | ||
} else { | ||
res(r); | ||
} | ||
}); | ||
@@ -46,8 +55,13 @@ }); | ||
exports.get = send.bind(null, 'GET'); | ||
exports.post = send.bind(null, 'POST'); | ||
exports.patch = send.bind(null, 'PATCH'); | ||
exports.del = send.bind(null, 'DELETE'); | ||
exports.put = send.bind(null, 'PUT'); | ||
const get = send.bind(null, 'GET'); | ||
const post = send.bind(null, 'POST'); | ||
const patch = send.bind(null, 'PATCH'); | ||
const del = send.bind(null, 'DELETE'); | ||
const put = send.bind(null, 'PUT'); | ||
exports.send = send; | ||
exports.del = del; | ||
exports.get = get; | ||
exports.patch = patch; | ||
exports.post = post; | ||
exports.put = put; | ||
exports.send = send; |
{ | ||
"name": "httpie", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"repository": "lukeed/httpie", | ||
@@ -18,3 +18,3 @@ "description": "A lightweight, Promise-based wrapper for Node.js HTTP requests~!", | ||
"scripts": { | ||
"build": "node builder", | ||
"build": "bundt", | ||
"pretest": "npm run build", | ||
@@ -33,9 +33,6 @@ "test": "tape test/*.js | tap-spec" | ||
"devDependencies": { | ||
"gzip-size": "^3.0.0", | ||
"mk-dirs": "^1.0.0", | ||
"pretty-bytes": "^4.0.2", | ||
"bundt": "^0.2.0", | ||
"tap-spec": "^5.0.0", | ||
"tape": "^4.9.1", | ||
"terser": "^3.10.0" | ||
"tape": "^4.9.1" | ||
} | ||
} |
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
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
5237
3
103