HTTP Preflight
Streamlining AMPS Connections: Enabling TCP Clients Over HTTP Proxy with HTTP Preflight
The HTTP preflight feature allows TCP clients (Python, Java, etc.) to initiate a connection through an HTTP proxy in a way similar to WebSocket clients. This enables a proxied connection for tcp/amps transport, just as AMPS already supports for tcp/websocket transport and the Admin interface. By using HTTP preflight, TCP clients can connect to AMPS via an HTTP proxy, optionally including custom HTTP headers for proxy authentication or routing.
Key Considerations:
AMPS Still Requires Separate Ports: This feature does not allow a single transport in AMPS to handle both WebSocket and raw TCP connections on the same port. AMPS still requires distinct ports for tcp/amps, tcp/websocket, and Admin.
Proxy Compatibility: The goal is to allow tcp/amps clients to connect through an HTTP proxy, making it easier to route traffic through infrastructure that already supports WebSockets.
Usage
There are no server-side changes required to use it. Simply add ?http_preflight=true in the connection string in order to enable HTTP Upgrade handshake on the client:
Client client = new Client("example");
client.connect("tcps://localhost:443/amps/json?&http_preflight=true");
HTTP Headers
A client can optionally set additional HTTP headers. This allows it to provide header data required by an HTTP proxy, for example, an authentication token. Here's an example of how to do it in the Java client:
Client client = new Client("example");
try {
client.addHttpPreflightHeader("Cookie: a=1; b=2"); // raw form
client.addHttpPreflightHeader("Token", "token_value"); // key-value form
client.connect("tcps://localhost:443/amps/json?&http_preflight=true");
}
Other clients have a similar API available -- please refer to each client's API documentation for more details.
When to Use: Use HTTP Preflight when you need to limit the number of exposed ports while supporting both WebSocket and TCP/TCPS connections through a reverse proxy like Nginx.
Why Use It:
Reduces Open Ports: Allows TCP/TCPS clients to connect via a single exposed port instead of requiring separate ports for different transport types.
Proxy-Friendly Routing: Enables proxies like Nginx to handle WebSocket-like traffic and route TCP connections efficiently.
Simplifies Network Management: Minimizes firewall and security rule complexity by consolidating traffic through a single entry point.
Avoids Additional Configuration in AMPS: No changes are needed on the AMPS server; only the proxy (Nginx) requires setup.
This approach is ideal for environments with strict port usage policies or those looking to simplify their network infrastructure while maintaining flexible client connectivity.
Last updated