Documentation
¶
Overview ¶
Package detect provides HTTP protocol detection from initial connection bytes.
Index ¶
Constants ¶
View Source
const MinPeekBytes = 4
MinPeekBytes is the minimum number of bytes needed to begin detection.
View Source
const PrefaceLen = len(frame.ClientPreface)
PrefaceLen is the full HTTP/2 client connection preface length.
Variables ¶
View Source
var ( // ErrInsufficientData indicates not enough bytes for detection. ErrInsufficientData = errors.New("insufficient data for protocol detection") // ErrUnknownProtocol indicates the data does not match any known protocol. ErrUnknownProtocol = errors.New("unknown protocol") )
Functions ¶
func Detect ¶
Detect examines the initial bytes of a connection and returns the detected protocol.
Detection logic:
- If len(buf) < 4, return ErrInsufficientData.
- If first 4 bytes are "PRI ", this may be HTTP/2. Need 24 bytes total. If we have 24 bytes and they match ClientPreface -> engine.H2C If we have < 24 bytes -> ErrInsufficientData (need more data) If 24 bytes don't match -> ErrUnknownProtocol
- If first byte is a known HTTP method start character -> engine.HTTP1
- Otherwise -> ErrUnknownProtocol
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.