httpp-forward
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -5,3 +5,3 @@ { | ||
"description": "Forward http traffic over httpp/udp with node-httpp", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
52
proxy.js
@@ -34,3 +34,3 @@ // Copyright (c) 2013 Tom Zhou<iwebpp@gmail.com> | ||
} else if (cap && (cap.proto === 'httpp')) { | ||
if (Debug) console.log('Detected httpp, '+JSON.stringify(cap)); | ||
if (Debug) console.log('Detected httpp, '+JSON.stringify(cap)+' for http://'+req.url); | ||
var altport = cap.port; | ||
@@ -111,3 +111,3 @@ | ||
} else if (cap && (cap.proto === 'httpp')) { | ||
if (Debug) console.log('Detected httpp, '+JSON.stringify(cap)); | ||
if (Debug) console.log('Detected httpp, '+JSON.stringify(cap)+' for '+'http://'+srvip+':'+srvport+path); | ||
var altport = cap.port; | ||
@@ -235,3 +235,3 @@ | ||
console.log("http tunnel proxy to NET " + req.url + ", socket error: " + e); | ||
socket.end(); | ||
resErr("http tunnel proxy to NET " + req.url + ", socket error: " + e); | ||
}); | ||
@@ -271,3 +271,4 @@ } | ||
hostname: hostname, | ||
method: 'GET', | ||
///method: 'GET', | ||
method: 'HEAD', | ||
path: path, | ||
@@ -296,2 +297,4 @@ }; | ||
capacity = {proto: 'httpp', port: altport}; | ||
console.log('Detected httpp on '+urle); | ||
} | ||
@@ -310,42 +313,1 @@ | ||
}; | ||
// connect httpp middleware to set httpp capacity in res.headers | ||
Proxy.connect_httpp = function(port) { | ||
var althttpp = /httpp:[0-9]+/gi; | ||
port = port || 80; | ||
return function(req, res, next){ | ||
var reshed = {}; | ||
var _res_writeHead = res.writeHead; | ||
res.writeHead = function(statusCode, reasonPhrase, headers) { | ||
reshed.statusCode = statusCode; | ||
reshed.headers = {}; | ||
if (typeof reasonPhrase === 'object') { | ||
reshed.headers = reasonPhrase; | ||
} else if (typeof headers === 'object') { | ||
reshed.headers = headers; | ||
} | ||
Object.keys(reshed.headers).forEach(function (key) { | ||
res.setHeader(key, reshed.headers[key]); | ||
}); | ||
// set httpp capacity | ||
if ('alternate-protocol' in res.headers) { | ||
if (!althttpp.test(res.headers['alternate-protocol'])) { | ||
res.headers['alternate-protocol'] = 'httpp:'+port+',' + | ||
res.headers['alternate-protocol']; | ||
} | ||
} else { | ||
res.setHeader('alternate-protocol', 'httpp:'+port); | ||
} | ||
// write statusCode | ||
_res_writeHead(reshed.statusCode || 200); | ||
}; | ||
if (next) next(); | ||
}; | ||
}; |
@@ -21,2 +21,3 @@ httpp-forward | ||
* for httpp-forward utility, refer to bin/httpp-forward. to start it, just node bin/httpp-forward --port xxx | ||
* httpp-forward is designed to work with connect-httpp enabled server, https://github.com/InstantWebP2P/connect-httpp | ||
@@ -23,0 +24,0 @@ <br/> |
7
35
15701
269