Categorygithub.com/cockroachlabs/httptun
modulepackage
0.0.0-20231123012040-00e4402b6c7a
Repository: https://github.com/cockroachlabs/httptun.git
Documentation: pkg.go.dev

# README

httptun

Tunnel TCP over a WebSocket connection. We use this with Google's Identity-Aware Proxy to get an authenticated TCP connection.

To use it, start the server somewhere and then use NewClient() in your client code. Use (*Client).Dial() to get a TCP connection in the form of a net.Conn.

# Listen for Websocket connections on, ie. all network interfaces.
export HTTPTUN_LISTEN_ADDR=:80
# Proxy the tunneled TCP connections to some upstream.
export HTTPTUN_DST_ADDR=1.2.3.4:5678
# Start the server.
go run ./cmd/server
# There's a basic healthcheck at /health
curl localhost:80/health
#=> ok
# Establish a connection at /ws with a client constructed with NewClient().

License

All the code within this repository is licensed under Apache-2.0.

Copyright 2023 Cockroach Labs, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

# Packages

No description provided by the author

# Functions

NewBuffer constructs a new buffer with the given size and logger.
NewServer creates a new server that can be used to serve HTTP requests over a websocket connection.
NewStream creates a new stream.
NewWebsocketConn creates a new WebsocketConn from an open websocket connection which implements net.Conn.

# Constants

List of error codes.
List of error codes.
List of error codes.
List of error codes.

# Variables

ErrPreempted (preemption) is a mechanism that makes Read calls of buffers return immediately, and notify the caller they have been preempted.

# Structs

Buffer provides the flexibility to recover from an interrupted connection.
BufferReader is a reader that reads from a Buffer.
Client opens Websocket connections, returning them as a [net.Conn].
Flow is an active "instance" of a stream, which represents an unreliable connection such as a WebSocket connection.
Handshake is the handshake message sent by both the client and server to negotiate connection resumption.
Server implements http.Handler for the server (termination point) of a TCP over HTTP tunnel.
Stream is a resumable stream, it represents a logical, persistent (extra-reliable) connection.
WebsocketConn wraps *websocket.Conn into implementing net.Conn.

# Type aliases

ErrorCode represents an error code in a handshake.