Comparing version 1.3.2 to 1.3.3
72
index.js
@@ -133,19 +133,20 @@ 'use strict'; | ||
this._max_retry = Request.MAX_RETRY; | ||
this._retryables = Request.RETRYABLES; | ||
this._max_retry = Request.MAX_RETRY; | ||
this._retryables = Request.RETRYABLES; | ||
this._formatted_payload = null; | ||
this.method = method; | ||
this.data = ''; | ||
this.headers = {}; | ||
this.callbacks = {}; | ||
this.request_opts = {}; | ||
this.retries = 0; | ||
this.auto_format = true; | ||
this.secure = false; | ||
this.follow = false; | ||
this.started = false; | ||
this.encoding = 'utf8'; | ||
this.logger = console; | ||
this.errors = []; | ||
this.last_error = null; | ||
this.method = method; | ||
this.data = ''; | ||
this.headers = {}; | ||
this.callbacks = {}; | ||
this.request_opts = {}; | ||
this.retries = 0; | ||
this.auto_format = true; | ||
this.secure = false; | ||
this.follow = false; | ||
this.started = false; | ||
this.encoding = 'utf8'; | ||
this.logger = console; | ||
this.errors = []; | ||
this.last_error = null; | ||
@@ -321,2 +322,3 @@ this.end = this.then; | ||
send (data) { | ||
this._formatted_payload = null; | ||
this.data = data || ''; | ||
@@ -331,3 +333,2 @@ return this; | ||
let new_path = this.path; | ||
let payload = ''; | ||
@@ -350,10 +351,25 @@ this.started = true; | ||
} | ||
else if (this.auto_format) { | ||
payload = (!this.headers['Content-Type'] && this.data) | ||
? Request.stringify(this.data) | ||
: JSON.stringify(this.data); | ||
else if (!this._formatted_payload) { | ||
if (this.auto_format) { | ||
/* | ||
Formatting cases: | ||
+------------------------------------------------+ | ||
| content-type | data | | format | | ||
|----------------+----------------+----+---------| | ||
| urlencoded | exists | -> | Request | | ||
| urlencoded | null/undefined | -> | JSON | | ||
| json | exists | -> | JSON | | ||
| json | null/undefined | -> | JSON | | ||
| null/undefined | exists | -> | Request | | ||
| null/undefined | null/undefined | -> | JSON | | ||
+------------------------------------------------+ | ||
*/ | ||
this._formatted_payload = (this.headers['Content-Type'] !== 'application/json' && this.data) | ||
? Request.stringify(this.data) | ||
: JSON.stringify(this.data); | ||
} | ||
else { | ||
this._formatted_payload = this.data; | ||
} | ||
} | ||
else { | ||
payload = this.data; | ||
} | ||
@@ -370,4 +386,6 @@ | ||
if (payload) { | ||
this.headers['Content-Length'] = Buffer.byteLength(payload); | ||
if (this._formatted_payload) { | ||
this.headers['Content-Length'] = Buffer.byteLength( | ||
this._formatted_payload | ||
); | ||
} | ||
@@ -394,3 +412,3 @@ | ||
if (this.method !== 'GET') { | ||
req.write(payload); | ||
req.write(this._formatted_payload); | ||
} | ||
@@ -397,0 +415,0 @@ |
{ | ||
"name": "cuddle", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "Cuddle is a minimal, chainable and readability first http client", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
18847
427