William Petit
04b41baea3
Some checks are pending
Cadoles/bouncer/pipeline/pr-develop Build started...
32 lines
735 B
Go
32 lines
735 B
Go
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)
|
|
}
|
|
|
|
func CtxRequest(ctx context.Context) (*http.Request, bool) {
|
|
return rule.Context[*http.Request](ctx, contextKeyRequest)
|
|
}
|
|
|
|
func CtxResponse(ctx context.Context) (*http.Response, bool) {
|
|
return rule.Context[*http.Response](ctx, contextKeyResponse)
|
|
}
|