mirror of
https://github.com/go-kratos/kratos.git
synced 2024-12-26 20:54:38 +02:00
adds Set-Cookie method to the HTTP transport. (#3353)
This commit is contained in:
parent
46362d1a36
commit
3198e0b83b
@ -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()
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user