package httphead

Import Path
	github.com/gobwas/httphead (on go.dev)

Dependency Relation
	imports 5 packages, and imported by one package

Involved Source Files cookie.go head.go Package httphead contains utils for parsing HTTP and HTTP-grammar compatible text protocols headers. That is, this package first aim is to bring ability to easily parse constructions, described here https://tools.ietf.org/html/rfc2616#section-2 lexer.go octet.go option.go writer.go
Package-Level Type Names (total 12)
/* sort by: | */
Control represents operation that scanner should perform. const ControlBreak const ControlContinue const ControlSkip
CookieScanner contains options for scanning cookie pairs. See https://tools.ietf.org/html/rfc6265#section-4.1.1 BreakOnPairError sets scanner to immediately return after first pair syntax validation error. If false, scanner will try to skip invalid pair bytes and go ahead. DisableNameValidation disables name validation of a cookie. If false, only RFC2616 "tokens" are accepted. DisableValueValidation disables value validation of a cookie. If false, only RFC6265 "cookie-octet" characters are accepted. Note that Strict option also affects validation of a value. If Strict is false, then scanner begins to allow space and comma characters inside the value for better compatibility with non standard cookies implementations. Strict enables strict RFC6265 mode scanning. It affects name and value validation, as also some other rules. If false, it is intended to bring the same behavior as http.Request.Cookies(). Scan maps data to name and value pairs. Usually data represents value of the Cookie header. var DefaultCookieScanner
ItemType encodes type of the lexing token. func ScanToken(p []byte) (n int, t ItemType) func (*Scanner).Type() ItemType const ItemComment const ItemOctet const ItemSeparator const ItemString const ItemToken const ItemUndef
OctetType desribes character type. From the "Basic Rules" chapter of RFC2616 See https://tools.ietf.org/html/rfc2616#section-2.2 OCTET = <any 8-bit sequence of data> CHAR = <any US-ASCII character (octets 0 - 127)> UPALPHA = <any US-ASCII uppercase letter "A".."Z"> LOALPHA = <any US-ASCII lowercase letter "a".."z"> ALPHA = UPALPHA | LOALPHA DIGIT = <any US-ASCII digit "0".."9"> CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)> CR = <US-ASCII CR, carriage return (13)> LF = <US-ASCII LF, linefeed (10)> SP = <US-ASCII SP, space (32)> HT = <US-ASCII HT, horizontal-tab (9)> <"> = <US-ASCII double-quote mark (34)> CRLF = CR LF LWS = [CRLF] 1*( SP | HT ) Many HTTP/1.1 header field values consist of words separated by LWS or special characters. These special characters MUST be in a quoted string to be used within a parameter value (as defined in section 3.6). token = 1*<any CHAR except CTLs or separators> separators = "(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{" | "}" | SP | HT IsChar reports whether octet is CHAR. IsControl reports whether octet is CTL. IsSeparator reports whether octet is separator. IsSpace reports whether octet is space (SP or HT). IsToken reports whether octet is token.
Option represents a header option. Name []byte Parameters Parameters Clone is a shorthand for making slice of opt.Size() sequenced with Copy() call. Copy copies all underlying []byte slices into p and returns new Option. Note that p must be at least of opt.Size() length. Equal reports whether option is equal to b. Size returns number of bytes need to be allocated for use in opt.Copy. String represents option as a string. Option : github.com/gogo/protobuf/proto.Sizer Option : expvar.Var Option : fmt.Stringer func NewOption(name string, params map[string]string) Option func ParseOptions(data []byte, options []Option) ([]Option, bool) func Option.Clone() Option func Option.Copy(p []byte) Option func OptionSelector.Select(data []byte, options []Option) ([]Option, bool) func ParseOptions(data []byte, options []Option) ([]Option, bool) func WriteOptions(dest io.Writer, options []Option) (n int, err error) func Option.Equal(b Option) bool func OptionSelector.Select(data []byte, options []Option) ([]Option, bool)
OptionSelector contains configuration for selecting Options from header value. Alloc used to allocate slice of bytes when selector is configured with SelectCopy flag. It will be called with number of bytes needed for copy of single Option. If Alloc is nil make is used. Check is a filter function that applied to every Option that possibly could be selected. If Check is nil all options will be selected. Flags contains flags for options selection. Select parses header data and appends it to given slice of Option. It also returns flag of successful (wellformed input) parsing.
Parameters represents option's parameters. Copy copies all underlying []byte slices into dst and returns new Parameters. Note that dst must be at least of p.Size() length. Equal reports whether a equal to b. ForEach iterates over parameters key-value pairs and calls cb for each one. Get returns value by key and flag about existence such value. Set sets value by key. Size returns number of bytes that needed to copy p. String represents parameters as a string. *Parameters : github.com/gogo/protobuf/proto.Sizer *Parameters : expvar.Var *Parameters : fmt.Stringer func (*Parameters).Copy(dst []byte) (Parameters, []byte) func Parameters.Equal(b Parameters) bool
RequestLine contains parameters parsed from the first request line. Method []byte URI []byte Version Version func ParseRequestLine(line []byte) (r RequestLine, ok bool)
ResponseLine contains parameters parsed from the first response line. Reason []byte Status int Version Version func ParseResponseLine(line []byte) (r ResponseLine, ok bool)
Scanner represents header tokens scanner. See https://tools.ietf.org/html/rfc2616#section-2 Advance moves current position index at n bytes. It returns true on successful move. Buffered reporst how many bytes there are left to scan. Bytes returns current token bytes. FetchUntil fetches ItemOctet from current scanner position to first occurence of the c or to the end of the underlying data. Next scans for next token. It returns true on successful scanning, and false on error or EOF. Peek reads byte at current position without advancing it. On end of data it returns 0. Peek2 reads two first bytes at current position without advancing it. If there not enough data it returs 0. Skip skips all bytes until first occurence of c. SkipEscaped skips all bytes until first occurence of non-escaped c. Type reports current token type. *Scanner : github.com/apache/arrow-go/v18/arrow/compute/exec.ArrayIter[bool] *Scanner : github.com/apache/arrow-go/v18/internal/hashing.ByteSlice func NewScanner(data []byte) *Scanner
SelectFlag encodes way of options selection. String represetns flag as string. SelectFlag : expvar.Var SelectFlag : fmt.Stringer const SelectCopy const SelectUnique
Version contains protocol major and minor version. Major int Minor int
Package-Level Functions (total 23)
CanonicalizeHeaderKey is like standard textproto/CanonicalMIMEHeaderKey, except that it operates with slice of bytes and modifies it inplace without copying.
IntFromASCII converts ascii encoded decimal numeric value from HTTP entities to an integer.
NewOption creates named option with given parameters.
NewScanner creates new RFC2616 data scanner.
ParseHeaderLine parses HTTP header as key-value pair. It returns parsed values and true if parse is ok.
ParseOptions parses all header options and appends it to given slice of Option. It returns flag of successful (wellformed input) parsing. Note that appended options are all consist of subslices of data. That is, mutation of data will mutate appended options.
ParseRequestLine parses http request line like "GET / HTTP/1.0".
ParseResponseLine parses first response line into ResponseLine struct.
ParseVersion parses major and minor version of HTTP protocol. It returns parsed values and true if parse is ok.
ReadLine reads line from br. It reads until '\n' and returns bytes without '\n' or '\r\n' at the end. It returns err if and only if line does not end in '\n'. Note that read bytes returned in any case of error. It is much like the textproto/Reader.ReadLine() except the thing that it returns raw bytes, instead of string. That is, it avoids copying bytes read from br. textproto/Reader.ReadLineBytes() is also makes copy of resulting bytes to be safe with future I/O operations on br. We could control I/O operations on br and do not need to make additional copy for safety.
RemoveByte returns data without c. If c is not present in data it returns the same slice. If not, it copies data without c.
ScanCookie scans cookie pairs from data using DefaultCookieScanner.Scan() method.
ScanOptions parses data in this form: values = 1#value value = token *( ";" param ) param = token [ "=" (token | quoted-string) ] It calls given callback with the index of the option, option itself and its parameter (attribute and its value, both could be nil). Index is useful when header contains multiple choises for the same named option. Given callback should return one of the defined Control* values. ControlSkip means that passed key is not in caller's interest. That is, all parameters of that key will be skipped. ControlBreak means that no more keys and parameters should be parsed. That is, it must break parsing immediately. ControlContinue means that caller want to receive next parameter and its value or the next key. It returns false if data is malformed.
ScanPairGreedy scans for complete pair of opening and closing chars in greedy manner. Note that first opening byte must not be present in data.
ScanToken scan for next token in p. It returns length of the token and its type. It do not trim p.
ScanTokens parses data in this form: list = 1#token It returns false if data is malformed.
ScanUntil scans for first non-escaped character c in given data. It returns index of matched c and -1 if c is not found.
SkipSpace skips spaces and lws-sequences from p. It returns number ob bytes skipped.
SplitRequestLine splits given slice of bytes into three chunks without parsing.
SplitResponseLine splits given slice of bytes into three chunks without parsing.
ValidCookieName reports wheter given bytes is a valid RFC2616 "token" bytes.
ValidCookieValue reports whether given value is a valid RFC6265 "cookie-octet" bytes. cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E ; US-ASCII characters excluding CTLs, ; whitespace DQUOTE, comma, semicolon, ; and backslash Note that the false strict parameter disables errors on space 0x20 and comma 0x2c. This could be useful to bring some compatibility with non-compliant clients/servers in the real world. It acts the same as standard library cookie parser if strict is false.
WriteOptions write options list to the dest. It uses the same form as {Scan,Parse}Options functions: values = 1#value value = token *( ";" param ) param = token [ "=" (token | quoted-string) ] It wraps valuse into the quoted-string sequence if it contains any non-token characters.
Package-Level Variables (total 2)
DefaultCookieScanner is a CookieScanner which is used by ScanCookie(). Note that it is intended to have the same behavior as http.Request.Cookies() has.
OctetTypes is a table of octets.
Package-Level Constants (total 11)
ControlBreak causes scanner to stop scan tokens.
ControlContinue causes scanner to continue scan tokens.
ControlSkip causes scanner to skip current entity.
ItemComment reports that token is RFC2616 comment.
ItemOctet reports that token is octet slice.
ItemSeparator reports that token is RFC2616 separator.
ItemString reports that token is RFC2616 quouted string.
ItemToken reports that token is RFC2616 token.
ItemUndef reports that token is undefined.
SelectCopy causes selector to copy selected option before appending it to resulting slice. If SelectCopy flag is not passed to selector, then appended options will contain sub-slices of the initial data.
SelectUnique causes selector to append only not yet existing option to resulting slice. Unique is checked by comparing option names.