Struct: http.BuildableClient

import "../ibm-cos-sdk-go-v2/aws/transport/http"

Overview

BuildableClient provides a HTTPClient implementation with options to create copies of the HTTPClient when additional configuration is provided.

The client’s methods will not share the http.Transport value between copies of the BuildableClient. Only exported member values of the Transport and optional Dialer will be copied between copies of BuildableClient.

Implemented Interfaces

types.AnalyticsFilter, aws.HTTPClient, s3.HTTPClient, kms.HTTPClient, v4.HTTPPresigner, s3.HTTPPresignerV4, types.MetricsFilter, s3.PresignPost, arn.S3ObjectLambdaARN, types.SelectObjectContentEventStream

Constructor Functions collapse

Method Summary collapse

Function Details

func NewBuildableClient() *BuildableClient

NewBuildableClient returns an initialized client for invoking HTTP requests.



54
55
56
// File 'aws/transport/http/client.go', line 54

func NewBuildableClient() *BuildableClient { return &BuildableClient{} }

Method Details

func (b *BuildableClient) Do(req *http.Request) (*http.Response, error)

Do implements the HTTPClient interface’s Do method to invoke a HTTP request, and receive the response. Uses the BuildableClient’s current configuration to invoke the http.Request.

If connection pooling is enabled (aka HTTP KeepAlive) the client will only share pooled connections with its own instance. Copies of the BuildableClient will have their own connection pools.

Redirect (3xx) responses will not be followed, the HTTP response received will returned instead.



68
69
70
71
72
// File 'aws/transport/http/client.go', line 68

func (b *BuildableClient) Do(req *http.Request) (*http.Response, error) { b.initOnce.Do(b.build) return b.client.Do(req) }

func (b *BuildableClient) Freeze() aws.HTTPClient

Freeze returns a frozen aws.HTTPClient implementation that is no longer a BuildableClient. Use this to prevent the SDK from applying DefaultMode configuration values to a buildable client.



76
77
78
79
80
// File 'aws/transport/http/client.go', line 76

func (b *BuildableClient) Freeze() aws.HTTPClient { cpy := b.clone() cpy.build() return cpy.client }

func (b *BuildableClient) GetDialer() *net.Dialer

GetDialer returns a copy of the client’s network dialer.



155
156
157
158
159
160
161
162
163
164
// File 'aws/transport/http/client.go', line 155

func (b *BuildableClient) GetDialer() *net.Dialer { var dialer *net.Dialer if b.dialer != nil { dialer = shallowCopyStruct(b.dialer).(*net.Dialer) } else { dialer = defaultDialer() } return dialer }

func (b *BuildableClient) GetTimeout() time.Duration

GetTimeout returns a copy of the client’s timeout to cancel requests with.



167
168
169
// File 'aws/transport/http/client.go', line 167

func (b *BuildableClient) GetTimeout() time.Duration { return b.clientTimeout }

func (b *BuildableClient) GetTransport() *http.Transport

GetTransport returns a copy of the client’s HTTP Transport.



143
144
145
146
147
148
149
150
151
152
// File 'aws/transport/http/client.go', line 143

func (b *BuildableClient) GetTransport() *http.Transport { var tr *http.Transport if b.transport != nil { tr = b.transport.Clone() } else { tr = defaultHTTPTransport() } return tr }

func (b *BuildableClient) WithDialerOptions(opts ...func(*net.Dialer)) *BuildableClient

WithDialerOptions copies the BuildableClient and returns it with the net.Dialer options applied. Will set the client’s http.Transport DialContext member.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// File 'aws/transport/http/client.go', line 119

func (b *BuildableClient) WithDialerOptions(opts ...func(*net.Dialer)) *BuildableClient { cpy := b.clone() dialer := cpy.GetDialer() for _, opt := range opts { opt(dialer) } cpy.dialer = dialer tr := cpy.GetTransport() tr.DialContext = cpy.dialer.DialContext cpy.transport = tr return cpy }

func (b *BuildableClient) WithTimeout(timeout time.Duration) *BuildableClient

WithTimeout Sets the timeout used by the client for all requests.



136
137
138
139
140
// File 'aws/transport/http/client.go', line 136

func (b *BuildableClient) WithTimeout(timeout time.Duration) *BuildableClient { cpy := b.clone() cpy.clientTimeout = timeout return cpy }

func (b *BuildableClient) WithTransportOptions(opts ...func(*http.Transport)) *BuildableClient

WithTransportOptions copies the BuildableClient and returns it with the http.Transport options applied.

If a non (*http.Transport) was set as the round tripper, the round tripper will be replaced with a default Transport value before invoking the option functions.



104
105
106
107
108
109
110
111
112
113
114
// File 'aws/transport/http/client.go', line 104

func (b *BuildableClient) WithTransportOptions(opts ...func(*http.Transport)) *BuildableClient { cpy := b.clone() tr := cpy.GetTransport() for _, opt := range opts { opt(tr) } cpy.transport = tr return cpy }