xhttp

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 6 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 NewTransport

func NewTransport() http.RoundTripper

NewTransport returns an http.RoundTripper with standard thoop headers.

func SetHeaderContentTypeApplicationJSON

func SetHeaderContentTypeApplicationJSON(w http.ResponseWriter)

func SetHeaderContentTypeTextHTML

func SetHeaderContentTypeTextHTML(w http.ResponseWriter)

func SetHeaderRequestID

func SetHeaderRequestID(w http.ResponseWriter, requestID string)

func SetHeaderRetryAfter

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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