mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-06 13:43:09 -06:00
Use gomatrixserverlib.Client for push notifications
This commit is contained in:
parent
01ba326d83
commit
236d7bd361
|
|
@ -3,31 +3,28 @@ package pushgateway
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/opentracing/opentracing-go"
|
"github.com/opentracing/opentracing-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
type httpClient struct {
|
type httpClient struct {
|
||||||
hc *http.Client
|
hc *gomatrixserverlib.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHTTPClient creates a new Push Gateway client.
|
// NewHTTPClient creates a new Push Gateway client.
|
||||||
func NewHTTPClient(disableTLSValidation bool) Client {
|
func NewHTTPClient(disableTLSValidation bool) Client {
|
||||||
hc := &http.Client{
|
return &httpClient{
|
||||||
Timeout: 30 * time.Second,
|
hc: gomatrixserverlib.NewClient(
|
||||||
Transport: &http.Transport{
|
gomatrixserverlib.WithTimeout(time.Second*30),
|
||||||
DisableKeepAlives: true,
|
gomatrixserverlib.WithKeepAlives(false),
|
||||||
TLSClientConfig: &tls.Config{
|
gomatrixserverlib.WithSkipVerify(disableTLSValidation),
|
||||||
InsecureSkipVerify: disableTLSValidation,
|
),
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
return &httpClient{hc: hc}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpClient) Notify(ctx context.Context, url string, req *NotifyRequest, resp *NotifyResponse) error {
|
func (h *httpClient) Notify(ctx context.Context, url string, req *NotifyRequest, resp *NotifyResponse) error {
|
||||||
|
|
@ -44,7 +41,7 @@ func (h *httpClient) Notify(ctx context.Context, url string, req *NotifyRequest,
|
||||||
}
|
}
|
||||||
hreq.Header.Set("Content-Type", "application/json")
|
hreq.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
hresp, err := h.hc.Do(hreq)
|
hresp, err := h.hc.DoHTTPRequest(ctx, hreq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue