On Thu, Feb 7, 2013 at 6:02 AM, V'Raj Kanwade <[email protected]> wrote: > Ok. Let me rephrase the question: > > I am inside connectionHandler of net.createServer. Now when I determine the > data from client is HTTP request, I want to convert it to HTTPRequest object > so that I can leverage the HTTP headers, status code parsing etc. > > It is some client requirement where the proxy has to listen to http, https > and custom protocol on same port.
I suggest you go with something like this: https://gist.github.com/bnoordhuis/4740141 The salient part: function tcpConnection(conn) { conn.once('data', function(buf) { // A TLS handshake record starts with byte 22. var address = (buf[0] === 22) ? httpsAddress : httpAddress; var proxy = net.createConnection(address, function() { proxy.write(buf); conn.pipe(proxy).pipe(conn); }); }); } You sniff the first packet and forward it to the right server, depending on whether it's a TLS handshake. The HTTP and HTTPS servers are listening on UNIX sockets in this example but that could be regular TCP ports, of course. -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
