Skip to content

Latest commit

 

History

History
50 lines (35 loc) · 1.89 KB

README.md

File metadata and controls

50 lines (35 loc) · 1.89 KB

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