Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

connect-rest

Package Overview
Dependencies
Maintainers
1
Versions
190
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-rest - npm Package Compare versions

Comparing version 3.0.11 to 3.0.12

41

lib/util/HttpHelper.js

@@ -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 @@

5

package.json
{
"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 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc