Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 8 additions & 8 deletions pkg/app/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ func TestClientReadTimeout(t *testing.T) {
ReadTimeout: time.Second * 4,
MaxIdempotentCallAttempts: 1,
Dialer: standard.NewDialer(),
Addr: opt.Addr,
},
Addr: opt.Addr,
}

req := protocol.AcquireRequest()
Expand Down Expand Up @@ -689,9 +689,9 @@ func TestHostClientPendingRequests(t *testing.T) {

c := &http1.HostClient{
ClientOptions: &http1.ClientOptions{
Addr: "foobar",
Dialer: newMockDialerWithCustomFunc(opt.Network, opt.Addr, time.Second, nil),
},
Addr: "foobar",
}

pendingRequests := c.PendingRequests()
Expand Down Expand Up @@ -780,10 +780,10 @@ func TestHostClientMaxConnsWithDeadline(t *testing.T) {

c := &http1.HostClient{
ClientOptions: &http1.ClientOptions{
Addr: "foobar",
Dialer: newMockDialerWithCustomFunc(opt.Network, opt.Addr, time.Second, nil),
MaxConns: 1,
},
Addr: "foobar",
}

for i := 0; i < 5; i++ {
Expand Down Expand Up @@ -849,10 +849,10 @@ func TestHostClientMaxConnDuration(t *testing.T) {

c := &http1.HostClient{
ClientOptions: &http1.ClientOptions{
Addr: "foobar",
Dialer: newMockDialerWithCustomFunc(opt.Network, opt.Addr, time.Second, nil),
MaxConnDuration: 10 * time.Millisecond,
},
Addr: "foobar",
}

for i := 0; i < 5; i++ {
Expand Down Expand Up @@ -895,11 +895,11 @@ func TestHostClientMultipleAddrs(t *testing.T) {
dialsCount := make(map[string]int)
c := &http1.HostClient{
ClientOptions: &http1.ClientOptions{
Addr: "foo,bar,baz",
Dialer: newMockDialerWithCustomFunc(opt.Network, opt.Addr, 1*time.Second, func(network, addr string, timeout time.Duration, tlsConfig *tls.Config) {
dialsCount[addr]++
}),
},
Addr: "foo,bar,baz",
}

for i := 0; i < 9; i++ {
Expand Down Expand Up @@ -961,9 +961,9 @@ func TestClientFollowRedirects(t *testing.T) {

c := &http1.HostClient{
ClientOptions: &http1.ClientOptions{
Addr: "xxx",
Dialer: newMockDialerWithCustomFunc(opt.Network, opt.Addr, 1*time.Second, nil),
},
Addr: "xxx",
}

for i := 0; i < 10; i++ {
Expand Down Expand Up @@ -1055,11 +1055,11 @@ func TestHostClientMaxConnWaitTimeoutSuccess(t *testing.T) {

c := &http1.HostClient{
ClientOptions: &http1.ClientOptions{
Addr: "foobar",
Dialer: newMockDialerWithCustomFunc(opt.Network, opt.Addr, time.Second, nil),
MaxConns: 1,
MaxConnWaitTimeout: 200 * time.Millisecond,
},
Addr: "foobar",
}

for i := 0; i < 5; i++ {
Expand Down Expand Up @@ -1124,11 +1124,11 @@ func TestHostClientMaxConnWaitTimeoutError(t *testing.T) {

c := &http1.HostClient{
ClientOptions: &http1.ClientOptions{
Addr: "foobar",
Dialer: newMockDialerWithCustomFunc(opt.Network, opt.Addr, time.Second, nil),
MaxConns: 1,
MaxConnWaitTimeout: 10 * time.Millisecond,
},
Addr: "foobar",
}

var errNoFreeConnsCount uint32
Expand Down
29 changes: 0 additions & 29 deletions pkg/protocol/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ package client

import (
"context"
"crypto/tls"
"sync"
"time"

Expand Down Expand Up @@ -79,34 +78,6 @@ type Doer interface {
Do(ctx context.Context, req *protocol.Request, resp *protocol.Response) error
}

type HostClientConfig struct {
DynamicConfig

Name string

NoDefaultUserAgentHeader bool
DialDualStack bool
DisableHeaderNamesNormalizing bool
DisablePathNormalizing bool
IsTLS bool

TLSConfig *tls.Config

MaxConns int
MaxIdempotentCallAttempts int
MaxResponseBodySize int

RetryIf RetryIfFunc
ResponseBodyStream bool

DialTimeout time.Duration
MaxIdleConnDuration time.Duration
MaxConnDuration time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
MaxConnWaitTimeout time.Duration
}

// DynamicConfig is config set which will be confirmed when starts a request.
type DynamicConfig struct {
Addr string
Expand Down
28 changes: 13 additions & 15 deletions pkg/protocol/http1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ type HostClient struct {

*ClientOptions

// Comma-separated list of upstream HTTP server host addresses,
// which are passed to Dialer in a round-robin manner.
//
// Each address may contain port if default dialer is used.
// For example,
//
// - foobar.com:80
// - foobar.com:443
// - foobar.com:8080
Addr string
IsTLS bool
ProxyURI *protocol.URI

clientName atomic.Value
lastUseTime uint32

Expand Down Expand Up @@ -1044,17 +1057,6 @@ func NewHostClient(c *ClientOptions) client.HostClient {
}

type ClientOptions struct {
// Comma-separated list of upstream HTTP server host addresses,
// which are passed to Dialer in a round-robin manner.
//
// Each address may contain port if default dialer is used.
// For example,
//
// - foobar.com:80
// - foobar.com:443
// - foobar.com:8080
Addr string

// Client name. Used in User-Agent request header.
Name string

Expand Down Expand Up @@ -1086,8 +1088,6 @@ type ClientOptions struct {
// Optional TLS config.
TLSConfig *tls.Config

IsTLS bool

// Maximum number of connections which may be established to all hosts
// listed in Addr.
//
Expand Down Expand Up @@ -1168,6 +1168,4 @@ type ClientOptions struct {

// ResponseBodyStream enables response body streaming
ResponseBodyStream bool

ProxyURI *protocol.URI
}
2 changes: 1 addition & 1 deletion pkg/protocol/http1/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ func TestHostClientMaxConnWaitTimeoutWithEarlierDeadline(t *testing.T) {

c := &HostClient{
ClientOptions: &ClientOptions{
Addr: "foobar",
Dialer: newSlowConnDialer(func(network, addr string) (network.Conn, error) {
return mock.SlowReadDialer(addr)
}),
MaxConns: 1,
MaxConnWaitTimeout: 50 * time.Millisecond,
},
Addr: "foobar",
}

var errTimeoutCount uint32
Expand Down