http

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package http provides shared server wiring and middleware helpers.

Index

Examples

Constants

View Source
const HeaderTraceID = lipsdk.HeaderTraceID

HeaderTraceID is the default inbound/outbound trace header.

Variables

This section is empty.

Functions

func CoarsePathGroup

func CoarsePathGroup(path string) string

CoarsePathGroup returns the first URL path segment as a bounded route family (e.g. "/v1/foo" -> "/v1", "/" -> "/"). Used for metrics, tracing span names, and access logs.

Example
fmt.Println(CoarsePathGroup("/v1/models/list"))
Output:
/v1

func RequestIDMiddleware

func RequestIDMiddleware(gen *diag.TraceIDGenerator, next http.Handler) http.Handler

RequestIDMiddleware generates and injects a new trace ID when one is not already present in the request context. gen must be non-nil (typically diag.NewTraceIDGenerator from the composition root).

func RequestIDMiddlewareHeaders

func RequestIDMiddlewareHeaders(gen *diag.TraceIDGenerator, names []string, next http.Handler) http.Handler

RequestIDMiddlewareHeaders is RequestIDMiddleware and echoes the trace ID on each configured outbound header name (defaults to HeaderTraceID).

func SecurityHeadersMiddleware

func SecurityHeadersMiddleware(next http.Handler) http.Handler

SecurityHeadersMiddleware adds standard security headers to every response.

func TraceMiddleware

func TraceMiddleware(next http.Handler) http.Handler

TraceMiddleware injects a trace ID into the request context when a configured inbound trace header is present.

func TraceMiddlewareHeaders

func TraceMiddlewareHeaders(names []string, next http.Handler) http.Handler

TraceMiddlewareHeaders is TraceMiddleware with explicit inbound header names. Empty names use HeaderTraceID.

Types

type ResponseStatusRecorder

type ResponseStatusRecorder struct {
	nethttp.ResponseWriter
	Status int
}

ResponseStatusRecorder wraps net/http.ResponseWriter and records the first status passed to WriteHeader. It forwards optional net/http.ResponseWriter behaviors (Flusher, Hijacker, Pusher, io.ReaderFrom) so streaming middleware preserves flush and HTTP/2 push support.

func (*ResponseStatusRecorder) Flush

func (rr *ResponseStatusRecorder) Flush()

Flush forwards to the underlying net/http.Flusher when supported; otherwise it is a no-op.

func (*ResponseStatusRecorder) Hijack

Hijack forwards to the underlying net/http.Hijacker when supported.

func (*ResponseStatusRecorder) Push

func (rr *ResponseStatusRecorder) Push(target string, opts *nethttp.PushOptions) error

Push forwards to the underlying net/http.Pusher when supported.

func (*ResponseStatusRecorder) ReadFrom

func (rr *ResponseStatusRecorder) ReadFrom(r io.Reader) (int64, error)

ReadFrom forwards to the underlying io.ReaderFrom when supported. Like ResponseStatusRecorder.Write, the first body bytes imply status 200 if WriteHeader was not called.

func (*ResponseStatusRecorder) Write

func (rr *ResponseStatusRecorder) Write(b []byte) (int, error)

Write implements net/http.ResponseWriter. If WriteHeader has not been called yet, the first Write implicitly sets status 200 (matching net/http.ResponseWriter rules) so ResponseStatusRecorder.Status reflects a committed response for middleware such as panic recovery that must not write a second body after bytes have been sent.

func (*ResponseStatusRecorder) WriteHeader

func (rr *ResponseStatusRecorder) WriteHeader(code int)

Jump to

Keyboard shortcuts

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