Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPAccept ¶
type HTTPAccept struct {
// contains filtered or unexported fields
}
HTTPAccept represents the values of the Accept headers of an HTTP request.
Note that an HTTP request can have multople Accept headers.
func Create ¶
func Create(mediaranges ...mediarange.MediaRange) HTTPAccept
Create creates an HTTPAccept.
For example:
// Accept: application/activity+json
accept := httpaccept.Create(
mediarange.Create("application", "activity+json"), // application/activity+json
)
// Accept: image/png,image/gif
accept := httpaccept.Create(
mediarange.Create("image", "png"), // image/png
mediarange.Create("image", "gif"), // image/gif
)
func Parse ¶
func Parse(headers ...string) (HTTPAccept, error)
Parse parses a list of strings and returns an HTTPAccept.
For example:
mr, err := mediaaccept.Parse("text/html,application/xhtml+xml, application/xml , image/avif,image/webp, */*")
And:
mr, err := mediaaccept.Parse("image/png,image/gif", "text/html,text/plain", "*/*")
func (HTTPAccept) Negotiate ¶
func (receiver HTTPAccept) Negotiate(mediatypes ...string) (string, error)
Negotiate figures out if there is an acceptable media-type, and if there is returns the "best" one.
For example:
var accept httpaccept.HTTPAccept
// ...
contentType, err := accept.Negotiate("text/gemini", "text/html", "application/activity+json")
func (HTTPAccept) String ¶
func (receiver HTTPAccept) String() string
String returns the serialized HTTP Accept header.
For example:
// "Accept: text/html,application/xhtml+xml\r\n"
s := httpaccept.Create(mediarange.Create("text", "html"), mediarange.Create("application","xhtml+xml")).String()
Click to show internal directories.
Click to hide internal directories.