Comparing version 0.2.1 to 0.2.10
@@ -76,3 +76,7 @@ var ICAPServer = require('../').ICAPServer; | ||
} | ||
icapRes.writeHeaders(icapReq.hasBody()); | ||
var hasBody = icapReq.hasBody(); | ||
if (hasBody) { | ||
icapRes.continuePreview(); | ||
} | ||
icapRes.writeHeaders(hasBody); | ||
icapReq.pipe(icapRes); | ||
@@ -79,0 +83,0 @@ }; |
@@ -54,3 +54,7 @@ var ICAPServer = require('../').ICAPServer; | ||
} | ||
icapRes.writeHeaders(icapReq.hasBody()); | ||
var hasBody = icapReq.hasBody(); | ||
if (hasbody) { | ||
icapRes.continuePreview(); | ||
} | ||
icapRes.writeHeaders(hasBody); | ||
icapReq.pipe(icapRes); | ||
@@ -57,0 +61,0 @@ }; |
{ | ||
"name": "nodecap2", | ||
"version": "0.2.1", | ||
"version": "0.2.10", | ||
"description": "ICAP server framework for node.js - create custom HTTP proxy filters for Squid, etc.", | ||
@@ -17,3 +17,3 @@ "main": "index.js", | ||
}, | ||
"optionalDependencies":{ | ||
"optionalDependencies": { | ||
"mmmagic": "~0.3.6" | ||
@@ -20,0 +20,0 @@ }, |
@@ -31,3 +31,6 @@ nodecap2 | ||
var server = new ICAPServer({ | ||
debug: false | ||
debug: false, | ||
// 4096 by default - size of chunks that will send to Squid | ||
// 0 - not slice big chunks by chunkSize | ||
chunkSize: 0 | ||
}); | ||
@@ -34,0 +37,0 @@ console.log('Starting ICAP server...'); |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
module.exports = { | ||
@@ -2,0 +4,0 @@ 100: ['Continue', 'Request received, please continue'], |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var fs = require('fs'); | ||
@@ -2,0 +4,0 @@ var path = require('path'); |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var url = require('url'); | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var util = require('util'); | ||
@@ -8,2 +10,2 @@ var Request = require('./request'); | ||
}; | ||
util.inherits(HTTPRequest, Request); | ||
util.inherits(HTTPRequest, Request); |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var util = require('util'); | ||
@@ -8,2 +10,2 @@ var Response = require('./response'); | ||
}; | ||
util.inherits(HTTPResponse, Response); | ||
util.inherits(HTTPResponse, Response); |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var util = require('util'); | ||
@@ -2,0 +4,0 @@ var codes = require('./codes'); |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var net = require('net'); | ||
@@ -33,2 +35,3 @@ var url = require('url'); | ||
this.logger = options.logger; | ||
this.options = options; | ||
this.buffer = new Buffer(0); | ||
@@ -52,3 +55,3 @@ this.bufferIndex = 0; | ||
this.logger.debug('[%s] socket connect', this.id); | ||
this.emitEvent('connnect'); | ||
this.emitEvent('connect'); | ||
}.bind(this)); | ||
@@ -99,3 +102,3 @@ | ||
resetState :function(isFirstReset) { | ||
resetState: function(isFirstReset) { | ||
if (!isFirstReset) { | ||
@@ -112,3 +115,3 @@ this.emitEvent('end'); | ||
this.icapRequest = new ICAPRequest(this.id); | ||
this.icapResponse = new ICAPResponse(this.id, this.socket); | ||
this.icapResponse = new ICAPResponse(this.id, this.socket, this.options); | ||
this.httpRequest = new HTTPRequest(); | ||
@@ -128,3 +131,3 @@ this.httpResponse = new HTTPResponse(); | ||
nextState : function(state, offset) { | ||
nextState: function(state, offset) { | ||
if (!this.nextIfNotDone()) { | ||
@@ -268,3 +271,3 @@ return; | ||
this.logger.verbose('[%s] icapmethod %s', this.id, JSON.stringify(method)); | ||
this.logger.verbose('[%s] icapmethod %j', this.id, method, ''); | ||
this.emitEvent('icapMethod'); | ||
@@ -281,3 +284,3 @@ this.nextState(states.icapheader); | ||
this.icapRequest.setHeaders(headers); | ||
this.logger.verbose('[%s] icapheader %s', this.id, JSON.stringify(this.icapRequest.headers)); | ||
this.logger.verbose('[%s] icapheader %j', this.id, this.icapRequest.headers, ''); | ||
this.emitEvent('icapHeaders'); | ||
@@ -322,3 +325,3 @@ this.icapBodyStartIndex = this.bufferIndex; | ||
this.httpRequest.setHeaders(headers); | ||
this.logger.verbose('[%s] requestheader %s', this.id, JSON.stringify(this.httpRequest)); | ||
this.logger.verbose('[%s] requestheader %j', this.id, this.httpRequest, ''); | ||
if (this.icapRequest.isReqMod() && !this.parsePreview) { | ||
@@ -342,3 +345,3 @@ this.emitEvent('httpRequest'); | ||
this.httpResponse.setHeaders(headers); | ||
this.logger.verbose('[%s] responseheader %s', this.id, JSON.stringify(this.httpResponse)); | ||
this.logger.verbose('[%s] responseheader %j', this.id, this.httpResponse, ''); | ||
if (this.icapRequest.isRespMod() && !this.parsePreview) { | ||
@@ -361,2 +364,5 @@ this.emitEvent('httpResponse'); | ||
this.icapRequest.preview = this.previewBuffer; | ||
if (this.previewBuffer.length === 0) { | ||
this.previewBuffer = null; | ||
} | ||
this.parsePreview = false; | ||
@@ -413,2 +419,3 @@ this.state = states.parsebody; | ||
this.bufferIndex = 0; | ||
this.waitOffset = 0; | ||
} | ||
@@ -415,0 +422,0 @@ } |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var util = require('util'); | ||
@@ -2,0 +4,0 @@ var _ = require('lodash'); |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var util = require('util'); | ||
@@ -8,3 +10,3 @@ var _ = require('lodash'); | ||
var ICAPResponse = module.exports = function(id, stream) { | ||
var ICAPResponse = module.exports = function(id, stream, options) { | ||
Response.call(this); | ||
@@ -18,2 +20,8 @@ this.stream = stream; | ||
this.allowUnchangedAllowed = true; | ||
this.chunkSize = 'chunkSize' in options ? options.chunkSize : 4096; | ||
this.icapStatus = null; | ||
this.icapHeaders = null; | ||
this.httpMethod = null; | ||
this.httpHeaders = null; | ||
this.buffer = null; | ||
}; | ||
@@ -135,9 +143,10 @@ util.inherits(ICAPResponse, Response); | ||
} | ||
if (data.length > 4096) { | ||
tmp = data.slice(0, 4096); | ||
data = data.slice(4096); | ||
if (this.chunkSize && data.length > this.chunkSize) { | ||
var size = this.chunkSize; // 4096 bytes by default | ||
tmp = data.slice(0, size); | ||
data = data.slice(size); | ||
while (tmp.length) { | ||
this._write(tmp); | ||
tmp = data.slice(0, 4096); | ||
data = data.slice(4096); | ||
tmp = data.slice(0, size); | ||
data = data.slice(size); | ||
} | ||
@@ -144,0 +153,0 @@ return; |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var net = require('net'); | ||
@@ -30,3 +32,4 @@ var util = require('util'); | ||
options = _.defaults(options || {}, { | ||
logger: this.logger | ||
logger: this.logger, | ||
chunkSize: 4096 | ||
}); | ||
@@ -43,2 +46,10 @@ | ||
this.on('error', function(err, icapReq, icapRes) { | ||
function next() { | ||
var fn = cbs[ix++]; | ||
if (!fn || icapRes.done) { | ||
return; | ||
} | ||
fn.call(self, err, icapReq, icapRes, next); | ||
} | ||
var ix, cbs, self = this; | ||
@@ -48,9 +59,2 @@ try { | ||
cbs = this.errorCallbacks; | ||
function next() { | ||
var fn = cbs[ix++]; | ||
if (!fn || icapRes.done) { | ||
return; | ||
} | ||
fn.call(self, err, icapReq, icapRes, next); | ||
} | ||
next(); | ||
@@ -71,2 +75,14 @@ } catch (e) { | ||
this.on('icapOptions', function(icapReq, icapRes) { | ||
function next() { | ||
var fn = cbs[ix++]; | ||
if (!fn || icapRes.done) { | ||
return; | ||
} | ||
if (!fn[0] || fn[0].test(pathname)) { | ||
fn[1].call(self, icapReq, icapRes, next); | ||
} else { | ||
next(); | ||
} | ||
} | ||
var ix, cbs, pathname, self = this; | ||
@@ -77,13 +93,2 @@ try { | ||
pathname = icapReq.parsedUri.pathname; | ||
function next() { | ||
var fn = cbs[ix++]; | ||
if (!fn || icapRes.done) { | ||
return; | ||
} | ||
if (!fn[0] || fn[0].test(pathname)) { | ||
fn[1].call(self, icapReq, icapRes, next); | ||
} else { | ||
next(); | ||
} | ||
} | ||
next(); | ||
@@ -98,2 +103,14 @@ this.logger.info('%s OPTIONS - %s %s', this.id, (icapRes.icapStatus || [null,null,null]).join(' '), (icapRes.httpMethod || [null,null,null]).join(' ')); | ||
this.on('httpRequest', function(icapReq, icapRes, req, res) { | ||
function next() { | ||
var fn = cbs[ix++]; | ||
if (!fn || icapRes.done) { | ||
return; | ||
} | ||
if (!fn[0] || fn[0].contains(host)) { | ||
fn[1].call(this, icapReq, icapRes, req, res, next); | ||
} else { | ||
next(); | ||
} | ||
} | ||
var ix, cbs, host, self = this; | ||
@@ -104,13 +121,2 @@ try { | ||
host = req.parsedUri.hostname; | ||
function next() { | ||
var fn = cbs[ix++]; | ||
if (!fn || icapRes.done) { | ||
return; | ||
} | ||
if (!fn[0] || fn[0].contains(host)) { | ||
fn[1].call(this, icapReq, icapRes, req, res, next); | ||
} else { | ||
next(); | ||
} | ||
} | ||
next(); | ||
@@ -125,2 +131,14 @@ this.logger.info('%s REQMOD - %s - %s %s - %s', this.id, (icapRes.icapStatus || [null,null,null]).join(' '), req.method, req.parsedUri.protocol + '//' + req.parsedUri.host + req.parsedUri.pathname, (icapRes.httpMethod || [null,null,null]).join(' ')); | ||
this.on('httpResponse', function(icapReq, icapRes, req, res) { | ||
function next() { | ||
var fn = cbs[ix++]; | ||
if (!fn || icapRes.done) { | ||
return; | ||
} | ||
if (!fn[0] || fn[0].contains(host)) { | ||
fn[1].call(self, icapReq, icapRes, req, res, next); | ||
} else { | ||
next(); | ||
} | ||
} | ||
var ix, cbs, host, self = this; | ||
@@ -131,13 +149,2 @@ try { | ||
host = req.parsedUri.hostname; | ||
function next() { | ||
var fn = cbs[ix++]; | ||
if (!fn || icapRes.done) { | ||
return; | ||
} | ||
if (!fn[0] || fn[0].contains(host)) { | ||
fn[1].call(self, icapReq, icapRes, req, res, next); | ||
} else { | ||
next(); | ||
} | ||
} | ||
next(); | ||
@@ -144,0 +151,0 @@ this.logger.info('%s RESPMOD - %s - %s %s - %s', this.id, (icapRes.icapStatus || [null,null,null]).join(' '), req.method, req.parsedUri.protocol + '//' + req.parsedUri.host + req.parsedUri.pathname, (icapRes.httpMethod || [null,null,null]).join(' ')); |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var util = require('util'); | ||
@@ -2,0 +4,0 @@ var _ = require('lodash'); |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var util = require('util'); | ||
@@ -2,0 +4,0 @@ var _ = require('lodash'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76683
1947
100