Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Most efficient way of piping HTTP body through a tunneling proxy
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
axs  
View profile  
 More options Jul 30 2012, 5:18 pm
From: axs <alexst...@gmail.com>
Date: Mon, 30 Jul 2012 14:18:38 -0700 (PDT)
Local: Mon, Jul 30 2012 5:18 pm
Subject: Most efficient way of piping HTTP body through a tunneling proxy

I'm making an http proxy that tunnels data at the transport layer. Here is
the complete code:

var http = require('http');
var net = require('net');
var url = require('url');

var proxy = http.createServer();

// proxy an HTTP request
proxy.on('request', function(req, res){
var uri = url.parse(req.url);
 var httpMessage = req.method + ' ' + uri.path + ' HTTP/'+ req.httpVersion
+ '\r\n';
for(var header in req.headers){
httpMessage += header + ': ' + req.headers[header] + '\r\n';

}

httpMessage += '\r\n';
req.on('data', function(data){
httpMessage += data;
});

req.on('end', function(data){
httpMessage += data;
var client = net.connect(uri.port || 80, uri.hostname, function(){
client.write(httpMessage);
client.pipe(req.connection);
req.connection.pipe(client);

});
});
});

// proxy an HTTPS request
proxy.on('connect', function(req, socket, head) {
  var uri = req.url.split(':')
var tunnel = net.connect({
port: uri[1],
host: uri[0]
}, function() {

socket.write('HTTP/1.1 200 Connection Established\r\n\r\n');
tunnel.write(head);
tunnel.pipe(socket);
socket.pipe(tunnel);

});
});

proxy.listen(8080);

My question has to do with http proxy section: I haven't run into this
problem yet, but I can see that for potentially large HTTP bodies (such as
file transfers), httpMessage may dramatically increase in size. What is the
best way to pipe this data over the client tcp socket as it comes in,
instead of caching the whole thing and sending all at once? Would be even
better if I could just pipe all the parts of the HTTP message (request
line, headers, body, ...) as they come into the server.

Thank for any help in advance.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mikeal Rogers  
View profile  
 More options Jul 30 2012, 5:21 pm
From: Mikeal Rogers <mikeal.rog...@gmail.com>
Date: Mon, 30 Jul 2012 14:21:04 -0700
Local: Mon, Jul 30 2012 5:21 pm
Subject: Re: [nodejs] Most efficient way of piping HTTP body through a tunneling proxy

request does all of this, including SSL tunneling.

req.pipe(request(req.url, {proxy:'https://site.com'})).pipe(resp)

-Mikeal

On Jul 30, 2012, at July 30, 20122:18 PM, axs <alexst...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
axs  
View profile  
 More options Jul 30 2012, 5:40 pm
From: axs <alexst...@gmail.com>
Date: Mon, 30 Jul 2012 14:40:16 -0700 (PDT)
Local: Mon, Jul 30 2012 5:40 pm
Subject: Re: [nodejs] Most efficient way of piping HTTP body through a tunneling proxy

Thank you, Mikeal. I use request quite a bit in my projects, and it's
great. However, I won't be using request for this project, because I need
to write this one at the transport layer. Eventually I will be redirecting
various requests to other servers and examining data at the transport
layer. I just need to make this barebones version function and then branch
from it. Any ideas on how to pipe the request into the socket?

I thought of listening to the 'connection' event on the proxy server, and
piping the socket into the tunnel. But this won't differentiate between
http and https requests without parsing the request header, which I'm not
sure how to do.

Regards,
Alex


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ajc  
View profile  
 More options Aug 2 2012, 5:09 pm
From: ajc <a.johnc...@gmail.com>
Date: Thu, 2 Aug 2012 14:09:01 -0700 (PDT)
Local: Thurs, Aug 2 2012 5:09 pm
Subject: Re: Most efficient way of piping HTTP body through a tunneling proxy

Hi axs,

+1 for request. It will help you massively on the client side. I tried to
do what you're doing a few weeks ago so I could use SSH in cafes. I found
that I had to do write a blank string into the http stream on the client
side to force request to send the request headers though. However, I think
request's 'data' event might give you a String, not a Buffer. This means
that any binary data might get corrupted. You can get round that by making
a base64 stream encoder and decoder, but they have to pass binary data
around as Buffer objects and not strings - stringstream didn't work for me.

Another problem you might get is that some firewalls might make sure that
your full request is sent to the server before any response is delivered,
which would prevent streaming. For instance, vodafone's 3g content filter
will block that implementation. Here is my solution:

https://github.com/johncant/node-http-tunnel

The client polls the server 5 times a second, and they relay all the Stream
events to eachother, keeping track of the streams. Gets through most
unhardcore firewalls. Unfortunately it still gets blocked
by McAfee's firewall, so I can't use it in my local library :(

In the end I just gave up and worked from somewhere devoid of technophobic
luddites :)

John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Diogo Resende  
View profile  
 More options Aug 3 2012, 4:37 am
From: Diogo Resende <drese...@thinkdigital.pt>
Date: Fri, 3 Aug 2012 09:37:48 +0100
Local: Fri, Aug 3 2012 4:37 am
Subject: Re: [nodejs] Most efficient way of piping HTTP body through a tunneling proxy

I'm not sure why you don't use .pipe().. you don't need to buffer all the request before sending it. The headers should have a content-length so your endpoint will know about it. Just send the data directly to the other end instead of buffering.

--
Diogo Resende


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dominic Tarr  
View profile  
 More options Aug 3 2012, 5:31 am
From: Dominic Tarr <dominic.t...@gmail.com>
Date: Fri, 3 Aug 2012 11:31:38 +0200
Local: Fri, Aug 3 2012 5:31 am
Subject: Re: [nodejs] Most efficient way of piping HTTP body through a tunneling proxy
@john I applaud your efforts for FREE WIFI!

does the firewall permit http pipelining?

also, have you heard of dnstunneling? http://dnstunnel.de/

with a little bit more work you could make your http-tunnel into a
reliable stream
that maintained stream semantics over disconnects.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ajc  
View profile  
 More options Aug 5 2012, 11:43 am
From: ajc <a.johnc...@gmail.com>
Date: Sun, 5 Aug 2012 08:43:32 -0700 (PDT)
Local: Sun, Aug 5 2012 11:43 am
Subject: Re: [nodejs] Most efficient way of piping HTTP body through a tunneling proxy

Looks great! I'll need to play around with that. I can't be bothered to
make my http tunnel disconnect proof though, because I've noticed SSH
connections stay open when my wifi has dropped out.

John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
axs  
View profile  
 More options Aug 6 2012, 12:06 am
From: axs <alexst...@gmail.com>
Date: Sun, 5 Aug 2012 21:06:08 -0700 (PDT)
Local: Mon, Aug 6 2012 12:06 am
Subject: Re: [nodejs] Most efficient way of piping HTTP body through a tunneling proxy

 I tried piping but was having issues: The following code throws an "Cannot
call method 'on' of undefined" error at the last line.

proxy.on('request', function(req, res){
var uri = url.parse(req.url);
var httpMessage = req.method + ' ' + uri.path + ' HTTP/'+ req.httpVersion +
'\r\n';
for(var header in req.headers){
httpMessage += header + ': ' + req.headers[header] + '\r\n';

}

httpMessage += '\r\n';
var client = net.connect(uri.port || 80, uri.hostname);
client.write(httpMessage);
req.connection.pipe(client);
client.pipe(res.connection);

});

When I change that last line to client.pipe(req.connection); , it works,
but for some requests I get multiple warnings:

 "(node) warning: possible EventEmitter memory leak detected. 11 listeners
added. Use emitter.setMaxListeners() to increase limit."

at the last two lines. I think I'm piping correctly in the first scenario,
but I'm not sure what the source of errors/warnings is.

Regards,
Alex


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »