http

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: AGPL-3.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrClientCanceled   = "the request was cancelled by the client"
	ErrDeadlineExceeded = "" /* 159-byte string literal not displayed */
)
View Source
const StatusClientClosedRequest = 499

StatusClientClosedRequest is the status code for when a client request cancellation of an http request

Variables

This section is empty.

Functions

func AuthenticateUser added in v2.1.0

func AuthenticateUser(on bool) middleware.Interface

AuthenticateUser propagates the user ID from HTTP headers back to the request's context. If on is false, it will inject the default tenant ID.

func ClientHTTPStatusAndError

func ClientHTTPStatusAndError(err error) (int, error)

ClientHTTPStatusAndError returns error and http status that is "safe" to return to client without exposing any implementation details.

func Error

func Error(w http.ResponseWriter, err error)

Error write a go error with the correct status code.

func ErrorWithStatus

func ErrorWithStatus(w http.ResponseWriter, err error, status int)

func InstrumentedDefaultHTTPClient added in v2.1.0

func InstrumentedDefaultHTTPClient(instruments ...RoundTripperInstrumentFunc) *http.Client

InstrumentedDefaultHTTPClient returns an http client configured with some default settings which is wrapped with a variety of instrumented RoundTrippers.

func InstrumentedHTTPClient added in v2.1.0

func InstrumentedHTTPClient(client *http.Client, instruments ...RoundTripperInstrumentFunc) *http.Client

InstrumentedHTTPClient adds the associated instrumentation middlewares to the provided http client.

func K6Middleware

func K6Middleware() middleware.Interface

K6Middleware creates a middleware that extracts k6 load test labels from the request baggage and adds them as dynamic profiling labels.

func NewHTTPMetricMiddleware added in v2.1.0

func NewHTTPMetricMiddleware(mux *mux.Router, namespace string, reg prometheus.Registerer) (middleware.Interface, error)

NewHTTPMetricMiddleware creates a new middleware that automatically instruments HTTP requests from the given router.

func RenderHTTPResponse added in v2.1.0

func RenderHTTPResponse(w http.ResponseWriter, v interface{}, t *template.Template, r *http.Request)

RenderHTTPResponse either responds with JSON or a rendered HTML page using the passed in template by checking the Accepts header.

func WriteHTMLResponse added in v2.1.0

func WriteHTMLResponse(w http.ResponseWriter, message string)

WriteHTMLResponse sends message as text/html response with 200 status code.

func WriteJSONResponse added in v2.1.0

func WriteJSONResponse(w http.ResponseWriter, v interface{})

WriteJSONResponse writes some JSON as a HTTP response.

func WriteTextResponse added in v2.1.0

func WriteTextResponse(w http.ResponseWriter, message string)

WriteTextResponse sends message as text/plain response with 200 status code.

func WriteYAMLResponse added in v2.1.0

func WriteYAMLResponse(w http.ResponseWriter, v interface{})

WriteYAMLResponse writes some YAML as a HTTP response.

Types

type Log added in v2.1.0

type Log struct {
	Log                      log.Logger
	LogRequestHeaders        bool
	LogRequestExcludeHeaders []string
	LogRequestAtInfoLevel    bool // LogRequestAtInfoLevel true -> log requests at info log level
	SourceIPs                *middleware.SourceIPExtractor
	// contains filtered or unexported fields
}

Log middleware logs http requests

func (*Log) Wrap added in v2.1.0

func (l *Log) Wrap(next http.Handler) http.Handler

Wrap implements Middleware

type RoundTripperFunc added in v2.1.0

type RoundTripperFunc func(req *http.Request) (*http.Response, error)

func (RoundTripperFunc) RoundTrip added in v2.1.0

func (f RoundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error)

type RoundTripperInstrumentFunc added in v2.1.0

type RoundTripperInstrumentFunc func(next http.RoundTripper) http.RoundTripper

func WithBaggageTransport added in v2.1.0

func WithBaggageTransport() RoundTripperInstrumentFunc

WithBaggageTransport will set the Baggage header on the request if there is any baggage in the context and it was not already set.

func WithTracingTransport added in v2.1.0

func WithTracingTransport() RoundTripperInstrumentFunc

WithTracingTransport wraps the given RoundTripper with a tracing instrumented one.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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