Skip to content

Commit

Permalink
allow users to provide their custom httptrace.ClientTrace (#1857)
Browse files Browse the repository at this point in the history
providing custom httptrace allows users to debug low
level details such as dial, dns and connection errors
more granularly.
  • Loading branch information
harshavardhana committed Jul 17, 2023
1 parent b75cfd4 commit afb31a8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* MinIO Go Library for Amazon S3 Compatible Cloud Storage
* Copyright 2015-2018 MinIO, Inc.
* Copyright 2015-2023 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,7 @@ import (
"net"
"net/http"
"net/http/cookiejar"
"net/http/httptrace"
"net/http/httputil"
"net/url"
"os"
Expand Down Expand Up @@ -69,6 +70,7 @@ type Client struct {

// Needs allocation.
httpClient *http.Client
httpTrace *httptrace.ClientTrace
bucketLocCache *bucketLocationCache

// Advanced functionality.
Expand Down Expand Up @@ -103,6 +105,7 @@ type Options struct {
Creds *credentials.Credentials
Secure bool
Transport http.RoundTripper
Trace *httptrace.ClientTrace
Region string
BucketLookup BucketLookupType

Expand Down Expand Up @@ -229,6 +232,8 @@ func privateNew(endpoint string, opts *Options) (*Client, error) {
}
}

clnt.httpTrace = opts.Trace

// Instantiate http client and bucket location cache.
clnt.httpClient = &http.Client{
Jar: jar,
Expand Down Expand Up @@ -771,6 +776,10 @@ func (c *Client) newRequest(ctx context.Context, method string, metadata request
return nil, err
}

if c.httpTrace != nil {
ctx = httptrace.WithClientTrace(ctx, c.httpTrace)
}

// Initialize a new HTTP request for the method.
req, err = http.NewRequestWithContext(ctx, method, targetURL.String(), nil)
if err != nil {
Expand Down

0 comments on commit afb31a8

Please sign in to comment.