From 2b2b83ca26870e4dbdb0c37e7a42c30b18a3fc6c Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 17 Jul 2023 00:38:54 -0700 Subject: [PATCH] allow users to provide their custom httptrace.ClientTrace providing custom httptrace allows users to debug low level details such as dial, dns and connection errors more granularly. --- api.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api.go b/api.go index 3462add85..6179b78c2 100644 --- a/api.go +++ b/api.go @@ -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. @@ -29,6 +29,7 @@ import ( "net" "net/http" "net/http/cookiejar" + "net/http/httptrace" "net/http/httputil" "net/url" "os" @@ -69,6 +70,7 @@ type Client struct { // Needs allocation. httpClient *http.Client + httpTrace *httptrace.ClientTrace bucketLocCache *bucketLocationCache // Advanced functionality. @@ -103,6 +105,7 @@ type Options struct { Creds *credentials.Credentials Secure bool Transport http.RoundTripper + Trace *httptrace.ClientTrace Region string BucketLookup BucketLookupType @@ -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, @@ -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 {