Help us shape the future of Go! Take the 2026 Go Developer Survey

internal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 6 Imported by: 0

README

problem/internal

Internal support code for the arkoren.dev/foundation/problem package.

Scope

This package currently provides Accept-header parsing and quality negotiation utilities used by the public problem package.

Stability

This is toolkit-contributor documentation. Go's internal import restriction prevents applications outside the problem module from importing these helpers, even when a helper's name is exported. They may change without notice; consumers use the public arkoren.dev/foundation/problem API instead.

Documentation

Overview

Package internal provides non-exported helpers for the problem module.

It currently contains HTTP Accept negotiation logic used to select response media types for problem rendering.

This package is internal to the module and not part of the public API contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Accept

type Accept struct {
	// contains filtered or unexported fields
}

Accept represents a parsed HTTP Accept header for content negotiation. It retains valid media requirements and weights in client order without modifying requests. Order compares those requirements with full supported content types, including parameters; it performs no response I/O.

func ParseAccept

func ParseAccept(request *http.Request) Accept

ParseAccept parses the Accept header values from request. Invalid ranges are ignored; missing or wholly invalid headers let Order retain the server's supported order. Parsing does not modify the request.

Example:

request := httptest.NewRequest(http.MethodGet, "/", nil)
request.Header.Set("Accept", "application/json")
preferred := internal.ParseAccept(request).Order([]string{"text/plain", "application/json"})
_ = preferred[0] // "application/json"

func (Accept) Order

func (accept Accept) Order(supported []string) []string

Order returns acceptable supported content types in client preference order. Supported values may include parameters; results preserve their original strings. Missing or wholly invalid Accept ranges keep server order. Matching parameters increase specificity; charset values compare case-insensitively.

Example:

request := httptest.NewRequest(http.MethodGet, "/", nil)
request.Header.Set("Accept", "text/plain;charset=UTF-8")
preferred := internal.ParseAccept(request).Order([]string{"text/plain; charset=utf-8"})
_ = preferred[0]

Jump to

Keyboard shortcuts

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