Winlin 1545425e06 TEST: Upgrade pion to v3.2.9. (#3567) 1 year ago
..
LICENSE 5a420ece3b GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2 years ago
README.md 5a420ece3b GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2 years ago
cookie.go 5a420ece3b GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2 years ago
head.go 5a420ece3b GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2 years ago
httphead.go 5a420ece3b GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2 years ago
lexer.go 5a420ece3b GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2 years ago
octet.go 5a420ece3b GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2 years ago
option.go 5a420ece3b GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2 years ago
writer.go 5a420ece3b GB28181: Support GB28181-2016 protocol. v5.0.74 (#3201) 2 years ago

README.md

httphead.go

GoDoc

Tiny HTTP header value parsing library in go.

Overview

This library contains low-level functions for scanning HTTP RFC2616 compatible header value grammars.

Install

    go get github.com/gobwas/httphead

Example

The example below shows how multiple-choise HTTP header value could be parsed with this library:

	options, ok := httphead.ParseOptions([]byte(`foo;bar=1,baz`), nil)
	fmt.Println(options, ok)
	// Output: [{foo map[bar:1]} {baz map[]}] true

The low-level example below shows how to optimize keys skipping and selection of some key:

	// The right part of full header line like:
	// X-My-Header: key;foo=bar;baz,key;baz
	header := []byte(`foo;a=0,foo;a=1,foo;a=2,foo;a=3`)

	// We want to search key "foo" with an "a" parameter that equal to "2".
	var (
		foo = []byte(`foo`)
		a   = []byte(`a`)
		v   = []byte(`2`)
	)
	var found bool
	httphead.ScanOptions(header, func(i int, key, param, value []byte) Control {
		if !bytes.Equal(key, foo) {
			return ControlSkip
		}
		if !bytes.Equal(param, a) {
			if bytes.Equal(value, v) {
				// Found it!
				found = true
				return ControlBreak
			}
			return ControlSkip
		}
		return ControlContinue
	})

For more usage examples please see docs or package tests.