Skip to content

Commit b406c9f

Browse files
committed
docs: improve code documentation and comments for better clarity
- Update comments to provide more detailed explanations for `convertHeaders` function - Enhance documentation for `defaultHeaderTransport` struct - Improve comments for `RoundTrip` method to clarify its functionality Signed-off-by: appleboy <[email protected]>
1 parent fa7f5b7 commit b406c9f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

proxy/proxy.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
"golang.org/x/net/proxy"
1111
)
1212

13-
// convertHeaders creates a new http.Header from the given slice of headers.
13+
// convertHeaders takes a slice of strings representing HTTP headers in the format "key=value"
14+
// and converts them into an http.Header type. If a header string does not contain exactly one "=",
15+
// it is ignored. The resulting http.Header map is returned.
1416
func convertHeaders(headers []string) http.Header {
1517
h := make(http.Header)
1618
for _, header := range headers {
@@ -24,13 +26,19 @@ func convertHeaders(headers []string) http.Header {
2426
return h
2527
}
2628

27-
// DefaultHeaderTransport is an http.RoundTripper that adds the given headers to
29+
// defaultHeaderTransport is a custom implementation of http.RoundTripper
30+
// that allows setting default headers for each request. It wraps an existing
31+
// http.RoundTripper (origin) and adds the specified headers (header) to each
32+
// outgoing request.
2833
type defaultHeaderTransport struct {
2934
origin http.RoundTripper
3035
header http.Header
3136
}
3237

33-
// RoundTrip implements the http.RoundTripper interface.
38+
// RoundTrip executes a single HTTP transaction and returns
39+
// a Response for the provided Request. It adds custom headers
40+
// from the defaultHeaderTransport to the request before
41+
// delegating the actual round-trip to the original transport.
3442
func (t *defaultHeaderTransport) RoundTrip(req *http.Request) (*http.Response, error) {
3543
for key, values := range t.header {
3644
for _, value := range values {

0 commit comments

Comments
 (0)