Comparing version 1.0.2 to 1.1.0
@@ -8,9 +8,8 @@ const { request } = require('https'); | ||
let out = ''; | ||
let o = { method }; | ||
opts.method = method; | ||
let { redirect=true } = opts; | ||
Object.assign(o, typeof uri === 'string' ? parse(uri) : uri); | ||
if (o.protocol === 'http:') o.agent = globalAgent; | ||
o.headers = opts.headers || {}; | ||
Object.assign(opts, typeof uri === 'string' ? parse(uri) : uri); | ||
opts.agent = opts.protocol === 'http:' ? globalAgent : void 0; | ||
let req = request(o, r => { | ||
let req = request(opts, r => { | ||
r.setEncoding('utf8'); | ||
@@ -25,3 +24,3 @@ | ||
if (type && out && type.includes('application/json')) { | ||
out = JSON.parse(out); | ||
out = JSON.parse(out, opts.reviver); | ||
} | ||
@@ -37,4 +36,4 @@ r.data = out; | ||
} else if (r.statusCode > 300 && redirect && r.headers.location) { | ||
o.path = resolve(o.path, r.headers.location); | ||
return send(method, o.path.startsWith('/') ? o : o.path, o).then(res, rej); | ||
opts.path = resolve(opts.path, r.headers.location); | ||
return send(method, opts.path.startsWith('/') ? opts : opts.path, opts).then(res, rej); | ||
} else { | ||
@@ -41,0 +40,0 @@ res(r); |
@@ -10,2 +10,3 @@ import {Url} from "url"; | ||
redirect: boolean, | ||
reviver: (key: string, value: any) => any, | ||
} | ||
@@ -12,0 +13,0 @@ |
{ | ||
"name": "httpie", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"repository": "lukeed/httpie", | ||
@@ -5,0 +5,0 @@ "description": "A lightweight, Promise-based wrapper for Node.js HTTP requests~!", |
@@ -118,3 +118,10 @@ <div align="center"> | ||
#### opts.reviver | ||
Type: `Function`<br> | ||
Default: `undefined` | ||
An optional function that's passed directly to [`JSON.parse`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Parameters), allowing you transform aspects of the response data before the `httpie` request resolves. | ||
> **Note:** This will _only_ run if `httpie` detects that JSON is contained in the response! | ||
### get(url, opts={}) | ||
@@ -121,0 +128,0 @@ > Alias for [`send('GET', url, opts)`](#sendmethod-url-opts). |
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
11869
170
131