Documentation
¶
Index ¶
- Variables
- type Downloader
- type HTTPOption
- type HTTPServer
- func (s *HTTPServer) Addr() net.Addr
- func (s *HTTPServer) Close() error
- func (s *HTTPServer) Closed() bool
- func (s *HTTPServer) HTTPEndpoint() string
- func (s *HTTPServer) Port() (int, error)
- func (s *HTTPServer) Shutdown(ctx context.Context) error
- func (s *HTTPServer) Start() error
- func (s *HTTPServer) Stop(ctx context.Context) error
- type HTTPTimeouts
- type Option
- type ServerTLSConfig
- type WrappedResponseWriter
Constants ¶
This section is empty.
Variables ¶
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 ¶
This section is empty.
Types ¶
type Downloader ¶
type Downloader struct {
Client *http.Client
Progressor ioutil.Progressor
MaxSize int64
}
type HTTPOption ¶
HTTPOption applies a change to an HTTP server, just before standup. HTTPOption options are be re-executed on server shutdown/startup cycles, for each new underlying Go *http.Server instance.
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.
It can be started with HTTPServer.Start and closed with HTTPServer.Stop, HTTPServer.Close and HTTPServer.Shutdown (convenience functions for different gracefulness).
The addr contains both host and port. A 0 port may be used to make the system bind to an available one. The resulting address can be retrieved with HTTPServer.Addr or HTTPServer.HTTPEndpoint.
The server may be started, stopped and started back up.
func NewHTTPServer ¶
func NewHTTPServer(addr string, handler http.Handler, opts ...Option) *HTTPServer
NewHTTPServer creates an HTTPServer that serves the given HTTP handler. The server is inactive and has to be started explicitly.
func StartHTTPServer ¶
func (*HTTPServer) Addr ¶
func (s *HTTPServer) Addr() net.Addr
Addr returns the address that the server is listening on. It returns nil if the server is not online.
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) HTTPEndpoint ¶
func (s *HTTPServer) HTTPEndpoint() string
HTTPEndpoint returns the http(s) endpoint the server is serving. It returns an empty string if the server is not online.
func (*HTTPServer) Port ¶
func (s *HTTPServer) Port() (int, error)
Port returns the port that the server is listening on.
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) Start ¶
func (s *HTTPServer) Start() error
Start starts the server, and checks if it comes online fully.
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 Option ¶
type Option func(cfg *config)
Option is a general config option.
func WithHTTPOptions ¶
func WithHTTPOptions(options ...HTTPOption) Option
func WithServerTLS ¶
func WithServerTLS(tlsCfg *ServerTLSConfig) Option
type ServerTLSConfig ¶
type WrappedResponseWriter ¶
type WrappedResponseWriter struct {
StatusCode int
ResponseLen int
UpgradeAttempt bool
// contains filtered or unexported fields
}
func NewWrappedResponseWriter ¶
func NewWrappedResponseWriter(w http.ResponseWriter) *WrappedResponseWriter
func (*WrappedResponseWriter) Header ¶
func (w *WrappedResponseWriter) Header() http.Header
func (*WrappedResponseWriter) Hijack ¶
func (w *WrappedResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack implements http.Hijacker, so the WrappedResponseWriter is compatible as middleware for websocket-upgrades that take over the connection.
func (*WrappedResponseWriter) Write ¶
func (w *WrappedResponseWriter) Write(bytes []byte) (int, error)
func (*WrappedResponseWriter) WriteHeader ¶
func (w *WrappedResponseWriter) WriteHeader(statusCode int)