indutny/sticky-session — pull request #17 by wzrdtales (2014-12-14 15:42:27+00:00)
Title: Support of Layer 4 Hash Balancing, fixes several issues

# Fixing following Issues

Fixes #15
Fixes #6
Probably Fixes #8, but there maybe is a need to look for more then only x-forwarded-to.

# Introduction

As there was a need to support variables on layer 4 of the OSI Model, because of relying on IPs doesn't work if something is in between node and the user.

### Prolog to Proxied connections

If you're using a proxy, like you do in many constellations, e.g. using a varnish as cache, using a *Cloudflare like* CDN or
using DDoS Protections which are build on a so called *reverse proxy Server*.
There are many cases where you may not be able to avoid proxying the users requests,
before they reach the node Application.

#### The Problem:

If we proxy any connection, the real IP will be lost. The original implementation of sticky-sessions
worked only on layer 3 of the OSI Model. But the Information we need, is right now on layer 4.

**Note:** Only versions smaller than 0.11.4 and greater than 0.9.6 are supported.
The reason for this is that the behavior of onread in net.js has changed:
https://github.com/joyent/node/blob/v0.11.4-release/lib/net.js#L487-L519

# Reasoning the usage of onread core component
As I 'catch' the packet, to parse informations from the http header, I needed to push the packet back to the file descriptor as it has never been received.

This was done by accessing the private element _handler which contains the method onread, which gets called whenever a file descriptor receives a buffer.
https://github.com/joyent/node/blob/v0.10.33-release/lib/net.js#L496-L560