package middleware import ( "net/http" "git.codelab.vc/pkg/httpx/internal/requestid" ) // RequestID returns a middleware that propagates the request ID from the // request context to the outgoing X-Request-Id header. This pairs with // the server.RequestID middleware: the server stores the ID in the context, // and the client middleware forwards it to downstream services. func RequestID() Middleware { return func(next http.RoundTripper) http.RoundTripper { return RoundTripperFunc(func(req *http.Request) (*http.Response, error) { if id := requestid.FromContext(req.Context()); id != "" { req = req.Clone(req.Context()) req.Header.Set("X-Request-Id", id) } return next.RoundTrip(req) }) } }