Documentation ¶
Overview ¶
Package nego implements HTTP Content Negotiation functions compliant with RFC 7231.
See https://tools.ietf.org/html/rfc7231#section-5.3 for more details.
Example ¶
This example shows how to use the negotiation functions.
import ( "net/http" "github.com/kevinpollet/nego" ) handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { nego.NegotiateContentCharset(req, "utf-8") nego.NegotiateContentEncoding(req, "gzip", "deflate") nego.NegotiateContentLanguage(req, "fr", "en") nego.NegotiateContentType(req, "text/plain") })
Index ¶
- Constants
- func NegotiateContentCharset(req *http.Request, offerCharsets ...string) string
- func NegotiateContentEncoding(req *http.Request, offerEncodings ...string) string
- func NegotiateContentLanguage(req *http.Request, offerLanguages ...string) string
- func NegotiateContentType(req *http.Request, offerMediaTypes ...string) string
Constants ¶
const EncodingIdentity = "identity"
The identity encoding constant used as a synonym for "no encoding" in order to communicate when no encoding is preferred.
See https://tools.ietf.org/html/rfc7231#section-5.3.4 for more details.
Variables ¶
This section is empty.
Functions ¶
func NegotiateContentCharset ¶
NegotiateContentCharset returns the best acceptable charset offer to use in the response according to the Accept-Charset request's header. If the given offer list is empty or no offer is acceptable then, an empty string is returned.
See https://tools.ietf.org/html/rfc7231#section-5.3.3 for more details.
func NegotiateContentEncoding ¶
NegotiateContentEncoding returns the best acceptable encoding offer to use in the response according to the Accept-Encoding request's header. If the given offer list is empty or no offer is acceptable then, an empty string is returned.
See https://tools.ietf.org/html/rfc7231#section-5.3.4 for more details.
func NegotiateContentLanguage ¶
NegotiateContentLanguage returns the best acceptable language offer to use in the response according to the Accept-Language request's header. If the given offer list is empty or no offer is acceptable then, an empty string is returned.
See https://tools.ietf.org/html/rfc7231#section-5.3.5 for more details.
func NegotiateContentType ¶
NegotiateContentType returns the best acceptable media type offer to use in the response according to the Accept-Language request's header. If the given offer list is empty or no offer is acceptable then, an empty string is returned.
See https://tools.ietf.org/html/rfc7231#section-5.3.2 for more details.
Types ¶
This section is empty.