Giter Club home page Giter Club logo

proxy-protocol-v2's Introduction

proxy-protocol-v2

Overview

A simple encoder and decoder for proxy protocol headers using the v1 text and v2 binary formats.

See http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt for details.

Supports IPv4 and IPv6, UDP and TCP, but not UNIX sockets.

install

npm install proxy-protocol-v2

encode

Separate v1 and v2 encoders are provided.

var buf = require('proxy-protocol-v2').v2_encode(socket);

or

var buf = require('proxy-protocol-v2').v2_encode({
  remoteFamily: 'IPv4',
  remoteAddress: '12.34.56.78',
  remotePort: 1234,
  localAddress: '172.16.0.1,
  localPort: 8080,
  protocol: 'udp'
});

protocol defaults to 'tcp' if unspecified.

The v1_encode function has the same API but is constrained by the limits of the v1 format, so only the tcp protocol is supported.

decode

A generic decoder is provided that detects the format of any header. If no valid v1 or v2 signature is detected, null is returned.

var details = require('proxy-protocol-v2').decode(buf);
if(details === null) {
    console.log('No proxy protocol header detected');
}

var remoteFamily = details.remoteFamily,
    remoteAddress = details.remoteAddress,
    remotePort = details.remotePort,
    localAddress = details.localAddress,
    localPort = details.localPort,
    protocol = details.prototol;

Separate decoders are provided for each version if the expected version is known.

var v1_details = require('proxy-protocol-v2').v1_decode(buf);
var v2_details = require('proxy-protocol-v2').v2_decode(buf);

The format-specific functions will assume the presence of a header and may throw an Error or return invalid details if a header is not present.

Each decode operation takes an optional validate second argument which causes the header to be validated (with an Error being thrown if invalid) at the minor cost of checking the signature validity an other validity checks on field values.

test

nodeunit test

proxy-protocol-v2's People

Contributors

paddybyers avatar lmars avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.