httputil

package
v0.0.0-...-e865ecf Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTimeouts = HTTPTimeouts{
	ReadTimeout:       30 * time.Second,
	ReadHeaderTimeout: 30 * time.Second,
	WriteTimeout:      30 * time.Second,
	IdleTimeout:       120 * time.Second,
}

DefaultTimeouts for HTTP server, based on the RPC timeouts that geth uses.

Functions

func NewHttpServer

func NewHttpServer(handler http.Handler) *http.Server

Types

type HTTPOption

type HTTPOption func(srv *HTTPServer) error

HTTPOption applies a change to an HTTP server

func WithMaxHeaderBytes

func WithMaxHeaderBytes(max int) HTTPOption

func WithTimeouts

func WithTimeouts(timeouts HTTPTimeouts) HTTPOption

type HTTPServer

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

HTTPServer wraps a http.Server, while providing conveniences like exposing the running state and address.

func StartHTTPServer

func StartHTTPServer(addr string, handler http.Handler, opts ...HTTPOption) (*HTTPServer, error)

func (*HTTPServer) Addr

func (s *HTTPServer) Addr() net.Addr

func (*HTTPServer) Close

func (s *HTTPServer) Close() error

Close force-closes the HTTPServer, its listener, and all its active connections.

func (*HTTPServer) Closed

func (s *HTTPServer) Closed() bool

func (*HTTPServer) Shutdown

func (s *HTTPServer) Shutdown(ctx context.Context) error

Shutdown shuts down the HTTP server and its listener, but allows active connections to close gracefully. If the function exits due to a ctx cancellation the listener is closed but active connections may remain, a call to Close() can force-close any remaining active connections.

func (*HTTPServer) Stop

func (s *HTTPServer) Stop(ctx context.Context) error

Stop is a convenience method to gracefully shut down the server, but force-close if the ctx is cancelled. The ctx error is not returned when the force-close is successful.

type HTTPTimeouts

type HTTPTimeouts struct {
	// ReadTimeout is the maximum duration for reading the entire
	// request, including the body. A zero or negative value means
	// there will be no timeout.
	//
	// Because ReadTimeout does not let Handlers make per-request
	// decisions on each request body's acceptable deadline or
	// upload rate, most users will prefer to use
	// ReadHeaderTimeout. It is valid to use them both.
	ReadTimeout time.Duration

	// ReadHeaderTimeout is the amount of time allowed to read
	// request headers. The connection's read deadline is reset
	// after reading the headers and the Handler can decide what
	// is considered too slow for the body. If ReadHeaderTimeout
	// is zero, the value of ReadTimeout is used. If both are
	// zero, there is no timeout.
	ReadHeaderTimeout time.Duration

	// WriteTimeout is the maximum duration before timing out
	// writes of the response. It is reset whenever a new
	// request's header is read. Like ReadTimeout, it does not
	// let Handlers make decisions on a per-request basis.
	// A zero or negative value means there will be no timeout.
	WriteTimeout time.Duration

	// IdleTimeout is the maximum amount of time to wait for the
	// next request when keep-alives are enabled. If IdleTimeout
	// is zero, the value of ReadTimeout is used. If both are
	// zero, there is no timeout.
	IdleTimeout time.Duration
}

HTTPTimeouts represents the configuration params for the HTTP RPC server.

type WrappedResponseWriter

type WrappedResponseWriter struct {
	StatusCode  int
	ResponseLen int
	// contains filtered or unexported fields
}

func NewWrappedResponseWriter

func NewWrappedResponseWriter(w http.ResponseWriter) *WrappedResponseWriter

func (*WrappedResponseWriter) Header

func (w *WrappedResponseWriter) Header() http.Header

func (*WrappedResponseWriter) Write

func (w *WrappedResponseWriter) Write(bytes []byte) (int, error)

func (*WrappedResponseWriter) WriteHeader

func (w *WrappedResponseWriter) WriteHeader(statusCode int)

Jump to

Keyboard shortcuts

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