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)
|
||
|
}
|