Skip to content

Go package providing an implementation of HTTP Content Negotiation compliant with RFC 7231

License

Notifications You must be signed in to change notification settings

kevinpollet/nego

Repository files navigation

nego

Build Status GoDoc Go Report Card

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.

Installation

Install using go get github.com/kevinpollet/nego.

Usage

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")
		...
	})
}

Contributing

Contributions are welcome!

Want to file a bug, request a feature or contribute some code?

  1. Check out the Code of Conduct.
  2. Check for an existing issue corresponding to your bug or feature request.
  3. Open an issue to describe your bug or feature request.

License

MIT

About

Go package providing an implementation of HTTP Content Negotiation compliant with RFC 7231

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Languages