mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-29 08:18:27 +00:00
gb vendor update github.com/matrix-org/gomatrixserverlib
This commit is contained in:
parent
847621bc5d
commit
b7687310fe
3 changed files with 27 additions and 3 deletions
2
vendor/manifest
vendored
2
vendor/manifest
vendored
|
@ -141,7 +141,7 @@
|
||||||
{
|
{
|
||||||
"importpath": "github.com/matrix-org/gomatrixserverlib",
|
"importpath": "github.com/matrix-org/gomatrixserverlib",
|
||||||
"repository": "https://github.com/matrix-org/gomatrixserverlib",
|
"repository": "https://github.com/matrix-org/gomatrixserverlib",
|
||||||
"revision": "f3be4cb492f23eb30a9f2ab5fc5bd85ee9c3add6",
|
"revision": "27d214da42f51906c2038ad3ddcffac9103c8e8f",
|
||||||
"branch": "master"
|
"branch": "master"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Client makes request to the federation listeners of matrix
|
// A Client makes request to the federation listeners of matrix
|
||||||
|
@ -120,7 +122,7 @@ func (fc *Client) LookupUserInfo(
|
||||||
}
|
}
|
||||||
|
|
||||||
var response *http.Response
|
var response *http.Response
|
||||||
response, err = fc.client.Do(req.WithContext(ctx))
|
response, err = fc.doHTTPRequest(ctx, req)
|
||||||
if response != nil {
|
if response != nil {
|
||||||
defer response.Body.Close() // nolint: errcheck
|
defer response.Body.Close() // nolint: errcheck
|
||||||
}
|
}
|
||||||
|
@ -197,7 +199,7 @@ func (fc *Client) LookupServerKeys( // nolint: gocyclo
|
||||||
}
|
}
|
||||||
req.Header.Add("Content-Type", "application/json")
|
req.Header.Add("Content-Type", "application/json")
|
||||||
|
|
||||||
response, err := fc.client.Do(req.WithContext(ctx))
|
response, err := fc.doHTTPRequest(ctx, req)
|
||||||
if response != nil {
|
if response != nil {
|
||||||
defer response.Body.Close() // nolint: errcheck
|
defer response.Body.Close() // nolint: errcheck
|
||||||
}
|
}
|
||||||
|
@ -244,10 +246,23 @@ func (fc *Client) CreateMediaDownloadRequest(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return fc.doHTTPRequest(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fc *Client) doHTTPRequest(ctx context.Context, req *http.Request) (*http.Response, error) {
|
||||||
|
reqID := util.RandomString(12)
|
||||||
|
logger := util.GetLogger(ctx).WithField("server", req.URL.Host).WithField("out.req.ID", reqID)
|
||||||
|
|
||||||
|
logger.Infof("Outgoing request %s %s", req.Method, req.URL)
|
||||||
resp, err := fc.client.Do(req.WithContext(ctx))
|
resp, err := fc.client.Do(req.WithContext(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Infof("Outgoing request %s %s failed with %v", req.Method, req.URL, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we haven't yet read the body, so this is slightly premature, but it's the easiest place.
|
||||||
|
logger.Infof("Response %d from %s %s", resp.StatusCode, req.Method, req.URL)
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
|
"github.com/matrix-org/util"
|
||||||
"golang.org/x/crypto/ed25519"
|
"golang.org/x/crypto/ed25519"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,6 +34,9 @@ func NewFederationClient(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ac *FederationClient) doRequest(ctx context.Context, r FederationRequest, resBody interface{}) error {
|
func (ac *FederationClient) doRequest(ctx context.Context, r FederationRequest, resBody interface{}) error {
|
||||||
|
reqID := util.RandomString(12)
|
||||||
|
logger := util.GetLogger(ctx).WithField("server", r.fields.Destination).WithField("out.req.ID", reqID)
|
||||||
|
|
||||||
if err := r.Sign(ac.serverName, ac.serverKeyID, ac.serverPrivateKey); err != nil {
|
if err := r.Sign(ac.serverName, ac.serverKeyID, ac.serverPrivateKey); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -42,16 +46,21 @@ func (ac *FederationClient) doRequest(ctx context.Context, r FederationRequest,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Infof("Outgoing request %s %s", req.Method, req.URL)
|
||||||
res, err := ac.client.Do(req.WithContext(ctx))
|
res, err := ac.client.Do(req.WithContext(ctx))
|
||||||
if res != nil {
|
if res != nil {
|
||||||
defer res.Body.Close() // nolint: errcheck
|
defer res.Body.Close() // nolint: errcheck
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Infof("Outgoing request %s %s failed with %v", req.Method, req.URL, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
contents, err := ioutil.ReadAll(res.Body)
|
contents, err := ioutil.ReadAll(res.Body)
|
||||||
|
|
||||||
|
logger.Infof("Response %d from %s %s", res.StatusCode, req.Method, req.URL)
|
||||||
|
|
||||||
if res.StatusCode/100 != 2 { // not 2xx
|
if res.StatusCode/100 != 2 { // not 2xx
|
||||||
// Adapted from https://github.com/matrix-org/gomatrix/blob/master/client.go
|
// Adapted from https://github.com/matrix-org/gomatrix/blob/master/client.go
|
||||||
var wrap error
|
var wrap error
|
||||||
|
|
Loading…
Reference in a new issue