<commit_before>---
title: "Nonintrusive http proxy in nodejs"
layout: "post"
categories: [nodejs, http, proxy]
permalink: "/2014/03/23/nonintrusive-http-proxy-in-nodejs.html"
---

I my previous posts I wrote about problems that might occur when
using http proxy written in nodejs to debug http issues.
Today I'm going to describe how to use nodejs builtin parser to 
overcome these problems.
##Nodejs streams
Node.js has decent support for handling streams. Especially
the `pipe` function takes a lot of burden away - whereas previously
it had to be carefully handled by programmer.
As a first step let's use a simple socket server and tunnel http requests
through it:

```javascript
var net = require('net');
var stdout = process.stdout;
var server = net.createServer(function(clientSocket){
  var serverSocket = net.connect(8888,'localhost', function(){

      clientSocket.pipe(serverSocket);
      clientSocket.pipe(stdout);

      serverSocket.pipe(clientSocket);
      serverSocket.pipe(stdout);

  });
});
server.listen(9000);<commit_msg>Fixed typo<commit_after>---
title: "Nonintrusive http proxy in nodejs"
layout: "post"
categories: [nodejs, http, proxy]
permalink: "/2014/03/23/nonintrusive-http-proxy-in-nodejs.html"
---

In my previous posts I wrote about problems that might occur when
using http proxy written in nodejs to debug http issues.
Today I'm going to describe how to use nodejs builtin parser to 
overcome these problems.
##Nodejs streams
Node.js has decent support for handling streams. Especially
the `pipe` function takes a lot of burden away - whereas previously
it had to be carefully handled by programmer.
As a first step let's use a simple socket server and tunnel http requests
through it:

```javascript
var net = require('net');
var stdout = process.stdout;
var server = net.createServer(function(clientSocket){
  var serverSocket = net.connect(8888,'localhost', function(){

      clientSocket.pipe(serverSocket);
      clientSocket.pipe(stdout);

      serverSocket.pipe(clientSocket);
      serverSocket.pipe(stdout);

  });
});
server.listen(9000);
{'fraction_non_alphanumeric': 0.09482758620689655, 'fraction_numerical': 0.01532567049808429, 'mean_word_length': 4.5855614973262036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4115773', 'n_tokens_mistral': 603, 'n_tokens_neox': 572, 'n_words': 232}