Documentation ¶
Overview ¶
Package proto provides byte-level interaction with HTTP request payload.
Example of HTTP payload for future references, new line symbols escaped:
POST /upload HTTP/1.1\r\n User-Agent: Gor\r\n Content-Length: 11\r\n \r\n Hello world GET /index.html HTTP/1.1\r\n User-Agent: Gor\r\n \r\n \r\n
Index ¶
- Variables
- func AddHeader(payload, name, value []byte) []byte
- func Body(payload []byte) []byte
- func Header(payload, name []byte) []byte
- func IsHTTPPayload(payload []byte) bool
- func MIMEHeadersEndPos(payload []byte) int
- func MIMEHeadersStartPos(payload []byte) int
- func Method(payload []byte) []byte
- func Path(payload []byte) []byte
- func PathParam(payload, name []byte) (value []byte, valueStart, valueEnd int)
- func SetHeader(payload, name, value []byte) []byte
- func SetHost(payload, url, host []byte) []byte
- func SetPath(payload, path []byte) []byte
- func SetPathParam(payload, name, value []byte) []byte
- func Status(payload []byte) []byte
Constants ¶
This section is empty.
Variables ¶
var CLRF = []byte("\r\n")
In HTTP newline defined by 2 bytes (for both windows and *nix support)
var EmptyLine = []byte("\r\n\r\n")
New line acts as separator: end of Headers or Body (in some cases)
var HeaderDelim = []byte(": ")
Separator for Header line. Header looks like: `HeaderName: value`
Functions ¶
func AddHeader ¶
AddHeader takes http payload and appends new header to the start of headers section Returns modified request payload
func IsHTTPPayload ¶
func MIMEHeadersEndPos ¶
MIMEHeadersEndPos finds end of the Headers section, which should end with empty line.
func MIMEHeadersStartPos ¶
MIMEHeadersStartPos finds start of Headers section It just finds position of second line (first contains location and method).
func PathParam ¶
PathParam returns URL query attribute by given name, if no found: valueStart will be -1
func SetHeader ¶
SetHeader sets header value. If header not found it creates new one. Returns modified request payload
func SetHost ¶
SetHost updates Host header for HTTP/1.1 or updates host in path for HTTP/1.0 or Proxy requests Returns modified payload
func SetPathParam ¶
SetPathParam takes payload and updates path Query attribute If query param not found, it will append new Returns modified payload
Types ¶
This section is empty.