2024-09-24 15:46:42 +02:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/rule"
|
|
|
|
)
|
|
|
|
|
|
|
|
type contextKey string
|
|
|
|
|
|
|
|
const (
|
|
|
|
contextKeyRequest contextKey = "request"
|
|
|
|
contextKeyResponse contextKey = "response"
|
|
|
|
)
|
|
|
|
|
|
|
|
func WithRequest(ctx context.Context, r *http.Request) context.Context {
|
|
|
|
return context.WithValue(ctx, contextKeyRequest, r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithResponse(ctx context.Context, r *http.Response) context.Context {
|
|
|
|
return context.WithValue(ctx, contextKeyResponse, r)
|
|
|
|
}
|
|
|
|
|
2024-09-25 15:50:13 +02:00
|
|
|
func CtxRequest(ctx context.Context) (*http.Request, bool) {
|
2024-09-24 15:46:42 +02:00
|
|
|
return rule.Context[*http.Request](ctx, contextKeyRequest)
|
|
|
|
}
|
|
|
|
|
2024-09-25 15:50:13 +02:00
|
|
|
func CtxResponse(ctx context.Context) (*http.Response, bool) {
|
2024-09-24 15:46:42 +02:00
|
|
|
return rule.Context[*http.Response](ctx, contextKeyResponse)
|
|
|
|
}
|