Documentation
¶
Index ¶
- Variables
- func BytesToString(b []byte) string
- type Method
- type Parser
- func (p *Parser) Eof() bool
- func (p *Parser) Execute(setting *Setting, buf []byte) (success int, err error)
- func (p *Parser) GetUserData() interface{}
- func (p *Parser) Init(t ReqOrRsp)
- func (p *Parser) ReadyUpgradeData() bool
- func (p *Parser) Reset()
- func (p *Parser) SetUserData(d interface{})
- func (p *Parser) Status() string
- type ReqOrRsp
- type Setting
- type TwoBuf
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrMethod = errors.New("http method fail") ErrHTTPVersion = errors.New("http version") ErrHTTPVersionNum = errors.New("http version number") ErrHeaderOverflow = errors.New("http header overflow") ErrNoEndLF = errors.New("http there is no end symbol") ErrChunkSize = errors.New("http wrong chunk size") ErrReqMethod = errors.New("http request wrong method") ErrRequestLineCRLF = errors.New("http request line wrong CRLF") )
View Source
var (
MaxHeaderSize int32 = 4096 //默认http header单行最大限制为4k
)
Functions ¶
Types ¶
type Parser ¶
type Parser struct {
Method Method //记录request的method
Major uint8 //主版本号
Minor uint8 //次版本号
MaxHeaderSize int32 //最大头长度
StatusCode uint16 //状态码
Upgrade bool //从http升级为别的协议, 比如websocket
// contains filtered or unexported fields
}
http 1.1 or http 1.0解析器
func (*Parser) GetUserData ¶ added in v0.0.5
func (p *Parser) GetUserData() interface{}
获取SetuserData函数设置的私有变量
func (*Parser) ReadyUpgradeData ¶ added in v0.0.7
如果ReadyUpgradeData为true 说明已经有Upgrade Data数据, 并且http数据已经成功解析完成
func (*Parser) SetUserData ¶ added in v0.0.3
func (p *Parser) SetUserData(d interface{})
一般情况,可以使用Setting里面函数闭包特性捕获调用者私有变量 好像提供SetUserData没有必要性 但是从 1.节约内存角度 2.数据和行为解耦的角度,提供一个Setting函数集,通过SetUserData,保存调用者私有变量 通过GetUserData拿需要的变量,还是比较爽的,不需要写一堆闭包
type Setting ¶
type Setting struct {
// 解析开始
MessageBegin func(*Parser)
// url 回调函数, 只有在request包才会回调
// 解析一个包时,URL回调可能会多次调用
URL func(*Parser, []byte)
// 状态短语
// 解析一个包时, Status回调可能会多次调用
Status func(*Parser, []byte)
// http field 回调函数
HeaderField func(*Parser, []byte)
// http value 回调函数
HeaderValue func(*Parser, []byte)
// http 解析完成之后的回调函数
HeadersComplete func(*Parser)
// body的回调函数
Body func(*Parser, []byte)
// 所有消息成功解析
MessageComplete func(*Parser)
}
查阅#6 看设计变更原因
Click to show internal directories.
Click to hide internal directories.