Documentation
¶
Index ¶
- Constants
- func ChunkedEncoding(decoderFactory ChunkedDecoderFactory) func(http.Handler) http.Handler
- func GetRequestID(ctx context.Context) string
- func GetRequestStartTime(ctx context.Context) (time.Time, bool)
- func RequestID(next http.Handler) http.Handler
- func SetDefaultHeadersMiddleware(next http.Handler) http.Handler
- func Timing(next http.Handler) http.Handler
- func TraceID(next http.Handler) http.Handler
- func ValidateS3BucketName(bucket string) error
- func ValidateS3BucketNameMiddleware(getBucket func(*http.Request) string, writeError response.XMLErrorWriter) func(http.Handler) http.Handler
- func ValidateS3Key(key string) error
- func ValidateS3KeyMiddleware(getKey func(*http.Request) string, writeError response.XMLErrorWriter) func(http.Handler) http.Handler
- type ChunkedDecoderFactory
Constants ¶
const (
// RequestIDHeader is the HTTP header name for request IDs
RequestIDHeader = "X-Request-Id"
)
Variables ¶
This section is empty.
Functions ¶
func ChunkedEncoding ¶
func ChunkedEncoding(decoderFactory ChunkedDecoderFactory) func(http.Handler) http.Handler
ChunkedEncoding is a middleware that decodes AWS SigV4 chunked transfer encoding if present in the request body. It should run AFTER authentication middleware.
This middleware: - Checks multiple indicators for AWS SigV4 chunked encoding - If detected, wraps r.Body with a decoder provided by the factory - The handler receives the decoded body transparently - Applies to all operations that accept request bodies (PutObject, UploadPart, etc.)
func GetRequestID ¶
GetRequestID extracts the request ID from the context. Returns an empty string if no request ID is found.
func GetRequestStartTime ¶
GetRequestStartTime retrieves the request start time from context. Returns the time and true if found, or zero time and false if not found.
func RequestID ¶
RequestID is a middleware that generates a unique request ID for each request. It adds the request ID to the request context and optionally to the response headers.
func SetDefaultHeadersMiddleware ¶
SetDefaultHeadersMiddleware is a middleware that sets a specific header
func Timing ¶
Timing is a middleware that captures the request start time as early as possible. This should be the FIRST middleware in the chain to get the most accurate timestamp of when the server received the request.
func TraceID ¶
TraceID is a middleware that generates or accepts a trace ID for each request. This is the first middleware that should run, creating the trace context for the entire request lifecycle. It checks for an incoming X-Trace-ID header and uses it if present, otherwise generates a new one.
func ValidateS3BucketName ¶
ValidateS3BucketName validates a bucket name according to S3 naming rules.
S3 bucket naming rules: - Between 3 and 63 characters long - Consist only of lowercase letters, numbers, dots (.), and hyphens (-) - Begin and end with a letter or number - Must not contain two adjacent periods - Must not be formatted as an IP address (e.g., 192.168.5.4)
func ValidateS3BucketNameMiddleware ¶
func ValidateS3BucketNameMiddleware( getBucket func(*http.Request) string, writeError response.XMLErrorWriter, ) func(http.Handler) http.Handler
ValidateS3BucketNameMiddleware returns a middleware that validates S3 bucket names. It should be applied to routes that have a {bucket} parameter. If validation fails, it writes an error response and stops the request chain.
The getBucket function extracts the bucket name from the request (typically from URL params). The writeError function handles writing the S3-formatted error response.
func ValidateS3Key ¶
ValidateS3Key validates an object key according to S3 naming rules.
S3 key naming rules: - Can be up to 1024 bytes long (UTF-8 encoded) - Can contain any UTF-8 character - Should avoid certain characters that require special handling - Must not start with '/' (not a valid S3 key)
func ValidateS3KeyMiddleware ¶
func ValidateS3KeyMiddleware( getKey func(*http.Request) string, writeError response.XMLErrorWriter, ) func(http.Handler) http.Handler
ValidateS3KeyMiddleware returns a middleware that validates S3 object keys. It should be applied to routes that have a {key} parameter. If validation fails, it writes an error response and stops the request chain.
The getKey function extracts the key from the request (typically from URL params). The writeError function handles writing the S3-formatted error response.