Skip to content

Commit

Permalink
Renamed headerCallerProcedureToRequest to transportHeadersToRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
biosvs committed May 7, 2024
1 parent 1d693b7 commit 08690c2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
4 changes: 1 addition & 3 deletions transport/tchannel/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions transport/tchannel/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions transport/tchannel/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
2 changes: 1 addition & 1 deletion transport/tchannel/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 08690c2

Please sign in to comment.