Skip to content
No description or website provided.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE readme and license Mar 12, 2017
README.md
cookie.go fix non-strict parsing of pairs without value Jul 17, 2017
cookie_test.go fix non-strict parsing of pairs without value Jul 17, 2017
head.go CanonicalizeHeaderKey export Jan 30, 2018
head_test.go implement basic http parsing functions Jan 21, 2018
httphead.go ParseOptions: add comment on data mutability Oct 16, 2017
httphead_test.go
lexer.go reimplement cookie scanner (#2) May 25, 2017
lexer_test.go cookie parsing Apr 18, 2017
octet.go reimplement cookie scanner (#2) May 25, 2017
option.go
writer.go reimplement cookie scanner (#2) May 25, 2017
writer_test.go move to bytes in option parameters Apr 2, 2017

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.

You can’t perform that action at this time.