Skip to content

Commit

Permalink
adds Set-Cookie method to the HTTP transport. (#3353)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonybase authored Jun 27, 2024
1 parent 46362d1 commit 3198e0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions transport/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions transport/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Transport struct {
reqHeader headerCarrier
replyHeader headerCarrier
request *http.Request
response http.ResponseWriter
pathTemplate string
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3198e0b

Please sign in to comment.