Fix the ancient bug where client wasn't able to use non-https endpoints.

This commit is contained in:
2023-02-26 11:38:20 +00:00
parent 9e8df7e297
commit 42e1afbf77
2 changed files with 24 additions and 19 deletions
+22 -18
View File
@@ -15,7 +15,6 @@ package gql
import ( import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"net"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
@@ -83,25 +82,30 @@ func setCacheEnabled() bool {
} }
func NewConnection() *GraphQL { func NewConnection() *GraphQL {
g := GraphQL{
Endpoint: pickGraphqlEndpoint(), endpoint := pickGraphqlEndpoint()
HttpClient: &http.Client{ var httpClient *http.Client
Transport: &http2.Transport{ if strings.HasPrefix(endpoint, "http://") {
DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) { // HTTP/1.1 client
if strings.HasPrefix(network, "http") { httpClient = &http.Client{}
return net.Dial(network, addr) } else {
} // HTTP/2 or HTTPS client
return tls.Dial(network, addr, cfg) http2Transport := &http2.Transport{
},
ReadIdleTimeout: 30 * time.Second,
DisableCompression: false,
AllowHTTP: true, AllowHTTP: true,
PingTimeout: 5 * time.Second, }
TLSClientConfig: &tls.Config{ if strings.HasPrefix(endpoint, "https://") {
http2Transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true, InsecureSkipVerify: true,
}, }
}, }
}, httpClient = &http.Client{
Transport: http2Transport,
}
}
g := GraphQL{
Endpoint: endpoint,
HttpClient: httpClient,
Log: logging.NewLogger(), Log: logging.NewLogger(),
Cache: setCacheEnabled(), Cache: setCacheEnabled(),
CacheStore: setupCache(), CacheStore: setupCache(),
+1
View File
@@ -83,6 +83,7 @@ func (g *GraphQL) Query(queryContent string, queryVariables interface{}, queryHe
err = retry.Do( err = retry.Do(
func() error { func() error {
g.Log.Debug("Sending the query")
httpResponse, err = g.HttpClient.Do(httpRequest) httpResponse, err = g.HttpClient.Do(httpRequest)
if err != nil { if err != nil {