Skip to content

Commit

Permalink
added clone map
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam-srivastava28 committed Jul 15, 2024
1 parent 3963a01 commit 9f7f8dd
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions runtime/yarpc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ import (
"context"
"fmt"
"io"
"maps"

"go.uber.org/yarpc/api/middleware"
"go.uber.org/yarpc/api/transport"
)

const _tracingKeyPrefix = "$tracing$"
const tracingKeyMappingSize = 100

// NewCaptureOutboundMiddleware captures outbound rpc calls
func NewCaptureOutboundMiddleware() middleware.UnaryOutbound {
return &captureOutboundMiddleware{}
Expand Down Expand Up @@ -70,7 +66,7 @@ func prepareRequest(request *transport.Request) (*GRPCOutgoingEvent, error) {
return nil, err
}
request.Body = io.NopCloser(bytes.NewReader(bodyBytes))
clonedHeaders := maps.Clone(request.Headers.OriginalItems())
clonedHeaders := cloneMap(request.Headers.OriginalItems())
return &GRPCOutgoingEvent{
ServiceName: request.Service,
MethodName: request.Procedure,
Expand All @@ -94,7 +90,15 @@ func prepareResponse(req *transport.Request, resp *transport.Response, event *GR
}
resp.Body = io.NopCloser(bytes.NewReader(responseBytes))
event.Rsp = responseBytes
event.RspHeaders = maps.Clone(resp.Headers.Items())
event.RspHeaders = cloneMap(resp.Headers.Items())
event.Success = !resp.ApplicationError
return nil
}

func cloneMap(src map[string]string) map[string]string {
clone := make(map[string]string)
for key, val := range src {
clone[key] = val
}
return clone
}

0 comments on commit 9f7f8dd

Please sign in to comment.