diff options
| author | Randall Meyer <[email protected]> | 2023-02-15 14:17:00 -0800 |
|---|---|---|
| committer | Randall Meyer <[email protected]> | 2023-02-22 09:18:25 -0800 |
| commit | bfa2e2b0fa93b6059fba0581b52d6d60a53b5a4a (patch) | |
| tree | ff8a9707caf844be368106ee8000ce7c6e0b57db /utilities/transport.go | |
| parent | aba993ed378297f48ff6be18b17c6a963d3fd190 (diff) | |
new flag: --connect-to
Allows user to override DNS for the initial config request. This is
accomplished using a custom DialContext overring the hostname used to
Dial to. This allows for TLS certificate validation to still
happen(optionally) while connecting to TLS secured resources.
Also,
- allows for optional enforcement of certificate verification
- stamp built git version into binary and adds a --version option
- adds a user-agent to all outgoing request
- exit(1) on failures for easier shell error detection
Diffstat (limited to 'utilities/transport.go')
| -rw-r--r-- | utilities/transport.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/utilities/transport.go b/utilities/transport.go new file mode 100644 index 0000000..2d70989 --- /dev/null +++ b/utilities/transport.go @@ -0,0 +1,46 @@ +/* + * This file is part of Go Responsiveness. + * + * Go Responsiveness is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software Foundation, + * either version 2 of the License, or (at your option) any later version. + * Go Responsiveness is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with Go Responsiveness. If not, see <https://www.gnu.org/licenses/>. + */ + +package utilities + +import ( + "context" + "net" + "net/http" + "time" + + "golang.org/x/net/http2" +) + +func OverrideHostTransport(transport *http.Transport, connectToAddr string) { + dialer := &net.Dialer{ + Timeout: 10 * time.Second, + } + + transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { + _, port, err := net.SplitHostPort(addr) + if err != nil { + return nil, err + } + + if len(connectToAddr) > 0 { + addr = net.JoinHostPort(connectToAddr, port) + } + + return dialer.DialContext(ctx, network, addr) + } + + http2.ConfigureTransport(transport) + +} |
