Skip to content

Commit

Permalink
Export CloneRequest() function
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVitek committed Jun 6, 2024
1 parent 6c51581 commit e5a8218
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package transport

import "net/http"

// cloneRequest creates a shallow copy of a given request
// CloneRequest creates a shallow copy of a given request
// to comply with stdlib's http.RoundTripper contract:
//
// RoundTrip should not modify the request, except for
// consuming and closing the Request's Body. RoundTrip may
// read fields of the request in a separate goroutine. Callers
// should not mutate or reuse the request until the Response's
// Body has been closed.
func cloneRequest(orig *http.Request) *http.Request {
func CloneRequest(orig *http.Request) *http.Request {
clone := &http.Request{}
*clone = *orig

Expand Down
2 changes: 1 addition & 1 deletion logRequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func LogRequests(next http.RoundTripper) http.RoundTripper {
return RoundTripFunc(func(req *http.Request) (resp *http.Response, err error) {
r := cloneRequest(req)
r := CloneRequest(req)

curlCommand, _ := http2curl.GetCurlCommand(r)
log.Printf("%v", curlCommand)
Expand Down
2 changes: 1 addition & 1 deletion setHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
func SetHeader(header string, value string) func(http.RoundTripper) http.RoundTripper {
return func(next http.RoundTripper) http.RoundTripper {
return RoundTripFunc(func(req *http.Request) (resp *http.Response, err error) {
r := cloneRequest(req)
r := CloneRequest(req)

r.Header.Set(http.CanonicalHeaderKey(header), value)

Expand Down
2 changes: 1 addition & 1 deletion setHeaderFunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
func SetHeaderFunc(header string, fn func(req *http.Request) string) func(http.RoundTripper) http.RoundTripper {
return func(next http.RoundTripper) http.RoundTripper {
return RoundTripFunc(func(req *http.Request) (resp *http.Response, err error) {
r := cloneRequest(req)
r := CloneRequest(req)

r.Header.Set(http.CanonicalHeaderKey(header), fn(r))

Expand Down

0 comments on commit e5a8218

Please sign in to comment.