Skip to content

Conversation

@odysseus0
Copy link
Contributor

Summary

  • Adds WithOrigin(r *http.Request, origin string) *http.Request
  • Symmetric with existing GetOrigin(ctx) - completes the API

Motivation

Middleware that validates API keys and derives origin programmatically needs a way to set origin in the request context. Previously, the only option was to set an HTTP header and rely on ExtractOriginFromHeader, which conflates internal context passing with external headers.

Usage

func authMiddleware(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        origin := validateAPIKey(r.Header.Get("X-API-Key"))
        r = rpcserver.WithOrigin(r, origin)
        next.ServeHTTP(w, r)
    })
}

🤖 Generated with Claude Code

Adds WithOrigin(r, origin) to set origin in request context.
Symmetric with GetOrigin(ctx) - completes the API for middleware
that needs to set origin programmatically (e.g., after API key validation).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@odysseus0 odysseus0 merged commit 2821847 into main Jan 20, 2026
2 checks passed
@odysseus0 odysseus0 deleted the feat/with-origin branch January 20, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant