From 08690c2d055e7fa53fb98b1e78ff2cd91188faf3 Mon Sep 17 00:00:00 2001 From: Vitalii Levitskii Date: Tue, 7 May 2024 12:42:24 +0200 Subject: [PATCH] Renamed headerCallerProcedureToRequest to transportHeadersToRequest --- transport/tchannel/handler.go | 4 +--- transport/tchannel/header.go | 10 +++++----- transport/tchannel/header_test.go | 4 ++-- transport/tchannel/outbound.go | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/transport/tchannel/handler.go b/transport/tchannel/handler.go index 714c632d6..672e88a7d 100644 --- a/transport/tchannel/handler.go +++ b/transport/tchannel/handler.go @@ -182,9 +182,7 @@ func (h handler) callHandler(ctx context.Context, call inboundCall, responseWrit return errors.RequestHeadersDecodeError(treq, err) } - // callerProcedure is a rpc header but recevied in application headers, so moving this header to transprotRequest - // by updating treq.CallerProcedure. - treq = headerCallerProcedureToRequest(treq, &headers) + transportHeadersToRequest(treq, headers) treq.Headers = headers if tcall, ok := call.(tchannelCall); ok { diff --git a/transport/tchannel/header.go b/transport/tchannel/header.go index 966607f1c..cd2920b99 100644 --- a/transport/tchannel/header.go +++ b/transport/tchannel/header.go @@ -177,15 +177,13 @@ func decodeHeaders(r io.Reader) (transport.Headers, error) { return headers, reader.Err() } -// headerCallerProcedureToRequest copies callerProcedure from headers to req.CallerProcedure -// and then deletes it from headers. -func headerCallerProcedureToRequest(req *transport.Request, headers *transport.Headers) *transport.Request { +// transportHeadersToRequest copies custom (which are not part of tchannel protocol) transport header values to request +// and then deletes them from headers list. +func transportHeadersToRequest(req *transport.Request, headers transport.Headers) { if callerProcedure, ok := headers.Get(CallerProcedureHeader); ok { req.CallerProcedure = callerProcedure headers.Del(CallerProcedureHeader) - return req } - return req } // requestToTransportHeaders adds custom (which are not part of tchannel protocol) transport headers from request. @@ -197,7 +195,9 @@ func requestToTransportHeaders(req *transport.Request, reqHeaders map[string]str if reqHeaders == nil { reqHeaders = make(map[string]string) } + reqHeaders[CallerProcedureHeader] = req.CallerProcedure + return reqHeaders } diff --git a/transport/tchannel/header_test.go b/transport/tchannel/header_test.go index 339a85d9e..7aa98084a 100644 --- a/transport/tchannel/header_test.go +++ b/transport/tchannel/header_test.go @@ -134,8 +134,8 @@ func TestMoveCallerProcedureToRequest(t *testing.T) { } { t.Run(tt.desc, func(t *testing.T) { headers := transport.HeadersFromMap(tt.headers) - treq := headerCallerProcedureToRequest(&tt.treq, &headers) - assert.Equal(t, tt.expectedTreq, *treq) + transportHeadersToRequest(&tt.treq, headers) + assert.Equal(t, tt.expectedTreq, tt.treq) assert.Equal(t, transport.HeadersFromMap(tt.expectedHeaders), headers) }) } diff --git a/transport/tchannel/outbound.go b/transport/tchannel/outbound.go index 790e6a63f..0da49c5d8 100644 --- a/transport/tchannel/outbound.go +++ b/transport/tchannel/outbound.go @@ -153,10 +153,10 @@ func callWithPeer(ctx context.Context, req *transport.Request, peer *tchannel.Pe req.Procedure, &callOptions, ) - if err != nil { return nil, err } + reqHeaders := getHeaderMap(req.Headers, headerCase) reqHeaders = requestToTransportHeaders(req, reqHeaders)