middleware

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package middleware provides utilities to inject the response writer and request reader for the original *http.Request into the context and also retrieve it.

Index

Constants

View Source
const ResponseWriterKey responseWriterKey = "response-writer"

ResponseWriterKey is the context key for the response writer.

Variables

This section is empty.

Functions

func LoginCSRFCookieAliasMiddleware added in v0.18.0

func LoginCSRFCookieAliasMiddleware(configuredName string) func(http.Handler) http.Handler

LoginCSRFCookieAliasMiddleware maps a configured login-CSRF cookie name onto the canonical name that the generated OpenAPI handler reads (session.LoginCSRFCookieName, i.e. "__Host-LoginCSRF").

The generated callback handler hard-codes r.Cookie("__Host-LoginCSRF"), and the "__Host-" prefix requires the cookie's Secure attribute — which browsers reject over plain http://. Local development therefore needs a non-"__Host-" cookie name, but the read side cannot be changed. This middleware bridges the gap: when configuredName differs from the canonical name and only the configured cookie is present, it appends a copy under the canonical name so the downstream binder finds it.

It is a no-op when configuredName is empty or already equal to the canonical name, so production behavior is unchanged.

func ResponseWriterFromContext

func ResponseWriterFromContext(ctx context.Context) (http.ResponseWriter, error)

ResponseWriterFromContext is a helper function that retrieves the response writer from the context.

func ResponseWriterMiddleware

func ResponseWriterMiddleware(next http.Handler) http.Handler

ResponseWriterMiddleware is an http.Handler middleware that injects the response writer for the original *http.Request into the context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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