Back out matrix-org/dendrite#2421 by restoring http.Clients

This creates problems with non-HTTPS endpoints and should fix #2444.
This commit is contained in:
Neil Alexander 2022-05-10 11:08:10 +01:00
parent 1b3fa9689c
commit 77722c5a4f
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
6 changed files with 44 additions and 33 deletions

View file

@ -3,28 +3,32 @@ package pushgateway
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
"time"
"github.com/matrix-org/gomatrixserverlib"
"github.com/opentracing/opentracing-go"
)
type httpClient struct {
hc *gomatrixserverlib.Client
hc *http.Client
}
// NewHTTPClient creates a new Push Gateway client.
func NewHTTPClient(disableTLSValidation bool) Client {
return &httpClient{
hc: gomatrixserverlib.NewClient(
gomatrixserverlib.WithTimeout(time.Second*30),
gomatrixserverlib.WithKeepAlives(false),
gomatrixserverlib.WithSkipVerify(disableTLSValidation),
),
hc := &http.Client{
Timeout: 30 * time.Second,
Transport: &http.Transport{
DisableKeepAlives: true,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: disableTLSValidation,
},
Proxy: http.ProxyFromEnvironment,
},
}
return &httpClient{hc: hc}
}
func (h *httpClient) Notify(ctx context.Context, url string, req *NotifyRequest, resp *NotifyResponse) error {
@ -41,7 +45,7 @@ func (h *httpClient) Notify(ctx context.Context, url string, req *NotifyRequest,
}
hreq.Header.Set("Content-Type", "application/json")
hresp, err := h.hc.DoHTTPRequest(ctx, hreq)
hresp, err := h.hc.Do(hreq)
if err != nil {
return err
}