masque

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 21 Imported by: 0

README

masque-go

Documentation PkgGoDev Code Coverage

masque-go is an implementation of the CONNECT-UDP protocol RFC 9298, based on quic-go. It provides both a client and a proxy implementation.

Detailed documentation can be found on quic-go.net.

Release Policy

masque-go always aims to support the latest two Go releases.

Contributing

We are always happy to welcome new contributors! If you have any questions, please feel free to reach out by opening an issue or leaving a comment.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientConn added in v0.4.0

type ClientConn struct {
	// contains filtered or unexported fields
}

A ClientConn represents a connection to a single proxy server. Multiple proxied connections can be established over a single ClientConn.

func NewClientConn added in v0.6.0

func NewClientConn(conn *http3.ClientConn) *ClientConn

NewClientConn creates a client connection using an existing HTTP/3 connection. The HTTP/3 connection and its underlying QUIC connection must have datagrams enabled. The caller owns the HTTP/3 connection and can also use it for ordinary HTTP requests. Closing a Conn returned by ClientConn.Dial does not close the HTTP/3 connection.

func (*ClientConn) Dial added in v0.4.0

func (c *ClientConn) Dial(req *Request) (*Conn, *http.Response, error)

Dial dials a proxied connection to a target server over the proxy connection.

type Conn added in v0.4.0

type Conn struct {
	// contains filtered or unexported fields
}

func (*Conn) Close added in v0.4.0

func (c *Conn) Close() error

func (*Conn) LocalAddr added in v0.4.0

func (c *Conn) LocalAddr() net.Addr

func (*Conn) ReadFrom added in v0.4.0

func (c *Conn) ReadFrom(b []byte) (n int, addr net.Addr, err error)

func (*Conn) RemoteAddr added in v0.4.0

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) SetDeadline added in v0.4.0

func (c *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline added in v0.4.0

func (c *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteDeadline added in v0.4.0

func (c *Conn) SetWriteDeadline(time.Time) error

func (*Conn) WriteTo added in v0.4.0

func (c *Conn) WriteTo(p []byte, _ net.Addr) (n int, err error)

WriteTo sends a UDP datagram to the target. The net.Addr parameter is ignored.

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

A Proxy is an RFC 9298 CONNECT-UDP proxy.

func (*Proxy) Close

func (s *Proxy) Close() error

Close closes the proxy, immediately terminating all proxied flows.

func (*Proxy) Proxy

func (s *Proxy) Proxy(w http.ResponseWriter, r *ProxyRequest) error

Proxy proxies a request on a newly created connected UDP socket. For more control over the UDP socket, use ProxyConnectedSocket. Applications may add custom header fields to the response header, but MUST NOT call WriteHeader on the http.ResponseWriter.

func (*Proxy) ProxyConnectedSocket

func (s *Proxy) ProxyConnectedSocket(w http.ResponseWriter, _ *ProxyRequest, conn *net.UDPConn) error

ProxyConnectedSocket proxies a request on a connected UDP socket. Applications may add custom header fields such as Proxy-Status to the response header, but MUST NOT call WriteHeader on the http.ResponseWriter. It closes the connection before returning.

type ProxyRequest added in v0.4.0

type ProxyRequest struct {
	Target string
	Host   string
}

ProxyRequest is the parsed CONNECT-UDP request returned from ParseProxyRequest. Target is the target server that the client requests to connect to. It can either be DNS name:port or an IP:port.

func ParseProxyRequest added in v0.4.0

func ParseProxyRequest(r *http.Request, template *uritemplate.Template) (*ProxyRequest, error)

ParseProxyRequest parses a CONNECT-UDP request. The template is the URI template that clients will use to configure this UDP proxy.

type ProxyRequestParseError added in v0.4.0

type ProxyRequestParseError struct {
	HTTPStatus int
	Err        error
}

ProxyRequestParseError is returned from ParseProxyRequest if parsing the CONNECT-UDP request fails. It is recommended that the request is rejected with the corresponding HTTP status code.

func (*ProxyRequestParseError) Error added in v0.4.0

func (e *ProxyRequestParseError) Error() string

func (*ProxyRequestParseError) Unwrap added in v0.4.0

func (e *ProxyRequestParseError) Unwrap() error

type Request

type Request struct {
	// contains filtered or unexported fields
}

Request is a CONNECT-UDP request created by NewRequest. The zero value is not valid.

func NewRequest added in v0.4.0

func NewRequest(ctx context.Context, proxyTemplate *uritemplate.Template, target string) (*Request, error)

NewRequest creates a CONNECT-UDP request for the given target. The target must be given as a host:port.

func (*Request) Header added in v0.4.0

func (r *Request) Header() http.Header

Header returns the HTTP header fields sent with the CONNECT-UDP request. Callers may add custom headers before dialing.

type Transport added in v0.4.0

type Transport struct {
	// TLSClientConfig is the TLS client config used when dialing the QUIC connection to the proxy.
	// It must set the "h3" ALPN.
	TLSClientConfig *tls.Config

	// QUICConfig is the QUIC config used when dialing the QUIC connection.
	QUICConfig *quic.Config

	// DialAddr dials the QUIC connection to the proxy.
	// If unset, quic.DialAddr is used.
	DialAddr func(ctx context.Context, addr string, tlsConf *tls.Config, quicConf *quic.Config) (*quic.Conn, error)
}

A Transport establishes proxied connections to multiple remote hosts.

func (*Transport) Dial added in v0.4.0

func (t *Transport) Dial(req *Request) (*Conn, *http.Response, error)

Dial is a shortcut that opens a QUIC connection to the proxy and then dials a proxied connection. Closing the returned Conn also closes the QUIC connection to the proxy. More advanced use cases, including multiple proxied connections via one proxy connection, should dial a new QUIC connection and use Transport.NewClientConn.

func (*Transport) NewClientConn added in v0.4.0

func (t *Transport) NewClientConn(conn *quic.Conn) (*ClientConn, error)

NewClientConn creates a client connection for an already established QUIC connection. It returns an error if the QUIC connection didn't negotiate datagram support. The caller owns the QUIC connection and closes it when done. To reuse an existing HTTP/3 connection, use NewClientConn.

Directories

Path Synopsis
cmd
client command
proxy command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址