1
0
Fork
You've already forked accept
0
A go library for parsing and using the accept header
  • Go 100%
2025年04月19日 21:06:45 +00:00
go.mod change module path 2022年06月17日 19:40:49 +02:00
LICENSE Initial commit 2022年06月05日 17:36:06 +02:00
match.go return first servable for empty header 2022年06月05日 19:46:34 +02:00
match_test.go also match application/json to application/ld+json 2022年06月05日 18:19:41 +02:00
README.md correct and explain example 2025年04月19日 21:06:45 +00:00

Accept

A go library to parse the Accept HTTP Header

It was written because of this toot: https://uwu.social/@Joshix/108424918060682309

Usage:

import"codeberg.org/u0nel/accept"funcHandleRequest(whttp.ResponseWriter,r*http.Request){// we're using a slice instead of a map[string]func,// because we want to be able to rank the typespossible_types:=[]string{"text/html","application/ld+json","text/plain",}switchaccept.ServeType(possible_types,r.Header.Get("Accept")){case"text/html":// write htmlcase"application/ld+json":// also matches if request accepts 'application/json'// write jsonldcase"text/plain":// write plaintextdefault:// only if accept header exists and none matches one of the possible typeshttp.Error(w,"Could not serve requested Type",http.StatusNotAcceptable)}}

Example:
codeberg.org/uonel/useragent