httputil

package
v0.0.0-...-5d378bd Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package httputil contains HTTP helpers used by discovery and JWKS clients.

FetchJSON applies JSON request headers, handles conditional responses, captures bounded error-body previews, and delegates successful response decoding to the caller. CalculateFreshUntil centralizes Cache-Control and Expires handling with a caller-provided fallback TTL.

Most applications should use the higher-level [metadata], [jwks], or [rp] packages instead of this package directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateFreshUntil

func CalculateFreshUntil(req *http.Request, statusCode int, headers http.Header, fallbackTTL time.Duration, now time.Time) time.Time

CalculateFreshUntil respects Cache-Control/Expires headers and falls back to the provided TTL when the response lacks explicit caching headers.

Types

type DecodeError

type DecodeError struct {
	Err error
}

DecodeError signals that the decoder returned a failure while handling a 200 response body. Callers can unwrap this type to add package-specific context.

func (*DecodeError) Error

func (e *DecodeError) Error() string

func (*DecodeError) Unwrap

func (e *DecodeError) Unwrap() error

type FetchJSONResult

type FetchJSONResult struct {
	NotModified bool
	StatusCode  int
	ETag        string
	FreshUntil  time.Time
	FetchedAt   time.Time
	BodyPreview string
}

FetchJSONResult captures the metadata that every JSON-based fetch flow needs.

func FetchJSON

func FetchJSON(req *http.Request, client *http.Client, priorETag string, fallbackTTL time.Duration, decoder func(io.Reader) error) (FetchJSONResult, error)

FetchJSON executes the provided request, applies JSON-specific headers, handles conditional success/previewing error bodies, and runs the decoder when a 200 response arrives.

Jump to

Keyboard shortcuts

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