h1

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Unlicense, MIT Imports: 12 Imported by: 1

README

h1

Yet another HTTP/1.1 library

Documentation

Index

Constants

View Source
const BufferPoolSize = 4096

Variables

View Source
var BodyReaderPool = &sync.Pool{
	New: func() any {
		return &BodyReader{}
	},
}
View Source
var ContentLengthHeader = []byte("Content-Length")
View Source
var DateServerHeaderFunc = func() []byte {
	return DefaultFastDateServer.GetDate()
}
View Source
var DefaultFastDateServer = NewFastDateServer("h1")
View Source
var ErrBufferTooSmall = errors.New("buffer too small")
View Source
var ErrInvalidMethod = errors.New("invalid method")
View Source
var ErrInvalidURI = errors.New("invalid uri")
View Source
var ErrInvalidVersion = errors.New("invalid version")
View Source
var ErrKeyNotFound = errors.New("key not found")
View Source
var ErrRequestHeaderTooLarge = errors.New("request header too large")
View Source
var ResponsePool = sync.Pool{
	New: func() any {
		return &Response{
			upstream:      nil,
			buf:           make([]byte, 8192),
			itoaBuf:       make([]byte, 0, 32),
			n:             0,
			ContentLength: -1,
		}
	},
}

Functions

func DefineStatusLine added in v1.2.0

func DefineStatusLine(status int, statusText string)

func GetBuffer

func GetBuffer() *[]byte

func GetStatusLine

func GetStatusLine(status int) []byte

func ParseContentLength

func ParseContentLength(src []byte) (int64, error)

func ParseHeaderLine

func ParseHeaderLine(src []byte) (name []byte, value []byte)

func ParseHeaders

func ParseHeaders(dst *Request, src []byte) (next []byte, err error)

func ParseRequest

func ParseRequest(dst *Request, r io.Reader) (next []byte, err error)

Do not use this function in production code. This function is only for testing purpose.

func ParseRequestLine

func ParseRequestLine(dst *Request, src []byte) (next []byte, err error)

func PutBodyReader

func PutBodyReader(r *BodyReader)

func PutBuffer

func PutBuffer(b *[]byte)

func PutRequest

func PutRequest(r *Request)

func PutResponse

func PutResponse(r *Response)

Types

type BodyReader

type BodyReader struct {
	Upstream *RequestReader

	Limit int
	Index int
}

func GetBodyReader

func GetBodyReader() *BodyReader

func (*BodyReader) Close

func (r *BodyReader) Close() error

func (*BodyReader) Read

func (r *BodyReader) Read(p []byte) (n int, err error)

type FastDateServer

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

func NewFastDateServer

func NewFastDateServer(serverName string) *FastDateServer

func (*FastDateServer) GetDate

func (fds *FastDateServer) GetDate() []byte

func (*FastDateServer) Start

func (fds *FastDateServer) Start()

func (*FastDateServer) Stop

func (fds *FastDateServer) Stop()
type Header struct {
	Name     []byte
	RawValue []byte
	// contains filtered or unexported fields
}

func (*Header) Reset

func (h *Header) Reset()

type HijackReader

type HijackReader struct {
	Upstream *RequestReader
}

func (HijackReader) Read

func (h HijackReader) Read(p []byte) (n int, err error)

type Method

type Method uint8
const (
	MethodInvalid Method = iota
	MethodGET
	MethodHEAD
	MethodPOST
	MethodPUT
	MethodDELETE
	MethodCONNECT
	MethodOPTIONS
	MethodTRACE
	MethodPATCH

	MethodBREW // HTCPCP/1.0 (https://datatracker.ietf.org/doc/html/rfc2324)
)

func (Method) String

func (m Method) String() string

type Query

type Query struct {
	Key   []byte
	Value []byte
}

func ParseRawQuery

func ParseRawQuery(rawQuery []byte, dst []Query) []Query

type Request

type Request struct {
	// Request line
	Method  Method
	RawURI  []byte
	Version []byte

	// Headers
	Headers []Header

	// Parsed URI
	URI URI

	ContentLength int64
}

func GetRequest

func GetRequest() *Request

func (*Request) GetHeader

func (r *Request) GetHeader(name []byte) (*Header, bool)

func (*Request) Reset

func (r *Request) Reset()

type RequestReader

type RequestReader struct {
	R io.Reader

	ReadBuffer []byte
	NextBuffer []byte

	Request Request
}

func (*RequestReader) Body

func (r *RequestReader) Body() *BodyReader

func (*RequestReader) Fill

func (r *RequestReader) Fill() (n int, err error)

func (*RequestReader) Hijack

func (r *RequestReader) Hijack() HijackReader

func (*RequestReader) Next

func (r *RequestReader) Next() (remaining int, err error)

func (*RequestReader) Remaining

func (r *RequestReader) Remaining() int

func (*RequestReader) Reset

func (r *RequestReader) Reset()

type Response

type Response struct {

	// Standard Hop-by-Hop response headers.
	ContentLength int
	// contains filtered or unexported fields
}

func GetResponse

func GetResponse(upstream io.Writer) *Response

func (*Response) Flush

func (r *Response) Flush() error

func (*Response) Reset

func (r *Response) Reset()

func (*Response) Write

func (r *Response) Write(b []byte) (int, error)

func (*Response) WriteHeader

func (r *Response) WriteHeader(status int) error

func (*Response) WriteInt

func (r *Response) WriteInt(i int) (int, error)

func (*Response) WriteInt64

func (r *Response) WriteInt64(i int64) (int, error)

func (*Response) WriteStatusLine

func (r *Response) WriteStatusLine(status int) error

func (*Response) WriteString

func (r *Response) WriteString(b string) (int, error)

func (*Response) WriteUint

func (r *Response) WriteUint(u uint) (int, error)

func (*Response) WriteUint64

func (r *Response) WriteUint64(u uint64) (int, error)

func (*Response) WriteUint64Hex

func (r *Response) WriteUint64Hex(u uint64) (int, error)

type Status

type Status uint16

type URI

type URI struct {
	RawURI []byte

	RawPath  []byte
	RawQuery []byte
	// contains filtered or unexported fields
}

func (*URI) Parse

func (u *URI) Parse(uri []byte)

func (*URI) Path

func (u *URI) Path() []byte

func (*URI) Query

func (u *URI) Query() []Query

func (*URI) QueryValue

func (u *URI) QueryValue(key []byte) ([]byte, error)

func (*URI) Reset

func (u *URI) Reset()

Directories

Path Synopsis
encoding

Jump to

Keyboard shortcuts

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