http

package
v0.0.0-...-e9b145e Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: Apache-2.0 Imports: 20 Imported by: 3

Documentation

Index

Constants

View Source
const (

	// DefaultShutdownTimeout - default shutdown timeout used for graceful http server shutdown.
	DefaultShutdownTimeout = 5 * time.Second

	// DefaultTCPKeepAliveTimeout - default TCP keep alive timeout for accepted connection.
	DefaultTCPKeepAliveTimeout = 10 * time.Second

	// DefaultReadTimeout - default timout to read data from accepted connection.
	DefaultReadTimeout = 5 * time.Minute

	// DefaultWriteTimeout - default timout to write data to accepted connection.
	DefaultWriteTimeout = 5 * time.Minute

	// DefaultMaxHeaderBytes - default maximum HTTP header size in bytes.
	DefaultMaxHeaderBytes = 1 * humanize.MiByte
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BufConn

type BufConn struct {
	QuirkConn
	// contains filtered or unexported fields
}

BufConn - is a generic stream-oriented network connection supporting buffered reader and read/write timeout.

func (*BufConn) Peek

func (c *BufConn) Peek(n int) ([]byte, error)

Peek - returns the next n bytes without advancing the reader. It just wraps bufio.Reader.Peek().

func (*BufConn) Read

func (c *BufConn) Read(b []byte) (n int, err error)

Read - reads data from the connection using wrapped buffered reader.

func (*BufConn) RemoveTimeout

func (c *BufConn) RemoveTimeout()

RemoveTimeout - removes all configured read and write timeouts. Used by callers which control net.Conn behavior themselves.

func (*BufConn) Write

func (c *BufConn) Write(b []byte) (n int, err error)

Write - writes data to the connection.

type QuirkConn

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

QuirkConn - similar to golang net.Conn struct, but contains a workaround of the following the go bug reported here https://github.com/golang/go/issues/21133. Once the bug will be fixed, we can remove this structure and replaces it with the standard net.Conn

func (*QuirkConn) SetReadDeadline

func (q *QuirkConn) SetReadDeadline(t time.Time) error

SetReadDeadline - implements a workaround of SetReadDeadline go bug

type Server

type Server struct {
	http.Server
	Addrs                  []string                 // addresses on which the server listens for new connection.
	ShutdownTimeout        time.Duration            // timeout used for graceful server shutdown.
	TCPKeepAliveTimeout    time.Duration            // timeout used for underneath TCP connection.
	UpdateBytesReadFunc    func(*http.Request, int) // function to be called to update bytes read in bufConn.
	UpdateBytesWrittenFunc func(*http.Request, int) // function to be called to update bytes written in bufConn.
	// contains filtered or unexported fields
}

Server - extended http.Server supports multiple addresses to serve and enhanced connection handling.

func NewServer

func NewServer(addrs []string, handler http.Handler, getCert certs.GetCertificateFunc) *Server

NewServer - creates new HTTP server using given arguments.

func (*Server) GetRequestCount

func (srv *Server) GetRequestCount() int32

GetRequestCount - returns number of request in progress.

func (*Server) Shutdown

func (srv *Server) Shutdown() error

Shutdown - shuts down HTTP server.

func (*Server) Start

func (srv *Server) Start() (err error)

Start - start HTTP server

type TimeoutConn

type TimeoutConn struct {
	QuirkConn
	// contains filtered or unexported fields
}

TimeoutConn - is wrapped net.Conn with read/write timeouts.

func NewTimeoutConn

func NewTimeoutConn(c net.Conn, readTimeout, writeTimeout time.Duration) *TimeoutConn

NewTimeoutConn - creates a new timeout connection.

func (*TimeoutConn) Read

func (c *TimeoutConn) Read(b []byte) (n int, err error)

Read - reads data from the connection with timeout.

func (*TimeoutConn) Write

func (c *TimeoutConn) Write(b []byte) (n int, err error)

Write - writes data to the connection with timeout.

Jump to

Keyboard shortcuts

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