Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gobwas/httphead
https://github.com/gobwas/httphead
headers http parsing rfc-2616
Last synced: 12 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/gobwas/httphead
- Owner: gobwas
- License: mit
- Created: 2017-02-24T22:29:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-12-08T10:25:42.000Z (almost 4 years ago)
- Last Synced: 2024-10-29T19:58:24.388Z (15 days ago)
- Topics: headers, http, parsing, rfc-2616
- Language: Go
- Size: 44.9 KB
- Stars: 85
- Watchers: 7
- Forks: 17
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# httphead.[go](https://golang.org)
[![GoDoc][godoc-image]][godoc-url]
> Tiny HTTP header value parsing library in go.
## Overview
This library contains low-level functions for scanning HTTP RFC2616 compatible header value grammars.
## Install
```shell
go get github.com/gobwas/httphead
```## Example
The example below shows how multiple-choise HTTP header value could be parsed with this library:
```go
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:```go
// 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][godoc-url] or package tests.
[godoc-image]: https://godoc.org/github.com/gobwas/httphead?status.svg
[godoc-url]: https://godoc.org/github.com/gobwas/httphead
[travis-image]: https://travis-ci.org/gobwas/httphead.svg?branch=master
[travis-url]: https://travis-ci.org/gobwas/httphead