Skip to content

Commit

Permalink
google/internal/externalaccount: use request.clone()
Browse files Browse the repository at this point in the history
  • Loading branch information
jwijenbergh committed Apr 28, 2023
1 parent 79e9b85 commit 6cd210f
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions google/internal/externalaccount/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,6 @@ func getHmacSha256(key, input []byte) ([]byte, error) {
return hash.Sum(nil), nil
}

func cloneRequest(r *http.Request) *http.Request {
r2 := new(http.Request)
*r2 = *r
if r.Header != nil {
r2.Header = make(http.Header, len(r.Header))

// Find total number of values.
headerCount := 0
for _, headerValues := range r.Header {
headerCount += len(headerValues)
}
copiedHeaders := make([]string, headerCount) // shared backing array for headers' values

for headerKey, headerValues := range r.Header {
headerCount = copy(copiedHeaders, headerValues)
r2.Header[headerKey] = copiedHeaders[:headerCount:headerCount]
copiedHeaders = copiedHeaders[headerCount:]
}
}
return r2
}

func canonicalPath(req *http.Request) string {
result := req.URL.EscapedPath()
if result == "" {
Expand Down Expand Up @@ -192,7 +170,7 @@ func canonicalRequest(req *http.Request, canonicalHeaderColumns, canonicalHeader
// SignRequest adds the appropriate headers to an http.Request
// or returns an error if something prevented this.
func (rs *awsRequestSigner) SignRequest(req *http.Request) error {
signedRequest := cloneRequest(req)
signedRequest := req.Clone(req.Context())
timestamp := now()

signedRequest.Header.Add("host", requestHost(req))
Expand Down

0 comments on commit 6cd210f

Please sign in to comment.