toh

package
v0.0.0-...-e1fa9fa Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PING_OK uint16 = iota + 1
	PING_CLOSED
	PING_OK_VOID
)

Variables

View Source
var (
	WithTransport = func(tr http.RoundTripper) Option {
		return Option(func(d *Dialer, ln *Listener) {
			if d != nil {
				d.Transport = tr
			}
		})
	}
	WithInactiveTimeout = func(t time.Duration) Option {
		return Option(func(d *Dialer, ln *Listener) {
			if d != nil {
				d.Timeout = t
			}
			if ln != nil {
				ln.Timeout = t
			}
		})
	}
	WithWebSocket = func(ws bool) Option {
		return Option(func(d *Dialer, ln *Listener) {
			if d != nil {
				d.WebSocket = ws
			}
		})
	}
	WithMaxWriteBuffer = func(size int) Option {
		return Option(func(d *Dialer, ln *Listener) {
			if d != nil {
				d.MaxWriteBuffer = size
			}
			if ln != nil {
				ln.MaxWriteBuffer = size
			}
		})
	}
	WithHeader = func(hdr string) Option {
		return Option(func(d *Dialer, ln *Listener) {
			if d != nil {
				d.URLHeader = hdr
			}
		})
	}
	WithPathPattern = func(pattern string) Option {
		return Option(func(d *Dialer, ln *Listener) {
			if d != nil {
				d.PathPattern = pattern
			}
		})
	}
	WithBadRequest = func(callback http.HandlerFunc) Option {
		return Option(func(d *Dialer, ln *Listener) {
			if ln != nil {
				ln.OnBadRequest = callback
			}
		})
	}
	WithBadRequestRoundTripper = func(rt http.RoundTripper) Option {
		return Option(func(d *Dialer, ln *Listener) {
			if ln != nil {
				ln.OnBadRequest = func(w http.ResponseWriter, r *http.Request) {
					resp, err := rt.RoundTrip(r)
					if err != nil {
						w.WriteHeader(http.StatusServiceUnavailable)
						w.Write([]byte(err.Error()))
						return
					}

					defer resp.Body.Close()
					w.WriteHeader(resp.StatusCode)

					for k := range w.Header() {
						w.Header().Del(k)
					}

					for k, v := range resp.Header {
						hdr := w.Header()
						for _, v := range v {
							hdr.Add(k, v)
						}
					}
					io.Copy(w, resp.Body)
				}
			}
		})
	}
)
View Source
var MaxReadBufferSize = 1024 * 1024 * 1

Define the max pending bytes stored in memory, any further bytes will be written to disk

Functions

func Listen

func Listen(network string, address string, options ...Option) (net.Listener, error)

Types

type BufConn

type BufConn struct {
	net.Conn
	*bufio.Reader
}

func NewBufConn

func NewBufConn(conn net.Conn) *BufConn

func (*BufConn) Read

func (c *BufConn) Read(p []byte) (int, error)

func (*BufConn) Write

func (c *BufConn) Write(p []byte) (int, error)

type ClientConn

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

func (*ClientConn) Close

func (c *ClientConn) Close() error

func (*ClientConn) LocalAddr

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

func (*ClientConn) Read

func (c *ClientConn) Read(p []byte) (n int, err error)

func (*ClientConn) RemoteAddr

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

func (*ClientConn) SetDeadline

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

func (*ClientConn) SetReadDeadline

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

func (*ClientConn) SetWriteDeadline

func (c *ClientConn) SetWriteDeadline(t time.Time) error

func (*ClientConn) String

func (c *ClientConn) String() string

func (*ClientConn) Write

func (c *ClientConn) Write(p []byte) (n int, err error)

type CommonOptions

type CommonOptions struct {
	MaxWriteBuffer int
	Timeout        time.Duration
}

type Dialer

type Dialer struct {
	Transport   http.RoundTripper
	WebSocket   bool
	URLHeader   string
	PathPattern string
	CommonOptions
	// contains filtered or unexported fields
}

func NewDialer

func NewDialer(network string, endpoint string, options ...Option) *Dialer

func (*Dialer) Dial

func (d *Dialer) Dial() (net.Conn, error)

func (*Dialer) Path

func (d *Dialer) Path() string

type Listener

type Listener struct {
	OnBadRequest http.HandlerFunc
	CommonOptions
	// contains filtered or unexported fields
}

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

func (*Listener) Close

func (l *Listener) Close() error

type Option

type Option func(d *Dialer, ln *Listener)

type ServerConn

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

func (*ServerConn) Close

func (c *ServerConn) Close() error

func (*ServerConn) LocalAddr

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

func (*ServerConn) Read

func (c *ServerConn) Read(p []byte) (n int, err error)

func (*ServerConn) RemoteAddr

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

func (*ServerConn) SetDeadline

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

func (*ServerConn) SetReadDeadline

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

func (*ServerConn) SetWriteDeadline

func (c *ServerConn) SetWriteDeadline(t time.Time) error

func (*ServerConn) String

func (c *ServerConn) String() string

func (*ServerConn) Write

func (c *ServerConn) Write(p []byte) (n int, err error)

type WSConn

type WSConn struct {
	net.Conn
	// contains filtered or unexported fields
}

func (*WSConn) Read

func (c *WSConn) Read(p []byte) (int, error)

func (*WSConn) Write

func (c *WSConn) Write(p []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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