feat: add middleware for handling requests without cancel context

Introduced `GTagMiddlewarWithoutCancel` and `MPv2MiddlewarWithoutCancel` to allow handling of requests with contexts where cancellation signals are ignored. This improves flexibility for specific use cases where cancel propagation is not desired.
This commit is contained in:
Kevin Franklin Kim 2025-04-25 14:52:23 +02:00
parent b2764d77d7
commit 07b186d846
No known key found for this signature in database
2 changed files with 14 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package client
import (
"context"
"net/http"
"strings"
@ -58,6 +59,12 @@ func GTagMiddlewarClientID(next GTagHandler) GTagHandler {
}
}
func GTagMiddlewarWithoutCancel(next GTagHandler) GTagHandler {
return func(r *http.Request, payload *gtag.Payload) error {
return next(r.WithContext(context.WithoutCancel(r.Context())), payload)
}
}
func GTagMiddlewarSessionID(measurementID string) GTagMiddleware {
measurementID = strings.Split(measurementID, "-")[1]
return func(next GTagHandler) GTagHandler {

View File

@ -1,6 +1,7 @@
package client
import (
"context"
"net/http"
"strings"
@ -47,6 +48,12 @@ func MPv2MiddlewarDebugMode(next MPv2Handler) MPv2Handler {
}
}
func MPv2MiddlewarWithoutCancel(next MPv2Handler) MPv2Handler {
return func(r *http.Request, payload *mpv2.Payload[any]) error {
return next(r.WithContext(context.WithoutCancel(r.Context())), payload)
}
}
func MPv2MiddlewareUserID(cookieName string) MPv2Middleware {
return func(next MPv2Handler) MPv2Handler {
return func(r *http.Request, payload *mpv2.Payload[any]) error {