npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

proxied-socket

v1.2.2

Published

proxied-socket ---

Downloads

5

Readme

proxied-socket

NPM Version Build Build Test Coverage MIT licensed

Proxies are commonly used to keep undisclosed the Server original IP address to the clients. Normal TCP level proxies have a big issue, they do even mask the Client IP address to the Server that just sees the Proxy IP address.

proxied-socket is meant to solve this issue. To do so, proxied-socket provides unobtrusive IP address forwarding support for Node.js sockets.

It is composed of two components the Client and the Server.

Client

The Client side API allows to add an header that contains an IP address. Proxies can use it to forward the remote Client IP address.

var ps = require('proxied-socket'),
    net = require('net');

var remote = {port: 1234};

var server = net.wrapServer(function (source) {
    var target = net.connect(options, forwarded);
    ps.sendHeader(source, target); // you just need this
    source.pipe(target).pipe(source);
});
server.listen(80);

Server

The Server side API allows to intercept the header present at the beginning of every connection and to attach the IP address present in it to relative socket.

The are two methods:

  • attach which attaches the original socket information as the properties originalRemoteFamily, originalRemoteAddress, originalRemotePort, originalLocalAddress and originalLocalPort
  • override (default) which moves the original socket information remoteFamily, remoteAddress, remotePort, localAddress and remotePorts to the respective property maskedRemoteFamily, maskedRemoteAddress, ... while replacing them with the information obtained from the header

And two supported formats:

  • default is compatible with the proxied-socket.Client. If you are writing both the proxy and server, this is the format to use. It is also the default format.
  • haproxy and haproxy-v2 are compatible with the HAProxy PROXY protocol V1 and v2.If you are writing a server that will be load balanced by HAProxy, this is the format you will want. More information about the PROXY protcol can be found at the following link. https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt

In both cases the full parsed header is attached to the proxyHeader property of the socket.

var ps = require('proxied-socket'),
    net = require('net');

var server = ps.wrapServer(net.Server(function (client) { // you just need to wrap your server
    console.log(client.remoteAddress);
}),
{
    method: 'override'
    format: 'default',
});
server.listen(1234);

Without proxied-socket the server would always log the same address. With proxied-socket the server instead logs the real address of the remote client.