xhttp

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XForwardedFor    = "X-Forwarded-For"
	XContentTypeOpts = "X-Content-Type-Options"
	XFrameOpts       = "X-Frame-Options"
	XXSSProtection   = "X-Xss-Protection"
	ReferrerPolicy   = "Referrer-Policy"
)
View Source
const (
	ContentType      = "Content-Type"
	ContentLength    = "Content-Length"
	ContentEncoding  = "Content-Encoding"
	AcceptEncoding   = "Accept-Encoding"
	Vary             = "Vary"
	XRateLimitReason = "X-Ratelimit-Reason"
	XSessionID       = "X-Session-Id"
	XAPIKey          = "X-Api-Key" //nolint:gosec // this is a header name, not a credential
)

Variables

This section is empty.

Functions

func Error

func Error(w http.ResponseWriter, status int)

func GetRequestHeaderAPIKey

func GetRequestHeaderAPIKey(req *http.Request) string

func GetRequestHeaderSessionID

func GetRequestHeaderSessionID(req *http.Request) string

func GetRequestIP

func GetRequestIP(r *http.Request) string

func NewHTTPClient

func NewHTTPClient(opts ...ClientOption) *http.Client

func NewRetryTransport added in v0.1.7

func NewRetryTransport(base http.RoundTripper, config RetryConfig) http.RoundTripper

NewRetryTransport creates a new retry transport wrapping the given transport.

func NewTransport

func NewTransport() http.RoundTripper

NewTransport returns an http.RoundTripper with standard thoop headers.

func ParseRetryAfter added in v0.1.7

func ParseRetryAfter(resp *http.Response, maxRetryAfter time.Duration) time.Duration

ParseRetryAfter parses the Retry-After header from a response. Returns 0 if the header is missing or invalid. This is exported for use by SSE clients that handle their own retry logic.

func SetHeaderContentTypeApplicationJSON

func SetHeaderContentTypeApplicationJSON(w http.ResponseWriter)

func SetHeaderContentTypeTextHTMLCharsetUTF8 added in v0.1.8

func SetHeaderContentTypeTextHTMLCharsetUTF8(w http.ResponseWriter)

func SetHeaderRequestID

func SetHeaderRequestID(w http.ResponseWriter, requestID string)

func SetHeaderRetryAfter

func SetHeaderRetryAfter(w http.ResponseWriter, retryAfter time.Duration)

func SetRequestHeaderAPIKey added in v0.0.11

func SetRequestHeaderAPIKey(req *http.Request, apiKey string)

func SetRequestHeaderSessionID

func SetRequestHeaderSessionID(req *http.Request, sessionID string)

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, data any)

func WriteNoContent

func WriteNoContent(w http.ResponseWriter)

func WriteOK

func WriteOK(w http.ResponseWriter, data any)

func WriteRateLimitError

func WriteRateLimitError(w http.ResponseWriter, err *RateLimitError)

Types

type ClientOption

type ClientOption func(*http.Client)

func WithTimeout

func WithTimeout(d time.Duration) ClientOption

type RateLimitError

type RateLimitError struct {
	RetryAfter time.Duration
	Reason     string
	Message    string
}

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

type RetryConfig added in v0.1.7

type RetryConfig struct {
	MaxAttempts    uint          // Maximum number of retry attempts (default: 3)
	MaxRetryAfter  time.Duration // Maximum Retry-After to respect (default: 30s)
	InitialBackoff time.Duration // Initial backoff duration (default: 1s)
	MaxBackoff     time.Duration // Maximum backoff duration (default: 10s)
	BackoffFactor  float64       // Backoff multiplier (default: 2.0)
}

RetryConfig configures the retry transport behavior.

func DefaultRetryConfig added in v0.1.7

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns sensible defaults for retry behavior.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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