Skip to content

Commit

Permalink
refs #33: for public test version;
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanfinn committed Apr 18, 2023
1 parent 406c2cd commit e7f07b8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type TransportOptions struct {
MaxResponseHeaderBytes int64 // Zero means to use a default limit.
WriteBufferSize int // If zero, a default (currently 4KB) is used.
ReadBufferSize int // If zero, a default (currently 4KB) is used.
// IdleConnTimeout is the maximum amount of time an idle (keep-alive)
// connection will remain idle before closing itself. Zero means no limit.
IdleConnTimeout time.Duration
}

type BadPinHandlerFunc func(req *http.Request)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/bogdanfinn/tls-client
go 1.18

require (
github.com/bogdanfinn/fhttp v0.5.20
github.com/bogdanfinn/fhttp v0.5.21-public-test
github.com/bogdanfinn/utls v1.5.16
github.com/google/uuid v1.3.0
github.com/stretchr/testify v1.8.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/bogdanfinn/fhttp v0.5.20 h1:joQrA0tVFBQNQ8BbKRmIM972GfawXA+qbCRQlX6dauQ=
github.com/bogdanfinn/fhttp v0.5.20/go.mod h1:brqi5woc5eSCVHdKYBV8aZLbO7HGqpwyDLeXW+fT18I=
github.com/bogdanfinn/fhttp v0.5.21-public-test h1:3/NtlIawWB+9zaekAF8ZVcLd9jFqiQi8g07ycUiKo0s=
github.com/bogdanfinn/fhttp v0.5.21-public-test/go.mod h1:brqi5woc5eSCVHdKYBV8aZLbO7HGqpwyDLeXW+fT18I=
github.com/bogdanfinn/utls v1.5.16 h1:NhhWkegEcYETBMj9nvgO4lwvc6NcLH+znrXzO3gnw4M=
github.com/bogdanfinn/utls v1.5.16/go.mod h1:mHeRCi69cUiEyVBkKONB1cAbLjRcZnlJbGzttmiuK4o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
17 changes: 16 additions & 1 deletion roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"strings"
"sync"
"time"

http "github.com/bogdanfinn/fhttp"
"github.com/bogdanfinn/fhttp/http2"
Expand Down Expand Up @@ -141,7 +142,19 @@ func (rt *roundTripper) dialTLS(ctx context.Context, network, addr string) (net.
utlsConfig.ServerName = rt.serverNameOverwrite
}

t2 := http2.Transport{DialTLS: rt.dialTLSHTTP2, TLSClientConfig: utlsConfig, ConnectionFlow: rt.connectionFlow, HeaderPriority: rt.headerPriority}
idleConnectionTimeout := 90 * time.Second

if rt.transportOptions != nil {
idleConnectionTimeout = rt.transportOptions.IdleConnTimeout

This comment has been minimized.

Copy link
@jsnjack

jsnjack Apr 19, 2023

Contributor

Just a note:

If a user uses the following set of TransportOptions:

	transportOptions := &tls_client.TransportOptions{
		DisableCompression: true,
	}

IdleConnTimeout will be set to 0 and won't use the default value. One way to overcome it might be using a pointer:

type TransportOptions struct {
...
	IdleConnTimeout *time.Duration
}

In this case, if it is not set by the user, IdleConnTimeout will be nil and the default value can be used.

This comment has been minimized.

Copy link
@bogdanfinn

bogdanfinn Apr 19, 2023

Author Owner

@jsnjack you are totally right! was creating this testversion yesterday for another person and i knew he did not specify the TransportOptions at all ... for the official change we should make it a pointer.

}

t2 := http2.Transport{
DialTLS: rt.dialTLSHTTP2,
TLSClientConfig: utlsConfig,
ConnectionFlow: rt.connectionFlow,
HeaderPriority: rt.headerPriority,
IdleConnTimeout: idleConnectionTimeout,
}

if rt.transportOptions != nil {
t1 := t2.GetT1()
Expand All @@ -154,6 +167,7 @@ func (rt *roundTripper) dialTLS(ctx context.Context, network, addr string) (net.
t1.MaxResponseHeaderBytes = rt.transportOptions.MaxResponseHeaderBytes
t1.WriteBufferSize = rt.transportOptions.WriteBufferSize
t1.ReadBufferSize = rt.transportOptions.ReadBufferSize
t1.IdleConnTimeout = rt.transportOptions.IdleConnTimeout
}
}

Expand Down Expand Up @@ -221,6 +235,7 @@ func (rt *roundTripper) buildHttp1Transport() *http.Transport {
t.MaxResponseHeaderBytes = rt.transportOptions.MaxResponseHeaderBytes
t.WriteBufferSize = rt.transportOptions.WriteBufferSize
t.ReadBufferSize = rt.transportOptions.ReadBufferSize
t.IdleConnTimeout = rt.transportOptions.IdleConnTimeout
}

return t
Expand Down

0 comments on commit e7f07b8

Please sign in to comment.