Go package providing an implementation of HTTP Content Negotiation compliant with RFC 7231.
As defined in RFC 7231 the following request headers are sent by a user agent to engage in a proactive negotiation of the response content: Accept, Accept-Charset, Accept-Language and Accept-Encoding.
This package provides convenient functions to negotiate the best and acceptable response content type, charset, language and encoding.
Install using go get github.com/kevinpollet/nego.
package main
import (
"log"
"net/http"
"github.com/kevinpollet/nego"
)
func main() {
handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
contentCharset := nego.NegotiateContentCharset(req, "utf-8")
contentEncoding := nego.NegotiateContentEncoding(req, "gzip", "deflate")
contentLanguage := nego.NegotiateContentLanguage(req, "fr", "en")
contentType := nego.NegotiateContentType(req, "text/html", "text/plain")
...
})
}Contributions are welcome!
Want to file a bug, request a feature or contribute some code?
- Check out the Code of Conduct.
- Check for an existing issue corresponding to your bug or feature request.
- Open an issue to describe your bug or feature request.