New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hyperswitch

Package Overview
Dependencies
Maintainers
4
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hyperswitch - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

test/hyperswitch/gzipping_module.js

4

.jscs.json

@@ -13,3 +13,5 @@ {

"validateIndentation": 4,
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
"requireCamelCaseOrUpperCaseIdentifiers": {
"ignoreProperties": true
},
"requireCapitalizedComments": null,

@@ -16,0 +18,0 @@ "maximumLineLength": 100,

@@ -167,2 +167,27 @@ 'use strict';

/**
* Removes Hop-To-Hop headers that might be
* proxied from a backend service
*
* @param {Object} rh response headers
* @private
*/
function removeHopToHopHeaders(rh) {
[
'connection',
'keep-alive',
'public',
'proxy-authenticate',
'transfer-encoding',
'content-length',
'content-encoding'
].forEach(function(headerName) {
// Need to delete properties and not set to undefined
// because node passes 'undefined' to client.
if (rh[headerName]) {
delete rh[headerName];
}
});
}
// Special handling for external web requests

@@ -183,4 +208,9 @@ HyperSwitch.prototype.defaultWebRequestHandler = function(req) {

req.uri = '' + req.uri;
// Call P.resolve to make sure we have a bluebird Promise
return P.resolve(preq(req));
return preq(req)
.then(function(res) {
if (res && res.headers) {
removeHopToHopHeaders(res.headers);
}
return res;
});
};

@@ -187,0 +217,0 @@

@@ -118,28 +118,2 @@ "use strict";

/**
* Removes Hop-To-Hop headers that might be
* proxied from a backend service
*
* @param {Object} rh response headers
* @private
*/
function removeHopToHopHeaders(rh) {
[
'connection',
'keep-alive',
'public',
'proxy-authenticate',
'transfer-encoding',
'content-length',
'content-encoding'
].forEach(function(headerName) {
// Need to delete properties and not set to undefined
// because node passes 'undefined' to client.
if (rh[headerName]) {
delete rh[headerName];
}
});
}
/**
* Set up basic CORS in response headers

@@ -161,3 +135,3 @@ *

removeHopToHopHeaders(rh);
delete rh['content-length'];
setCORSHeaders(rh);

@@ -237,3 +211,4 @@

if (/\bgzip\b/.test(req.headers['accept-encoding'])
&& /^application\/json\b|^text\//.test(cType)) {
&& /^application\/json\b|^text\//.test(cType)
&& rh['content-encoding'] !== 'gzip') {
rh['content-encoding'] = 'gzip';

@@ -248,2 +223,13 @@ resp.writeHead(response.status, '', rh);

}
} else if (rh['content-encoding'] === 'gzip'
&& !/\bgzip\b/.test(req.headers['accept-encoding'])) {
delete rh['content-encoding'];
resp.writeHead(response.status, '', rh);
var unzStream = zlib.createGunzip();
unzStream.pipe(resp);
if (bodyIsStream) {
body.pipe(unzStream);
} else {
unzStream.end(body);
}
} else if (bodyIsStream) {

@@ -250,0 +236,0 @@ resp.writeHead(response.status, '', rh);

{
"name": "hyperswitch",
"version": "0.3.2",
"version": "0.3.3",
"description": "REST API creation framework",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -16,3 +16,3 @@ "use strict";

describe('Documentation handling', function() {
describe('Filters', function() {
var server = new Server('test/hyperswitch/filters_config.yaml');

@@ -19,0 +19,0 @@

@@ -193,3 +193,2 @@ 'use strict';

assert.deepEqual(res.status, 200);
assert.deepEqual(res.headers.hasOwnProperty('transfer-encoding'), false);
assert.deepEqual(res.headers.hasOwnProperty('public'), false);

@@ -211,3 +210,28 @@ assert.deepEqual(res.headers.hasOwnProperty('content-encoding'), false);

it('Should not gzip already gzipped content', function() {
return preq.get({
uri: server.hostPort + '/service/gzip/get'
})
.then(function(res) {
assert.deepEqual(res.status, 200);
assert.deepEqual(res.body.toString(), 'TEST');
});
});
it('Should unzip content if it is not accepted', function() {
return preq.get({
uri: server.hostPort + '/service/gzip/get',
headers: {
'accept-encoding': 'identity'
},
gzip: false
})
.then(function(res) {
assert.deepEqual(res.status, 200);
assert.deepEqual(res.headers.hasOwnProperty('content-encoding'), false);
assert.deepEqual(res.body.toString(), 'TEST');
});
});
after(function() { return server.stop(); });
});

Sorry, the diff of this file is not supported yet

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