teeny-request
Advanced tools
Comparing version 3.2.1 to 3.3.0
import * as r from 'request'; | ||
declare function teenyRequest(reqOpts: r.OptionsWithUri, callback: any): void; | ||
declare function teenyRequest(reqOpts: r.OptionsWithUri, callback?: any): void; | ||
declare namespace teenyRequest { | ||
@@ -4,0 +4,0 @@ function defaults(defaults: r.OptionsWithUri): (reqOpts: r.UriOptions & r.CoreOptions, callback: any) => void; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
function requestToFetchOptions(reqOpts) { | ||
const options = Object.assign({}, reqOpts.headers && { headers: reqOpts.headers }, reqOpts.method && { method: reqOpts.method }, reqOpts.json && { body: JSON.stringify(reqOpts.json) }, reqOpts.timeout && { timeout: reqOpts.timeout }, reqOpts.gzip && { compress: reqOpts.gzip }); | ||
const options = Object.assign({}, reqOpts.headers && { headers: reqOpts.headers }, reqOpts.method && { method: reqOpts.method }, reqOpts.json && { body: JSON.stringify(reqOpts.body) }, reqOpts.timeout && { timeout: reqOpts.timeout }, reqOpts.gzip && { compress: reqOpts.gzip }); | ||
let uri = reqOpts.uri; | ||
@@ -36,9 +36,22 @@ if (reqOpts.useQuerystring === true) { | ||
} | ||
res.json().then(json => { | ||
let header = res.headers.get('content-type'); | ||
if (header === 'application/json') { | ||
let response = fetchToRequestResponse(res); | ||
response.body = json; | ||
callback(null, response, json); | ||
}).catch((err) => { | ||
res.json().then(json => { | ||
response.body = json; | ||
callback(null, response, json); | ||
}).catch(err => { | ||
callback(err); | ||
}); | ||
return; | ||
} | ||
res.text().then(text => { | ||
let response = fetchToRequestResponse(res); | ||
response.body = text; | ||
callback(null, response, text); | ||
}).catch(err => { | ||
callback(err); | ||
}); | ||
}).catch(err => { | ||
callback(err); | ||
}); | ||
@@ -45,0 +58,0 @@ } |
{ | ||
"name": "teeny-request", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"description": "Like request, but smaller.", | ||
@@ -5,0 +5,0 @@ "main": "./build/src/index.js", |
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
19548
72