negotiate

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package negotiate provides HTTP content negotiation utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accept

func Accept(header string, offers []string) string

Accept returns the best matching offer based on the Accept header value. Returns "" if no offer matches. Matching is case-insensitive per RFC 9110, but the original offer string is returned. Entries with q=0 are treated as "not acceptable" per RFC 9110 §12.5.1 and exclude matching offers even from wildcard entries.

func MatchMedia

func MatchMedia(pattern, offer string) bool

MatchMedia returns true if the Accept pattern matches the offered media type. Supports wildcards: "*" or "*/*" matches everything, "text/*" matches any text subtype. Comparison is case-insensitive per RFC 9110.

Types

type AcceptItem

type AcceptItem struct {
	MediaType string
	Quality   float64
}

AcceptItem represents a parsed Accept header entry with media type and quality.

func Parse

func Parse(header string) []AcceptItem

Parse parses an Accept header value into a slice of AcceptItems. MediaType values are lowercased for case-insensitive matching.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL