http

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HttpMethods = []string{
	"GET",
	"HEAD",
	"POST",
	"PUT",
	"PATCH",
	"DELETE",
	"CONNECT",
	"OPTIONS",
	"TRACE",
}

Functions

func PragmaCacheControl

func PragmaCacheControl(header http.Header)

PragmaCacheControl RFC 7234, section 5.4: Pragma: no-cache && Cache-Control: no-cache

func ValidBody

func ValidBody(body string) bool

func ValidHeader

func ValidHeader(header string) bool

func ValidMethod

func ValidMethod(method string) bool

ValidMethod 验证http方法

func ValidPath

func ValidPath(path string) bool

func ValidQuery

func ValidQuery(query string) bool

Types

type Body

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

func NewBody

func NewBody() *Body

func NewReadBody

func NewReadBody(size int64, reader io.Reader) *Body

func NewReaderWriteBody

func NewReaderWriteBody(reader io.Reader, writer io.Writer) *Body

func NewWriteBody

func NewWriteBody(writer io.Writer) *Body

func (*Body) Read

func (b *Body) Read(p []byte) (n int, err error)

func (*Body) ReadBytes

func (b *Body) ReadBytes() ([]byte, error)

func (*Body) ReadString

func (b *Body) ReadString() (string, error)

func (*Body) Size

func (b *Body) Size() int64

func (*Body) Write

func (b *Body) Write(p []byte) (int, error)

func (*Body) WriteString

func (b *Body) WriteString(data string) (int, error)

type Request

type Request struct {
	http.Request
	Response *Response

	BufReadr  *codec.ByteBuf
	BufWriter *codec.ByteBuf
	// contains filtered or unexported fields
}

Request http请求体

func NewRequest

func NewRequest(readBuff *codec.ByteBuf) *Request

func (*Request) AddCookie

func (r *Request) AddCookie(name, value string)

func (*Request) AddCookieEntity

func (r *Request) AddCookieEntity(cookie *http.Cookie)

func (*Request) AddHeader

func (r *Request) AddHeader(name, value string)

func (*Request) Body

func (r *Request) Body() *Body

func (*Request) SetBody

func (r *Request) SetBody(body *Body)

type RequestDecoder

type RequestDecoder struct {
}

RequestDecoder 请求解码器, 从io缓冲区读取字节流, 并解码为http请求对象, 缓冲区一般为socket连接, 也可以使字节数组等

func NewRequestDecoder

func NewRequestDecoder() *RequestDecoder

NewRequestDecoder 构造函数

func (*RequestDecoder) Decoder

func (r *RequestDecoder) Decoder(request *Request) (err error)

Decoder 解码入口

type RequestEncode added in v1.1.0

type RequestEncode struct{}

RequestEncode http编码器, 把request对象编码成字节流, 并写入io缓冲区, 根据 RFC2616 规范编码

func NewRequestEncode added in v1.1.0

func NewRequestEncode() *RequestEncode

func (*RequestEncode) Encoder added in v1.1.0

func (r *RequestEncode) Encoder(request *Request) (err error)

type RequestProcess

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

func NewRequestProcess

func NewRequestProcess() *RequestProcess

func (*RequestProcess) Accept

func (r *RequestProcess) Accept(session *event.Session) error

func (*RequestProcess) Active

func (r *RequestProcess) Active(session *event.Session, _ any) (any, error)

func (*RequestProcess) Disconnect

func (r *RequestProcess) Disconnect(session *event.Session) error

type Response

type Response struct {
	Proto      string
	ProtoMajor int
	ProtoMinor int

	Header http.Header
	Close  bool

	Server string

	BufWriter *codec.ByteBuf
	BufReader *codec.ByteBuf
	// contains filtered or unexported fields
}

func NewReplyResponse

func NewReplyResponse(request *Request) *Response

NewReplyResponse 根据request创建Response, 用于服务端模式

func NewResponse

func NewResponse() *Response

NewResponse 创建默认的response对象

func (*Response) AddCookie

func (r *Response) AddCookie(name, value string)

func (*Response) AddCookieEntity

func (r *Response) AddCookieEntity(cookie *http.Cookie)

func (*Response) AddHeader

func (r *Response) AddHeader(name, value string)

func (*Response) Body

func (r *Response) Body() *Body

func (*Response) Cookies

func (r *Response) Cookies() []*http.Cookie

func (*Response) Request

func (r *Response) Request() *Request

func (*Response) SetBody

func (r *Response) SetBody(body *Body)

func (*Response) SetStatusCode

func (r *Response) SetStatusCode(statusCode int)

func (*Response) SetStatusCodeAndText added in v1.1.0

func (r *Response) SetStatusCodeAndText(statusCode int, statusText string)

func (*Response) StatusCode

func (r *Response) StatusCode() int

type ResponseDecoder added in v1.1.0

type ResponseDecoder struct{}

ResponseDecoder 解码器, 从io缓冲区读取字节流, 并解码为response对象

func NewResponseDecoder added in v1.1.0

func NewResponseDecoder() *ResponseDecoder

func (*ResponseDecoder) Decoder added in v1.1.0

func (r *ResponseDecoder) Decoder(response *Response) (err error)

type ResponseEncode

type ResponseEncode struct{}

ResponseEncode 编码器, 把response编码为字节流并写入缓冲区

func NewResponseEncode

func NewResponseEncode() *ResponseEncode

func (*ResponseEncode) Encode

func (r *ResponseEncode) Encode(response *Response) (err error)

type ResponseProcess

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

func NewResponseProcess

func NewResponseProcess() *ResponseProcess

func (*ResponseProcess) Accept

func (r *ResponseProcess) Accept(session *event.Session) error

func (*ResponseProcess) Active

func (r *ResponseProcess) Active(session *event.Session, value any) (any, error)

func (*ResponseProcess) Disconnect

func (r *ResponseProcess) Disconnect(session *event.Session) error

Jump to

Keyboard shortcuts

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