diff --git a/transport/http/server.go b/transport/http/server.go index 9c5550b22..917b41e19 100644 --- a/transport/http/server.go +++ b/transport/http/server.go @@ -296,6 +296,7 @@ func (s *Server) filter() mux.MiddlewareFunc { reqHeader: headerCarrier(req.Header), replyHeader: headerCarrier(w.Header()), request: req, + response: w, } if s.endpoint != nil { tr.endpoint = s.endpoint.String() diff --git a/transport/http/transport.go b/transport/http/transport.go index 686baed76..0400ea833 100644 --- a/transport/http/transport.go +++ b/transport/http/transport.go @@ -23,6 +23,7 @@ type Transport struct { reqHeader headerCarrier replyHeader headerCarrier request *http.Request + response http.ResponseWriter pathTemplate string } @@ -70,6 +71,17 @@ func SetOperation(ctx context.Context, op string) { } } +// SetCookie adds a Set-Cookie header to the provided [ResponseWriter]'s headers. +// The provided cookie must have a valid Name. Invalid cookies may be +// silently dropped. +func SetCookie(ctx context.Context, cookie *http.Cookie) { + if tr, ok := transport.FromServerContext(ctx); ok { + if tr, ok := tr.(*Transport); ok { + http.SetCookie(tr.response, cookie) + } + } +} + // RequestFromServerContext returns request from context. func RequestFromServerContext(ctx context.Context) (*http.Request, bool) { if tr, ok := transport.FromServerContext(ctx); ok {