connect-rest
Advanced tools
Comparing version 3.0.11 to 3.0.12
@@ -10,2 +10,5 @@ let http = require('http') | ||
const Proback = require('proback.js') | ||
const FormData = require('form-data') | ||
function getQuery ( query ) { | ||
@@ -23,3 +26,3 @@ return query ? '?' + querystring.stringify( query ) : '' | ||
'accept-version': '1.0.0', | ||
'Content-Type': 'application/json' | ||
'content-type': 'application/json' | ||
} | ||
@@ -89,7 +92,18 @@ } | ||
httpHelper.upload = async function (serverURL, query, refName, fileName, contentType, fileStream ) { | ||
var form = new FormData({ }) | ||
form.append( refName, fileStream, { | ||
filename: fileName, | ||
contentType: contentType | ||
}) | ||
let length = await Proback.promisify( form, form.getLength ) | ||
return this.headers( form.getHeaders() ).headers( { 'content-length': length } ).mimetype('').payload().generalCall( serverURL + getQuery(query), 'POST', { form: form } ) | ||
} | ||
httpHelper.callOn = function ( options = {} ) { | ||
return this.headers(options.headers).mimetype(options.mimetype).payload(options.err, options.result).generalCall( options.serverURL, options.method || 'GET' ) | ||
return this.headers(options.headers).mimetype(options.mimetype).payload(options.err || options.result).generalCall( options.serverURL, options.method || 'GET' ) | ||
} | ||
httpHelper.generalCall = async function (serverURL, method) { | ||
httpHelper.generalCall = async function (serverURL, method, options = {}) { | ||
let self = this | ||
@@ -110,3 +124,4 @@ | ||
voptions.headers['Content-Type'] = self.opt.mimetype | ||
if (self.opt.mimetype) | ||
voptions.headers['content-type'] = self.opt.mimetype | ||
@@ -119,5 +134,5 @@ if (self._options.logger) | ||
let data | ||
if ( self._options.payload ) { | ||
if ( self._options.payload && !options.form ) { | ||
data = (self.opt.mimetype === 'application/json') ? JSON.stringify( self._options.payload ) : querystring.stringify( self._options.payload ) | ||
voptions.headers['Content-Length'] = Buffer.byteLength( data ) | ||
voptions.headers['content-length'] = Buffer.byteLength( data ) | ||
if (self._options.logger) | ||
@@ -128,4 +143,4 @@ self._options.logger.debug('Payload to be sent:', data) | ||
let responseStatus | ||
let body = '' | ||
let req = lib.request( voptions, function (res) { | ||
let body = '' | ||
res.on('data', function (chunk) { | ||
@@ -140,2 +155,3 @@ body += chunk | ||
}) | ||
req.on('error', function (er) { | ||
@@ -145,6 +161,15 @@ self.reset() | ||
}) | ||
if ( options.form ) { | ||
options.form.once('end', function () { | ||
req.complete = true | ||
}) | ||
options.form.pipe( req ) | ||
} | ||
if ( data ) | ||
req.write( data ) | ||
req.end() | ||
if ( !options.form ) | ||
req.end() | ||
} ) | ||
@@ -151,0 +176,0 @@ |
{ | ||
"name": "connect-rest", | ||
"version": "3.0.11", | ||
"version": "3.0.12", | ||
"description": "Exceptionally featureful RESTful web services middleware for Connect.", | ||
@@ -29,5 +29,6 @@ "keywords": [ | ||
"axios": "^0.17.1", | ||
"form-data": "^2.3.2", | ||
"isa.js": "^2.2.0", | ||
"pino": "^4.11.0", | ||
"proback.js": "^2.1.5", | ||
"proback.js": "^2.1.6", | ||
"semver": "^5.5.0" | ||
@@ -34,0 +35,0 @@ }, |
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
117165
2025
7
+ Addedform-data@^2.3.2
+ Addedasynckit@0.4.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedform-data@2.5.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
Updatedproback.js@^2.1.6