Socket
Socket
Sign inDemoInstall

nodecap2

Package Overview
Dependencies
23
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.0.1

3

examples/example.js

@@ -73,3 +73,3 @@ var ICAPServer = require('../').ICAPServer;

} else {
icapRes.setHttpMethod(res);
icapRes.setHttpStatus(res.code);
icapRes.setHttpHeaders(res.headers);

@@ -104,2 +104,3 @@ }

}
icapRes.end();
};

@@ -106,0 +107,0 @@

@@ -51,3 +51,3 @@ var ICAPServer = require('../').ICAPServer;

} else {
icapRes.setHttpMethod(res);
icapRes.setHttpStatus(res.code); // or icapRes.setHttpStatus(res);
icapRes.setHttpHeaders(res.headers);

@@ -54,0 +54,0 @@ }

{
"name": "nodecap2",
"version": "2.0.0",
"version": "2.0.1",
"description": "ICAP server framework for node.js - create custom HTTP proxy filters for Squid, etc.",

@@ -11,7 +11,5 @@ "main": "index.js",

"dependencies": {
"eventemitter2": "~0.4.13",
"datauri": "~0.4.0",
"lodash": "~2.4.1",
"q": "~1.0.0",
"winston": "^0.7.3"
"eventemitter2": "^0.4.14",
"lodash": "^4.3.0",
"winston": "^2.1.1"
},

@@ -18,0 +16,0 @@ "optionalDependencies": {

nodecap2
=======
[![Join the chat at https://gitter.im/horpto/nodecap2](https://badges.gitter.im/horpto/nodecap2.svg)](https://gitter.im/horpto/nodecap2?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
It is fork of [nodecap](https://www.npmjs.com/package/nodecap) with some fixes and performance improvements.

@@ -5,0 +7,0 @@ I didn't change gh pages, docs and tests yet.

@@ -7,2 +7,4 @@ "use strict";

'Switching to new protocol; obey Upgrade header'],
102: ['Processing',
'This code indicates that the server has received and is processing the request, but no response is available yet.'],

@@ -17,2 +19,8 @@ 200: ['OK', 'Request fulfilled, document follows'],

206: ['Partial Content', 'Partial content follows.'],
207: ['Multi-Status',
'The message body that follows is an XML message and can contain a number of separate response codes, depending on how many sub-requests were made.'],
208: ['Already Reported',
'The members of a DAV binding have already been enumerated in a previous reply to this request, and are not being included again.'],
226: ['IM Used',
'The server has fulfilled a request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance.'],

@@ -27,5 +35,9 @@ 300: ['Multiple Choices',

305: ['Use Proxy',
'You must use proxy specified in Location to access thisresource.'],
'You must use proxy specified in Location to access this resource.'],
306: ['Switch Proxy',
'Subsequent requests should use the specified proxy.'],
307: ['Temporary Redirect',
'Object moved temporarily -- see URI list'],
308: ['Permanent Redirect',
'The request, and all future requests should be repeated using another URI. 307 and 308 parallel the behaviours of 302 and 301, but do not allow the HTTP method to change.'],

@@ -58,2 +70,21 @@ 400: ['Bad Request',

'Expect condition could not be satisfied.'],
419: ['Authentication Timeout',
'419 Authentication Timeout denotes that previously valid authentication has expired.'],
421: ['Misdirected Request',
'The request was directed at a server that is not able to produce a response'],
422: ['Unprocessable Entity',
'The request was well-formed but was unable to be followed due to semantic errors.'],
423: ['Locked',
'The resource that is being accessed is locked.'],
424: ['Failed Dependency',
'The request failed due to failure of a previous request.'],
426: ['Upgrade Required',
'The client should switch to a different protocol such as TLS/1.0, given in the Upgrade header field.'],
428: ['Precondition Required',
'The origin server requires the request to be conditional.'],
429: ['Too Many Requests',
'The user has sent too many requests in a given amount of time. Intended for use with rate limiting schemes.'],
431: ['Request Header Fields Too Large',
'The server is unwilling to process the request because either an individual header field, or all the header fields collectively, are too large.'],
451: ['Unavailable For Legal Reasons', 'Resource access is denied due to legal demands.'],

@@ -69,2 +100,38 @@ 500: ['Internal Server Error', 'Server got itself in trouble'],

505: ['Protocol Version Not Supported', 'Cannot fulfill request.'],
506: ['Variant Also Negotiates',
'Transparent content negotiation for the request results in a circular reference.'],
507: ['Insufficient Storage',
'The server is unable to store the representation needed to complete the request.'],
508: ['Loop Detected',
'The server detected an infinite loop while processing the request.'],
510: ['Not Extended',
'Further extensions to the request are required for the server to fulfil it.'],
511: ['Network Authentication Required',
'The client needs to authenticate to gain network access.'],
// Unofficial HTTP Codes
418: ['I\'m a teapot',
'The RFC specifies this code should be returned by tea pots requested to brew coffee.'],
440: ['Login Timeout',
'The client\'s session has expired and must log in again.'],
449: ['Retry With',
'The server cannot honour the request as the user has not provided the required information.'],
450: ['Blocked by Parental Controls',
'A Custom extension. This error is given when Parental Controls are turned on and are blocking access to the given webpage.'],
// NGINX Error Codes
444: ['No Response',
'Used to indicate that the server has returned no information to the client and closed the connection.'],
495: ['SSL Certificate Error',
'An expansion of the 400 Bad Request response code, used when the client has provided an invalid client certificate.'],
496: ['SSL Certificate Required',
'An expansion of the 400 Bad Request response code, used when a client certificate is required but not provided.'],
497: ['HTTP Request Sent to HTTPS Port',
'An expansion of the 400 Bad Request response code, used when the client has made a HTTP request to a port listening for HTTPS requests.'],
499: ['Client Closed Request',
'Used when the client has closed the request before the server could send a response.'],
// Apache Error code
509: ['Bandwidth Limit Exceeded',
'The server has exceeded the bandwidth specified by the server administrator'],
};
"use strict";
var url = require('url');
var querystring = require('querystring');

@@ -55,2 +56,16 @@ // read from start/0 up to the next newline. returns null if no newline found, else

// some urls were not parsing correctly (twitter.com) as they had ports included (twitter.com:443)
// partially copied from isaacs/url-parse-as-address and optimised
var parseUrlOrAddress = function parseUrlOrAddress(uri) {
var parsed = url.parse(uri, false);
if (!parsed.slashes) {
parsed = url.parse('http://' + uri, false);
} else if (!parsed.protocol) {
parsed = url.parse('http:' + uri, false);
}
parsed.query = querystring.parse(parsed.query);
return parsed;
}
// read from start/0 up to the next newline and parse as a HTTP/ICAP method line.

@@ -75,3 +90,3 @@ // returns null if not valid method line or:

var uri = tokens.shift();
var parsedUri = url.parse(uri, true);
var parsedUri = parseUrlOrAddress(uri);
var version = tokens.join(' ');

@@ -78,0 +93,0 @@ return {

"use strict";
var net = require('net');
var url = require('url');
var util = require('util');
var _ = require('lodash');

@@ -49,2 +47,3 @@

initialize: function() {
var self = this;
var socket = this.socket;

@@ -54,39 +53,39 @@ socket.setTimeout(0);

socket.on('connect', function() {
this.logger.debug('[%s] socket connect', this.id);
this.emitEvent('connect');
}.bind(this));
self.logger.debug('[%s] socket connect', self.id);
self.emitEvent('connect');
});
socket.on('data', function(data) {
if (this.buffer.length == 0) {
this.buffer = data;
if (self.buffer.length == 0) {
self.buffer = data;
} else {
this.buffer = Buffer.concat([this.buffer, data], this.buffer.length + data.length);
self.buffer = Buffer.concat([self.buffer, data], self.buffer.length + data.length);
}
this.nextState();
}.bind(this));
self.nextState();
});
socket.on('end', function() {
this.logger.debug('[%s] socket end', this.id);
this.emitEvent('closed');
socket.end();
}.bind(this));
self.logger.debug('[%s] socket end', self.id);
self.emitEvent('closed');
socket.destroy();
});
socket.on('timeout', function() {
this.logger.debug('[%s] socket timeout', this.id);
}.bind(this));
self.logger.debug('[%s] socket timeout', self.id);
});
socket.on('close', function() {
this.logger.debug('[%s] socket close', this.id);
}.bind(this));
self.logger.debug('[%s] socket close', self.id);
});
socket.on('error', function(err) {
this.logger.error('[%s] socket error "%s"', this.id, err.message || 'Unknown Error');
self.logger.error('[%s] socket error "%s"', self.id, err.message || 'Unknown Error');
// notify the error handler not to process the response further
if (this.icapResponse) {
this.icapResponse.done = true;
if (self.icapResponse) {
self.icapResponse.done = true;
}
this.emitError(err);
socket.end();
}.bind(this));
self.emitError(err);
socket.destroy();
});
},

@@ -144,3 +143,3 @@

this.emitError(err);
this.socket.end();
this.socket.destroy();
}

@@ -250,3 +249,3 @@ }

while ((header = this.read(helpers.header)) !== null) {
_.extend(headers, header.header);
_.assign(headers, header.header);

@@ -315,3 +314,3 @@ if (this.read(helpers.newline).newline) {

}
_.extend(this.httpRequest, method);
this.httpRequest.setMethod(method);

@@ -335,3 +334,3 @@ var headers = this.readAllHeaders();

}
_.extend(this.httpResponse, status);
_.assign(this.httpResponse, status);

@@ -338,0 +337,0 @@ var headers = this.readAllHeaders();

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

_.extend(ICAPRequest.prototype, {
_.assign(ICAPRequest.prototype, {
push: function(data) {

@@ -27,0 +27,0 @@ if (this.stream) {

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

_.extend(ICAPResponse.prototype, {
_.assign(ICAPResponse.prototype, {
_getCode: function(code, options) {

@@ -41,3 +41,3 @@ code = code || 500;

setIcapHeaders: function(headers) {
this.icapHeaders = _.extend(this.icapHeaders || {}, headers);
this.icapHeaders = _.assign(this.icapHeaders || {}, headers);
},

@@ -59,3 +59,3 @@ setHttpMethod: function(options) {

setHttpHeaders: function(headers) {
this.httpHeaders = _.extend(this.httpHeaders || {}, headers);
this.httpHeaders = _.assign(this.httpHeaders || {}, headers);
},

@@ -62,0 +62,0 @@ hasFilter: function() {

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

ICAPServer.prototype = _.extend({}, EventEmitter2.prototype, {
ICAPServer.prototype = _.assign({}, EventEmitter2.prototype, {
constructor: ICAPServer,

@@ -152,0 +152,0 @@

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

_.extend(Request.prototype, {
_.assign(Request.prototype, {
setHeaders: function(headers) {

@@ -24,6 +24,6 @@ if (!this.headers) {

}
_.extend(this.headers, headers);
_.assign(this.headers, headers);
},
setMethod: function(method) {
_.extend(this, method);
_.assign(this, method);
if (!this.parsedUri) {

@@ -30,0 +30,0 @@ this.parsedUri = {

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

_.extend(Response.prototype, {
_.assign(Response.prototype, {
setHeaders: function(headers) {

@@ -23,4 +23,4 @@ if (!this.headers) {

}
_.extend(this.headers, headers);
_.assign(this.headers, headers);
}
});
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc