This is an automated email from the ASF dual-hosted git repository.

Alanxtl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/develop by this push:
     new bcd6aa42b fix triple unary response metadata (#3446)
bcd6aa42b is described below

commit bcd6aa42be158b28f969e7669c43ae8f543ac7e5
Author: Xuetao Li <[email protected]>
AuthorDate: Tue Jul 14 03:26:33 2026 +0000

    fix triple unary response metadata (#3446)
---
 protocol/triple/triple_protocol/handler.go         |  1 +
 protocol/triple/triple_protocol/triple_ext_test.go | 33 ++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/protocol/triple/triple_protocol/handler.go 
b/protocol/triple/triple_protocol/handler.go
index a0ad7e42f..2cbbdb596 100644
--- a/protocol/triple/triple_protocol/handler.go
+++ b/protocol/triple/triple_protocol/handler.go
@@ -109,6 +109,7 @@ func generateUnaryHandlerFunc(
                request.header = conn.RequestHeader()
                // embed header in context so that user logic could process 
them via FromIncomingContext
                ctx = newIncomingContext(ctx, conn.RequestHeader())
+               ctx = context.WithValue(ctx, handlerOutgoingKey{}, conn)
 
                response, err := untyped(ctx, request)
 
diff --git a/protocol/triple/triple_protocol/triple_ext_test.go 
b/protocol/triple/triple_protocol/triple_ext_test.go
index 73e477376..fb8b40e58 100644
--- a/protocol/triple/triple_protocol/triple_ext_test.go
+++ b/protocol/triple/triple_protocol/triple_ext_test.go
@@ -532,6 +532,39 @@ func TestServer(t *testing.T) {
        })
 }
 
+func TestSetHeaderAndSetTrailerInUnaryHandler(t *testing.T) {
+       t.Parallel()
+
+       handler := triple.NewUnaryHandler(
+               "/connect.ping.v1.PingService/Ping",
+               func() any { return new(pingv1.PingRequest) },
+               func(ctx context.Context, req *triple.Request) 
(*triple.Response, error) {
+                       if err := triple.SetHeader(ctx, 
http.Header{handlerHeader: []string{headerValue}}); err != nil {
+                               return nil, err
+                       }
+                       if err := triple.SetTrailer(ctx, 
http.Header{handlerTrailer: []string{trailerValue}}); err != nil {
+                               return nil, err
+                       }
+
+                       msg := req.Msg.(*pingv1.PingRequest)
+                       return triple.NewResponse(&pingv1.PingResponse{
+                               Number: msg.Number,
+                               Text:   msg.Text,
+                       }), nil
+               },
+       )
+       server := httptest.NewServer(handler)
+       t.Cleanup(server.Close)
+
+       client := pingv1connect.NewPingServiceClient(server.Client(), 
server.URL)
+       request := triple.NewRequest(&pingv1.PingRequest{Number: 42})
+       response := triple.NewResponse(&pingv1.PingResponse{})
+       err := client.Ping(context.Background(), request, response)
+       assert.Nil(t, err)
+       assert.Equal(t, response.Header().Values(handlerHeader), 
[]string{headerValue})
+       assert.Equal(t, response.Trailer().Values(handlerTrailer), 
[]string{trailerValue})
+}
+
 func TestConcurrentStreams(t *testing.T) {
        if testing.Short() {
                t.Skipf("skipping %s test in short mode", t.Name())

Reply via email to