diff --git a/helpers.common.go b/helpers.common.go index a315b0b..a292248 100644 --- a/helpers.common.go +++ b/helpers.common.go @@ -22,6 +22,7 @@ const ( RequestIDPrefix string = "r" ContextRequestID ContextKey = "request.id" ContextRequestNumber ContextKey = "request.number" + ConnContextKey ContextKey = "http-conn" ) func (m missingFieldError) Error() string { @@ -132,3 +133,15 @@ func IsAppRunningInDocker() bool { } return false } + +// SaveConnInContext is the hook used by the server under ConnContext. +// It sets the underlying connection into the request context for later +// use by ReadDeadline or WriteDeadline method on *CustomResponseWriter. +func SaveConnInContext(ctx context.Context, c net.Conn) context.Context { + return context.WithValue(ctx, ConnContextKey, c) +} + +// GetConnFromContext returns the connection saved into the context. +func GetConnFromContext(ctx context.Context) net.Conn { + return ctx.Value(ConnContextKey).(net.Conn) +}