feat/auth-hook: refactor RequstInfo to preserve original HTTP semantics

This commit is contained in:
HEUDavid
2026-02-12 06:44:07 +08:00
parent 3caadac003
commit 65debb874f
2 changed files with 6 additions and 19 deletions

View File

@@ -2282,23 +2282,8 @@ func (h *Handler) GetAuthStatus(c *gin.Context) {
// PopulateAuthContext extracts request info and adds it to the context // PopulateAuthContext extracts request info and adds it to the context
func PopulateAuthContext(ctx context.Context, c *gin.Context) context.Context { func PopulateAuthContext(ctx context.Context, c *gin.Context) context.Context {
info := &coreauth.RequestInfo{ info := &coreauth.RequestInfo{
Query: make(map[string]string), Query: c.Request.URL.Query(),
Headers: make(map[string]string), Headers: c.Request.Header,
} }
// Capture all query parameters, joining multiple values with a comma.
for k, v := range c.Request.URL.Query() {
if len(v) > 0 {
info.Query[k] = strings.Join(v, ",")
}
}
// Capture all headers, joining multiple values with a comma.
for k, v := range c.Request.Header {
if len(v) > 0 {
info.Headers[k] = strings.Join(v, ",")
}
}
return coreauth.WithRequestInfo(ctx, info) return coreauth.WithRequestInfo(ctx, info)
} }

View File

@@ -5,6 +5,8 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"net/http"
"net/url"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@@ -21,8 +23,8 @@ type PostAuthHook func(context.Context, *Auth) error
// RequestInfo holds information extracted from the HTTP request. // RequestInfo holds information extracted from the HTTP request.
// It is injected into the context passed to PostAuthHook. // It is injected into the context passed to PostAuthHook.
type RequestInfo struct { type RequestInfo struct {
Query map[string]string Query url.Values
Headers map[string]string Headers http.Header
} }
type requestInfoKey struct{} type requestInfoKey struct{}