supra-http
Advanced tools
Comparing version 1.1.0 to 1.2.0
declare enum CONTENT_TYPE { | ||
TextEventStream = "text/event-stream", | ||
ApplicationJson = "application/json" | ||
ApplicationJson = "application/json", | ||
FormUrlEncoded = "application/x-www-form-urlencoded" | ||
} | ||
@@ -5,0 +6,0 @@ declare enum CACHE_CONTROL { |
@@ -7,2 +7,3 @@ "use strict"; | ||
CONTENT_TYPE["ApplicationJson"] = "application/json"; | ||
CONTENT_TYPE["FormUrlEncoded"] = "application/x-www-form-urlencoded"; | ||
})(CONTENT_TYPE || (CONTENT_TYPE = {})); | ||
@@ -9,0 +10,0 @@ exports.CONTENT_TYPE = CONTENT_TYPE; |
@@ -11,2 +11,3 @@ "use strict"; | ||
const fast_url_parser_1 = __importDefault(require("fast-url-parser")); | ||
const querystring_1 = require("querystring"); | ||
class Http { | ||
@@ -33,3 +34,8 @@ constructor() { | ||
requestOptions.body : undefined; | ||
const options = this.createRequestOptions(url, requestOptions, requestProvider.agent, requestBody); | ||
const requestFormContent = !requestBody ? | ||
typeof requestOptions.form === "object" ? | ||
querystring_1.stringify(requestOptions.form) : | ||
typeof requestOptions.form === "string" ? | ||
requestOptions.form : undefined : undefined; | ||
const options = this.createRequestOptions(url, requestOptions, requestProvider.agent, requestBody, requestFormContent); | ||
const request = requestProvider.client.request(options, response => { | ||
@@ -49,8 +55,9 @@ compression_1.Compression | ||
.on('timeout', request.abort); | ||
if (requestBody) { | ||
request.write(requestBody); | ||
const writableContent = requestBody || requestFormContent; | ||
if (writableContent) { | ||
request.write(writableContent); | ||
} | ||
request.end(); | ||
} | ||
createRequestOptions(targetUrl, options, agent, bodyContent) { | ||
createRequestOptions(targetUrl, options, agent, bodyContent, formContent) { | ||
const url = fast_url_parser_1.default.parse(targetUrl); | ||
@@ -76,2 +83,6 @@ const mergedOptions = { | ||
} | ||
else if (formContent) { | ||
mergedOptions.headers['content-length'] = formContent.length; | ||
mergedOptions.headers['content-type'] = enums_1.CONTENT_TYPE.FormUrlEncoded; | ||
} | ||
return mergedOptions; | ||
@@ -78,0 +89,0 @@ } |
@@ -7,2 +7,3 @@ /// <reference types="node" /> | ||
body?: string | object; | ||
form?: string | object; | ||
json?: boolean; | ||
@@ -9,0 +10,0 @@ headers?: Record<string, string>; |
{ | ||
"name": "supra-http", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Circuit breaking http client for NodeJs. And it is fast...", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
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
18333
257