Skip to content

Commit afb31a8

Browse files
allow users to provide their custom httptrace.ClientTrace (#1857)
providing custom httptrace allows users to debug low level details such as dial, dns and connection errors more granularly.
1 parent b75cfd4 commit afb31a8

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

api.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
3-
* Copyright 2015-2018 MinIO, Inc.
3+
* Copyright 2015-2023 MinIO, Inc.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@ import (
2929
"net"
3030
"net/http"
3131
"net/http/cookiejar"
32+
"net/http/httptrace"
3233
"net/http/httputil"
3334
"net/url"
3435
"os"
@@ -69,6 +70,7 @@ type Client struct {
6970

7071
// Needs allocation.
7172
httpClient *http.Client
73+
httpTrace *httptrace.ClientTrace
7274
bucketLocCache *bucketLocationCache
7375

7476
// Advanced functionality.
@@ -103,6 +105,7 @@ type Options struct {
103105
Creds *credentials.Credentials
104106
Secure bool
105107
Transport http.RoundTripper
108+
Trace *httptrace.ClientTrace
106109
Region string
107110
BucketLookup BucketLookupType
108111

@@ -229,6 +232,8 @@ func privateNew(endpoint string, opts *Options) (*Client, error) {
229232
}
230233
}
231234

235+
clnt.httpTrace = opts.Trace
236+
232237
// Instantiate http client and bucket location cache.
233238
clnt.httpClient = &http.Client{
234239
Jar: jar,
@@ -771,6 +776,10 @@ func (c *Client) newRequest(ctx context.Context, method string, metadata request
771776
return nil, err
772777
}
773778

779+
if c.httpTrace != nil {
780+
ctx = httptrace.WithClientTrace(ctx, c.httpTrace)
781+
}
782+
774783
// Initialize a new HTTP request for the method.
775784
req, err = http.NewRequestWithContext(ctx, method, targetURL.String(), nil)
776785
if err != nil {

0 commit comments

Comments
 (0)