Documentation ¶
Index ¶
- Constants
- Variables
- type BodyReader
- type ClientProcessor
- func (p *ClientProcessor) Close()
- func (p *ClientProcessor) Conn() net.Conn
- func (p *ClientProcessor) HandleExecute(executor func(index int, f func()))
- func (p *ClientProcessor) HandleMessage(handler func(*http.Response))
- func (p *ClientProcessor) OnBody(data []byte)
- func (p *ClientProcessor) OnComplete(parser *Parser)
- func (p *ClientProcessor) OnContentLength(contentLength int)
- func (p *ClientProcessor) OnHeader(key, value string)
- func (p *ClientProcessor) OnMethod(method string)
- func (p *ClientProcessor) OnProto(proto string) error
- func (p *ClientProcessor) OnStatus(code int, status string)
- func (p *ClientProcessor) OnTrailerHeader(key, value string)
- func (p *ClientProcessor) OnURL(uri string) error
- type Config
- type EmptyProcessor
- func (p *EmptyProcessor) Close()
- func (p *EmptyProcessor) Conn() net.Conn
- func (p *EmptyProcessor) HandleExecute(executor func(index int, f func()))
- func (p *EmptyProcessor) HandleMessage(handler http.Handler)
- func (p *EmptyProcessor) OnBody(data []byte)
- func (p *EmptyProcessor) OnComplete(parser *Parser)
- func (p *EmptyProcessor) OnContentLength(contentLength int)
- func (p *EmptyProcessor) OnHeader(key, value string)
- func (p *EmptyProcessor) OnMethod(method string)
- func (p *EmptyProcessor) OnProto(proto string) error
- func (p *EmptyProcessor) OnStatus(code int, status string)
- func (p *EmptyProcessor) OnTrailerHeader(key, value string)
- func (p *EmptyProcessor) OnURL(uri string) error
- type Hijacker
- type Http2Upgrader
- type Parser
- type Processor
- type Response
- type Server
- type ServerProcessor
- func (p *ServerProcessor) Close()
- func (p *ServerProcessor) Conn() net.Conn
- func (p *ServerProcessor) HandleExecute(executor func(index int, f func()))
- func (p *ServerProcessor) HandleMessage(handler http.Handler)
- func (p *ServerProcessor) OnBody(data []byte)
- func (p *ServerProcessor) OnComplete(parser *Parser)
- func (p *ServerProcessor) OnContentLength(contentLength int)
- func (p *ServerProcessor) OnHeader(key, value string)
- func (p *ServerProcessor) OnMethod(method string)
- func (p *ServerProcessor) OnProto(proto string) error
- func (p *ServerProcessor) OnStatus(code int, status string)
- func (p *ServerProcessor) OnTrailerHeader(key, value string)
- func (p *ServerProcessor) OnURL(uri string) error
- type Upgrader
Constants ¶
const (
H2HeaderLen = 9
)
Variables ¶
var ( // ErrClosed . ErrClosed = errors.New("closed") // ErrInvalidCRLF . ErrInvalidCRLF = errors.New("invalid cr/lf at the end of line") // ErrInvalidHTTPVersion . ErrInvalidHTTPVersion = errors.New("invalid HTTP version") // ErrInvalidHTTPStatusCode . ErrInvalidHTTPStatusCode = errors.New("invalid HTTP status code") // ErrInvalidHTTPStatus . ErrInvalidHTTPStatus = errors.New("invalid HTTP status") // ErrInvalidMethod . ErrInvalidMethod = errors.New("invalid HTTP method") // ErrInvalidRequestURI . ErrInvalidRequestURI = errors.New("invalid URL") // ErrInvalidHost . ErrInvalidHost = errors.New("invalid host") // ErrInvalidPort . ErrInvalidPort = errors.New("invalid port") // ErrInvalidPath . ErrInvalidPath = errors.New("invalid path") // ErrInvalidQueryString . ErrInvalidQueryString = errors.New("invalid query string") // ErrInvalidFragment . ErrInvalidFragment = errors.New("invalid fragment") // ErrCRExpected . ErrCRExpected = errors.New("CR character expected") // ErrLFExpected . ErrLFExpected = errors.New("LF character expected") // ErrInvalidCharInHeader . ErrInvalidCharInHeader = errors.New("invalid character in header") // ErrUnexpectedContentLength . ErrUnexpectedContentLength = errors.New("unexpected content-length header") // ErrInvalidContentLength . ErrInvalidContentLength = errors.New("invalid ContentLength") // ErrInvalidChunkSize . ErrInvalidChunkSize = errors.New("invalid chunk size") // ErrTrailerExpected . ErrTrailerExpected = errors.New("trailer expected") // ErrTooLong . ErrTooLong = errors.New("invalid http message: too long") )
var ( // ErrInvalidH2SM . ErrInvalidH2SM = errors.New("invalid http2 SM characters") // ErrInvalidH2HeaderR . ErrInvalidH2HeaderR = errors.New("invalid http2 SM characters") )
var ( // DefaultMaxLoad . DefaultMaxLoad = 1024 * 1024 // DefaultHTTPReadLimit . DefaultHTTPReadLimit = 1024 * 1024 * 64 // DefaultMinBufferSize . DefaultMinBufferSize = 1024 * 2 // DefaultHTTPWriteBufferSize . DefaultHTTPWriteBufferSize = 1024 * 2 // DefaultMaxWebsocketFramePayloadSize DefaultMaxWebsocketFramePayloadSize = 1024 * 32 // DefaultMessageHandlerTaskIdleTime . DefaultMessageHandlerTaskIdleTime = time.Second * 60 // DefaultKeepaliveTime . DefaultKeepaliveTime = time.Second * 120 // DefaultTLSHandshakeTimeout . DefaultTLSHandshakeTimeout = time.Second * 10 )
var ( // ErrNilConn . ErrNilConn = errors.New("nil Conn") )
Functions ¶
This section is empty.
Types ¶
type BodyReader ¶
type BodyReader struct {
// contains filtered or unexported fields
}
BodyReader .
func (*BodyReader) RawBody ¶
func (br *BodyReader) RawBody() []byte
RawBody returns BodyReader's buffer directly, the buffer returned would be released to the mempool after http handler func, the application layer should not hold it any longer after the http handler func.
func (*BodyReader) Read ¶
func (br *BodyReader) Read(p []byte) (int, error)
Read implements io.Reader
func (*BodyReader) TakeOver ¶
func (br *BodyReader) TakeOver() []byte
TakeOver returns BodyReader's buffer, the buffer returned would not be released to the mempool after http handler func, the application layer could hold it longer and should manage when to release the buffer to the mempool.
type ClientProcessor ¶
type ClientProcessor struct {
// contains filtered or unexported fields
}
ClientProcessor .
func (*ClientProcessor) HandleExecute ¶
func (p *ClientProcessor) HandleExecute(executor func(index int, f func()))
HandleExecute .
func (*ClientProcessor) HandleMessage ¶
func (p *ClientProcessor) HandleMessage(handler func(*http.Response))
HandleMessage .
func (*ClientProcessor) OnComplete ¶
func (p *ClientProcessor) OnComplete(parser *Parser)
OnComplete .
func (*ClientProcessor) OnContentLength ¶
func (p *ClientProcessor) OnContentLength(contentLength int)
OnContentLength .
func (*ClientProcessor) OnStatus ¶
func (p *ClientProcessor) OnStatus(code int, status string)
OnStatus .
func (*ClientProcessor) OnTrailerHeader ¶
func (p *ClientProcessor) OnTrailerHeader(key, value string)
OnTrailerHeader .
type Config ¶
type Config struct { // Name describes your gopher name for logging, it's set to "NB" by default. Name string // Network is the listening protocol, used with Addrs toghter. // tcp* supported only by now, there's no plan for other protocol such as udp, // because it's too easy to write udp server/client. Network string // Addrs is the listening addr list for a nbio server. // if it is empty, no listener created, then the Gopher is used for client by default. Addrs []string // MaxLoad represents the max online num, it's set to 10k by default. MaxLoad int // NPoller represents poller goroutine num, it's set to runtime.NumCPU() by default. NPoller int // NListener represents poller goroutine num, it's set to runtime.NumCPU() by default. NListener int // NParser represents parser goroutine num, it's set to NPoller by default. NParser int // ReadLimit represents the max size for parser reading, it's set to 64M by default. ReadLimit int // ReadBufferSize represents buffer size for reading, it's set to 2k by default. ReadBufferSize int // MaxWriteBufferSize represents max write buffer size for Conn, it's set to 1m by default. // if the connection's Send-Q is full and the data cached by nbio is // more than MaxWriteBufferSize, the connection would be closed by nbio. MaxWriteBufferSize int // MaxWebsocketFramePayloadSize represents max payload size of websocket frame. MaxWebsocketFramePayloadSize int // MessageHandlerPoolSize represents max http server's task pool goroutine num, it's set to runtime.NumCPU() * 256 by default. MessageHandlerPoolSize int // KeepaliveTime represents Conn's ReadDeadline when waiting for a new request, it's set to 120s by default. KeepaliveTime time.Duration // LockListener represents listener's goroutine to lock thread or not, it's set to false by default. LockListener bool // LockPoller represents poller's goroutine to lock thread or not, it's set to false by default. LockPoller bool // EnableSendfile . EnableSendfile bool // ReleaseWebsocketPayload . ReleaseWebsocketPayload bool // MaxReadTimesPerEventLoop represents max read times in one poller loop for one fd MaxReadTimesPerEventLoop int }
Config .
type EmptyProcessor ¶
type EmptyProcessor struct{}
EmptyProcessor .
func (*EmptyProcessor) HandleExecute ¶
func (p *EmptyProcessor) HandleExecute(executor func(index int, f func()))
HandleExecute .
func (*EmptyProcessor) HandleMessage ¶
func (p *EmptyProcessor) HandleMessage(handler http.Handler)
HandleMessage .
func (*EmptyProcessor) OnComplete ¶
func (p *EmptyProcessor) OnComplete(parser *Parser)
OnComplete .
func (*EmptyProcessor) OnContentLength ¶
func (p *EmptyProcessor) OnContentLength(contentLength int)
OnContentLength .
func (*EmptyProcessor) OnStatus ¶
func (p *EmptyProcessor) OnStatus(code int, status string)
OnStatus .
func (*EmptyProcessor) OnTrailerHeader ¶
func (p *EmptyProcessor) OnTrailerHeader(key, value string)
OnTrailerHeader .
type Http2Upgrader ¶
type Http2Upgrader struct { ReadLimit int64 HandshakeTimeout time.Duration Subprotocols []string CheckOrigin func(r *http.Request) bool // contains filtered or unexported fields }
Http2Upgrader .
type Parser ¶
type Parser struct { Processor Processor Upgrader Upgrader Server *Server Conn net.Conn // contains filtered or unexported fields }
Parser .
type Processor ¶
type Processor interface { Conn() net.Conn OnMethod(method string) OnURL(uri string) error OnProto(proto string) error OnStatus(code int, status string) OnHeader(key, value string) OnContentLength(contentLength int) OnBody(data []byte) OnTrailerHeader(key, value string) OnComplete(parser *Parser) HandleExecute(executor func(index int, f func())) Close() }
Processor .
func NewClientProcessor ¶
NewClientProcessor .
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response represents the server side of an HTTP response.
func NewResponse ¶
NewResponse .
type Server ¶
type Server struct { *nbio.Gopher MaxLoad int MaxWebsocketFramePayloadSize int ReleaseWebsocketPayload bool CheckUtf8 func(data []byte) bool MessageHandlerExecutor func(index int, f func()) // contains filtered or unexported fields }
Server .
func NewServer ¶
func NewServer(conf Config, handler http.Handler, messageHandlerExecutor func(index int, f func())) *Server
NewServer .
func NewServerTLS ¶
func NewServerTLS(conf Config, handler http.Handler, messageHandlerExecutor func(index int, f func()), tlsConfig *tls.Config) *Server
NewServerTLS .
type ServerProcessor ¶
type ServerProcessor struct {
// contains filtered or unexported fields
}
ServerProcessor .
func (*ServerProcessor) HandleExecute ¶
func (p *ServerProcessor) HandleExecute(executor func(index int, f func()))
HandleExecute .
func (*ServerProcessor) HandleMessage ¶
func (p *ServerProcessor) HandleMessage(handler http.Handler)
HandleMessage .
func (*ServerProcessor) OnComplete ¶
func (p *ServerProcessor) OnComplete(parser *Parser)
OnComplete .
func (*ServerProcessor) OnContentLength ¶
func (p *ServerProcessor) OnContentLength(contentLength int)
OnContentLength .
func (*ServerProcessor) OnStatus ¶
func (p *ServerProcessor) OnStatus(code int, status string)
OnStatus .
func (*ServerProcessor) OnTrailerHeader ¶
func (p *ServerProcessor) OnTrailerHeader(key, value string)
OnTrailerHeader .