Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

buffered stream with limited size

  • Loading branch information...
commit 7460c9f169aef312f0c02933b05a8046d2d1173e 1 parent 270929f
@peteroconnor authored
Showing with 14 additions and 4 deletions.
  1. +14 −4 lib/server.js
View
18 lib/server.js
@@ -6,6 +6,9 @@ var spdy = require('spdy'),
url = require('url'),
fs = require('fs');
+//https://github.com/flatiron/union/blob/master/lib/buffered-stream.js
+var union = require('union')
+
var SPDYProxy = function(options) {
function logRequest(req) {
console.log(req.method.green + ' ' + req.url.yellow);
@@ -30,6 +33,7 @@ var SPDYProxy = function(options) {
}
function handlePlain(req, res) {
+ var buffer = new union.BufferedStream(1024 * 1024 / 2)
var path = req.headers.path || url.parse(req.url).path;
var requestOptions = {
host: req.headers.host,
@@ -45,7 +49,8 @@ var SPDYProxy = function(options) {
// write out headers to handle redirects
res.writeHead(rres.statusCode, '', rres.headers);
- rres.pipe(res);
+ rres.pipe(buffer);
+ buffer.pipe(res);
});
rreq.on('error', function(e) {
@@ -54,10 +59,12 @@ var SPDYProxy = function(options) {
res.end();
});
- req.pipe(rreq);
+ req.pipe(buffer);
+ buffer.pipe(rreq);
}
function handleSecure(req, socket) {
+ var buffer = new union.BufferedStream(1024 * 1024 / 2)
var dest = req.headers.host.split(':');
var tunnel = net.createConnection(dest[1] || 443, dest[0], function() {
synReply(socket, 200, 'Connection established',
@@ -66,8 +73,11 @@ var SPDYProxy = function(options) {
'Proxy-Agent': 'SPDY Proxy ' + options.version
},
function() {
- tunnel.pipe(socket);
- socket.pipe(tunnel);
+ tunnel.pipe(buffer);
+ buffer.pipe(socket);
+
+ socket.pipe(buffer);
+ buffer.pipe(tunnel);
}
);
});
Please sign in to comment.
Something went wrong with that request. Please try again.