Skip to content

Commit 81fe8d9

Browse files
committed
Refactor HeadersToString function to improve readability
1 parent b5e3a18 commit 81fe8d9

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

httpclient/httpclient_headers.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,6 @@ func NewHeaderManager(req *http.Request, log logger.Logger, apiHandler APIHandle
2727
}
2828
}
2929

30-
// HeadersToString converts a http.Header to a string for logging,
31-
// with each header on a new line for readability.
32-
func HeadersToString(headers http.Header) string {
33-
var headerStrings []string
34-
for name, values := range headers {
35-
// Join all values for the header with a comma, as per HTTP standard
36-
valueStr := strings.Join(values, ", ")
37-
headerStrings = append(headerStrings, fmt.Sprintf("%s: %s", name, valueStr))
38-
}
39-
return strings.Join(headerStrings, "\n") // "\n" as seperator.
40-
}
41-
4230
// SetAuthorization sets the Authorization header for the request.
4331
func (h *HeaderManager) SetAuthorization(token string) {
4432
// Ensure the token is prefixed with "Bearer " only once
@@ -144,6 +132,18 @@ func (h *HeaderManager) LogHeaders(client *Client) {
144132
}
145133
}
146134

135+
// HeadersToString converts a http.Header to a string for logging,
136+
// with each header on a new line for readability.
137+
func HeadersToString(headers http.Header) string {
138+
var headerStrings []string
139+
for name, values := range headers {
140+
// Join all values for the header with a comma, as per HTTP standard
141+
valueStr := strings.Join(values, ", ")
142+
headerStrings = append(headerStrings, fmt.Sprintf("%s: %s", name, valueStr))
143+
}
144+
return strings.Join(headerStrings, "\n") // "\n" as seperator.
145+
}
146+
147147
// CheckDeprecationHeader checks the response headers for the Deprecation header and logs a warning if present.
148148
func CheckDeprecationHeader(resp *http.Response, log logger.Logger) {
149149
deprecationHeader := resp.Header.Get("Deprecation")

0 commit comments

Comments
 (0)