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

rocky

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rocky - npm Package Compare versions

Comparing version 0.4.11 to 0.4.12

36

lib/middleware/response-body.js

@@ -22,2 +22,5 @@ const zlib = require('zlib')

// Cache http.ServerResponse prototype chain for future use
const resProto = Object.getPrototypeOf(res)
var buf = []

@@ -99,3 +102,3 @@ var length = 0

function finisher (cb, err, body, encoding) {
if (isEnded()) return cb && cb()
if (isEnded() || res.headersSent) return cb && cb()

@@ -109,24 +112,19 @@ if (err) {

const finalEncoding = encoding || res._originalEncoding
var finalBody = body || res.body
res.body = body == null ? res.body : body
if (isGzip(res, headArgs)) {
finalBody = deflate(finalBody)
res.body = deflate(res.body)
}
// Set the proper new content length
if (finalBody) {
res.setHeader('content-length', Buffer.byteLength(finalBody))
}
// Set content length response header
setContentLength(res)
// Write the response head
if (headArgs && !res.headersSent) {
res.writeHead(headArgs)
res.writeHead.apply(res, headArgs)
}
// Write body
res.write(finalBody, finalEncoding)
resProto.write.call(res, res.body, finalEncoding)
// Be sure we expose the final body in the response
if (finalBody) res.body = finalBody
// Clean references to prevent leaks

@@ -136,3 +134,3 @@ cleanup()

// Send EOF
res.end(cb)
resProto.end.call(res, cb)
}

@@ -161,2 +159,12 @@

function setContentLength (res) {
if (typeof res.body === 'string') {
return res.setHeader('content-length', Buffer.byteLength(res.body))
}
if (Buffer.isBuffer(res.body)) {
return res.setHeader('content-length', res.body.length)
}
res.setHeader('content-length', 0)
}
function parseJSON (res) {

@@ -173,3 +181,3 @@ if (res.json) return

function isGzip (res, head) {
return res.getHeader('content-encoding') === 'gzip' ||
return (res.body && res.getHeader('content-encoding') === 'gzip') ||
(head && head[1] && head[1]['content-encoding'] === 'gzip') ||

@@ -176,0 +184,0 @@ false

{
"name": "rocky",
"version": "0.4.11",
"version": "0.4.12",
"description": "Full-featured, middleware-oriented, hackable HTTP and WebSocket proxy",

@@ -5,0 +5,0 @@ "repository": "h2non/rocky",

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