From 911c9a939078668b3c80b5888f0ea7dbf1d7c964 Mon Sep 17 00:00:00 2001 From: Michael Hoppal Date: Tue, 17 Sep 2019 13:48:55 -0600 Subject: [PATCH] Fix using http2 between TO and TM when setting proxy --- .../traffic_ops_golang/cachesstats/cachesstats.go | 10 +++++++++- traffic_ops/traffic_ops_golang/cdn/capacity.go | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go b/traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go index 969dbf41e0..42908fbf33 100644 --- a/traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go +++ b/traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go @@ -20,6 +20,7 @@ package cachesstats */ import ( + "crypto/tls" "database/sql" "encoding/json" "errors" @@ -66,7 +67,14 @@ func getCachesStats(tx *sql.Tx) ([]CacheData, error) { if err != nil { return nil, errors.New("monitor forward proxy '" + monitorForwardProxy + "' in parameter '" + MonitorProxyParameter + "' not a URI: " + err.Error()) } - client = &http.Client{Timeout: MonitorRequestTimeout, Transport: &http.Transport{Proxy: http.ProxyURL(proxyURI)}} + clientTransport := &http.Transport{Proxy: http.ProxyURL(proxyURI)} + if proxyURI.Scheme == "https" { + // TM does not support HTTP/2 and golang when connecting to https will use HTTP/2 by default causing a conflict + // The result will be an unsupported scheme error + // Setting TLSNextProto to any empty map will disable using HTTP/2 per https://golang.org/src/net/http/doc.go + clientTransport.TLSNextProto = make(map[string]func(authority string, c *tls.Conn) http.RoundTripper) + } + client = &http.Client{Timeout: MonitorRequestTimeout, Transport: clientTransport} } cacheData, err := getCacheData(tx) diff --git a/traffic_ops/traffic_ops_golang/cdn/capacity.go b/traffic_ops/traffic_ops_golang/cdn/capacity.go index a1f754ef0c..9272457f14 100644 --- a/traffic_ops/traffic_ops_golang/cdn/capacity.go +++ b/traffic_ops/traffic_ops_golang/cdn/capacity.go @@ -20,6 +20,7 @@ package cdn */ import ( + "crypto/tls" "database/sql" "encoding/json" "errors" @@ -105,7 +106,14 @@ func getMonitorsCapacity(tx *sql.Tx, monitors map[tc.CDNName][]string) (Capacity if err != nil { return CapacityResp{}, errors.New("monitor forward proxy '" + monitorForwardProxy + "' in parameter '" + MonitorProxyParameter + "' not a URI: " + err.Error()) } - client = &http.Client{Timeout: MonitorRequestTimeout, Transport: &http.Transport{Proxy: http.ProxyURL(proxyURI)}} + clientTransport := &http.Transport{Proxy: http.ProxyURL(proxyURI)} + if proxyURI.Scheme == "https" { + // TM does not support HTTP/2 and golang when connecting to https will use HTTP/2 by default causing a conflict + // The result will be an unsupported scheme error + // Setting TLSNextProto to any empty map will disable using HTTP/2 per https://golang.org/src/net/http/doc.go + clientTransport.TLSNextProto = make(map[string]func(authority string, c *tls.Conn) http.RoundTripper) + } + client = &http.Client{Timeout: MonitorRequestTimeout, Transport: clientTransport} } thresholds, err := getEdgeProfileHealthThresholdBandwidth(tx)