Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow users to provide their custom httptrace.ClientTrace #1857

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading