sintaxi/harp — pull request #323 by shovon (2014-08-13 05:14:01+00:00)
Title: Added option to specify address to listen on

I noticed how Harp is unable to listen on alternative IP addresses, other than Node.js' default `0.0.0.0`. I suggest that we have the option to specify which IP address that Harp will listen on.

This pull request adds an `-a` or `--address` option to Harp's command-line utility, and Harp's API now accepts an `address` option when calling the `server` method.

--------

Typically, when an application is listening on `0.0.0.0`, all packets sent to the host will be sent to the application that is listening on `0.0.0.0` (assuming that there aren't any application listening on *the* specific IP address of the host, e.g. `192.168.1.70`).

Contrast `0.0.0.0` to the loopback IP address, `127.0.0.1`. When the operating system receives either TCP or UDP packets that are not from the loopback address, if there aren't any applications listening on either the address assigned to the network interface (again, e.g. `192.168.1.70`), *or* `0.0.0.0`, then the operating system will simply drop those packets.

And, as a result, **allowing applications (i.e. Harp) to listen on loopback allows for a certain level of privacy**.

A use case here is when Harp is sitting behind a reverse proxy. More often than not, Harp being proxied is most likely listening on a port *other* than `80`, say, `9000`. If Harp were to listen on `0.0.0.0`, then clients will be able to request the site on *both* ports `80`, *and*, `9000`, which may be an undesirable result for many website admins.

And so, for the sake of security, it might be a good idea to allow users to specify what address to listen on.

I was indirectly motivated to issue this pull request based on #294.