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

tiny-json-http

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-json-http - npm Package Compare versions

Comparing version 3.0.6 to 3.0.7

28

_read.js

@@ -32,10 +32,7 @@ var http = require('http')

// make a request
method(opts, function __res(res) {
var req = method(opts, function __res(res) {
var raw = []
var statusCode = res.statusCode
var contentType = res.headers['content-type']
var isJSON = contentType.startsWith('application/json')
var ok = statusCode >= 200 && statusCode < 300
var ok = res.statusCode >= 200 && res.statusCode < 300
if (!ok) {

@@ -47,15 +44,22 @@ callback(Error('GET failed with: ' + statusCode))

// res.setEncoding('utf8')
res.on('data', function(chunk) {raw.push(chunk)})
res.on('end', function(x) {
res.on('data', function __data(chunk) {
raw.push(chunk)
})
res.on('end', function __end() {
var err = null
var result = null
try {
var isJSON = res.headers['content-type'].startsWith('application/json')
var rawData = Buffer.concat(raw).toString()
var parsedData = isJSON? JSON.parse(rawData) : rawData
callback(null, parsedData)
result = isJSON? JSON.parse(rawData) : rawData
}
catch (e) {
callback(e)
err = e
}
callback(err, result)
})
}).on('error', function(e) { callback(Error(e.message)) } )
})
req.on('error', callback)
}

@@ -31,8 +31,5 @@ var qs = require('querystring')

var raw = []
var statusCode = res.statusCode
var contentType = res.headers['content-type']
var isJSON = contentType === 'application/json'
var raw = [] // keep our buffers here
var ok = res.statusCode >= 200 && res.statusCode < 300
var ok = statusCode >= 200 && statusCode < 300
if (!ok) {

@@ -44,17 +41,22 @@ callback(Error(httpMethod + ' failed with: ' + statusCode))

// res.setEncoding('utf8')
res.on('data', function(chunk) { raw.push(chunk) })
res.on('end', function(x) {
res.on('data', function __data(chunk) {
raw.push(chunk)
})
res.on('end', function __end() {
var err = null
var result = null
try {
var isJSON = res.headers['content-type'].startsWith('application/json')
var rawData = Buffer.concat(raw).toString()
var parsedData = isJSON? JSON.parse(rawData) : rawData
callback(null, parsedData)
result = isJSON? JSON.parse(rawData) : rawData
}
catch (e) {
callback(e)
err = e
}
callback(err, result)
})
})
req.on('error', function(e) { callback(Error(e.message)) })
req.on('error', callback)

@@ -61,0 +63,0 @@ req.write(postData)

{
"name": "tiny-json-http",
"version": "3.0.6",
"version": "3.0.7",
"main": "index.js",

@@ -5,0 +5,0 @@ "scripts": {

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