Skip to content

Commit 513c7c2

Browse files
committed
fix: improve NewLoggedClient structure
Signed-off-by: Christian Stewart <christian@aperture.us>
1 parent 657ba84 commit 513c7c2

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

http/log/client.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,27 @@ func DoRequestWithTransport(le *logrus.Entry, transport http.RoundTripper, req *
3535
return DoRequestWithClient(le, &roundTripperClient{rt: transport}, req, verbose)
3636
}
3737

38-
// NewLoggedClient wraps an http.Client with a logger.
39-
func NewLoggedClient(client *http.Client, le *logrus.Entry, verbose bool) *http.Client {
40-
return &http.Client{
41-
Transport: NewLoggedRoundTripper(client.Transport, le, verbose),
42-
CheckRedirect: client.CheckRedirect,
43-
Jar: client.Jar,
44-
Timeout: client.Timeout,
38+
// loggedClient wraps http.Client to HttpClient with a logger.
39+
type loggedClient struct {
40+
client HttpClient
41+
le *logrus.Entry
42+
verbose bool
43+
}
44+
45+
// Do performs the request.
46+
func (l *loggedClient) Do(req *http.Request) (*http.Response, error) {
47+
return DoRequestWithClient(l.le, l.client, req, l.verbose)
48+
}
49+
50+
// _ is a type assertion
51+
var _ HttpClient = (*loggedClient)(nil)
52+
53+
// NewLoggedClient wraps an HttpClient with a logger.
54+
func NewLoggedClient(le *logrus.Entry, client HttpClient, verbose bool) HttpClient {
55+
return &loggedClient{
56+
client: client,
57+
le: le,
58+
verbose: verbose,
4559
}
4660
}
4761

0 commit comments

Comments
 (0)