ppp
A Proxy Protocol Parser written in Rust. Supports both text and binary versions of the HAProxy header. See HAProxy for the protocol specification.
Usage
Add the following to your Cargo.toml
as a dependency:
= "2.0"
Then, you can use either the text or binary versions of the protocol.
To parse or generate the text version use:
use v1;
use SocketAddr;
let client_address: SocketAddr = ...;
let server_address: SocketAddr = ...;
// Create a v1 header
let header = from.to_string;
assert_eq!;
To parse or generate the binary version use:
use v2;
use SocketAddr;
let client_address: SocketAddr = ...;
let server_address: SocketAddr = ...;
let header = with_addresses
.write_tlv
.unwrap
.build
.unwrap;
assert_eq!;
To parse either version use:
use ;
let input = "PROXY UNKNOWN\r\n";
let header = parse;
assert_eq!;
Examples
The repository contains examples for how to use both versions of the proxy protocol with streaming support. To run the examples, you will need to use 3 terminal windows.
Proxy
The proxy Server that writes the proxy protocol header will be in its own terminal. The example takes an optional argument of which version of the header to write as v1
or v2
, with a default of v2
.
Version 2:
Version 1:
Server
A minimal HTTP server that reads the proxy protocol headers and responds to HTTP requests.
HTTP Client
We use cURL
as the HTTP client for the examples, but any HTTP client will do.
Profiling
Profiling a benchmark run is currently only supported on a *nix environment. The profiler outputs a flamegraph in the target
directory. To run a profiling session use:
Benchmark
To run the benchmarks use:
Results
The following are a snapshot of a benchmarking run on a desktop with a hexa-core i7 processor with hyper-threading.
Binary
Text