From 1651c38b919944699bb8a705311c15b6ada8be11 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 6 Feb 2023 13:57:51 -0700 Subject: [PATCH] chore(transport): remove support for go runtimes earlier than 1.16 (#1844) --- transport/http/configure_http2_go116.go | 26 --------------------- transport/http/configure_http2_not_go116.go | 17 -------------- transport/http/dial.go | 14 +++++++++-- 3 files changed, 12 insertions(+), 45 deletions(-) delete mode 100644 transport/http/configure_http2_go116.go delete mode 100644 transport/http/configure_http2_not_go116.go diff --git a/transport/http/configure_http2_go116.go b/transport/http/configure_http2_go116.go deleted file mode 100644 index 305a6929c88..00000000000 --- a/transport/http/configure_http2_go116.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2021 Google LLC. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build go1.16 -// +build go1.16 - -package http - -import ( - "net/http" - "time" - - "golang.org/x/net/http2" -) - -// configureHTTP2 configures the ReadIdleTimeout HTTP/2 option for the -// transport. This allows broken idle connections to be pruned more quickly, -// preventing the client from attempting to re-use connections that will no -// longer work. -func configureHTTP2(trans *http.Transport) { - http2Trans, err := http2.ConfigureTransports(trans) - if err == nil { - http2Trans.ReadIdleTimeout = time.Second * 31 - } -} diff --git a/transport/http/configure_http2_not_go116.go b/transport/http/configure_http2_not_go116.go deleted file mode 100644 index d2742d283a6..00000000000 --- a/transport/http/configure_http2_not_go116.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2021 Google LLC. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build !go1.16 -// +build !go1.16 - -package http - -import ( - "net/http" -) - -// configureHTTP2 configures the ReadIdleTimeout HTTP/2 option for the -// transport. The interface to do this is only available in Go 1.16 and up, so -// this performs a no-op. -func configureHTTP2(trans *http.Transport) {} diff --git a/transport/http/dial.go b/transport/http/dial.go index cab709f0c05..47568a4061d 100644 --- a/transport/http/dial.go +++ b/transport/http/dial.go @@ -16,6 +16,7 @@ import ( "time" "go.opencensus.io/plugin/ochttp" + "golang.org/x/net/http2" "golang.org/x/oauth2" "google.golang.org/api/googleapi/transport" "google.golang.org/api/internal" @@ -175,13 +176,22 @@ func defaultBaseTransport(ctx context.Context, clientCertSource cert.Source) htt } } - // If possible, configure http2 transport in order to use ReadIdleTimeout - // setting. This can only be done in Go 1.16 and up. configureHTTP2(trans) return trans } +// configureHTTP2 configures the ReadIdleTimeout HTTP/2 option for the +// transport. This allows broken idle connections to be pruned more quickly, +// preventing the client from attempting to re-use connections that will no +// longer work. +func configureHTTP2(trans *http.Transport) { + http2Trans, err := http2.ConfigureTransports(trans) + if err == nil { + http2Trans.ReadIdleTimeout = time.Second * 31 + } +} + // fallbackBaseTransport is used in