gb vendor update github.com/matrix-org/gomatrixserverlib
parent
847621bc5d
commit
b7687310fe
|
@ -141,7 +141,7 @@
|
|||
{
|
||||
"importpath": "github.com/matrix-org/gomatrixserverlib",
|
||||
"repository": "https://github.com/matrix-org/gomatrixserverlib",
|
||||
"revision": "f3be4cb492f23eb30a9f2ab5fc5bd85ee9c3add6",
|
||||
"revision": "27d214da42f51906c2038ad3ddcffac9103c8e8f",
|
||||
"branch": "master"
|
||||
},
|
||||
{
|
||||
|
|
|
@ -26,6 +26,8 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
// A Client makes request to the federation listeners of matrix
|
||||
|
@ -120,7 +122,7 @@ func (fc *Client) LookupUserInfo(
|
|||
}
|
||||
|
||||
var response *http.Response
|
||||
response, err = fc.client.Do(req.WithContext(ctx))
|
||||
response, err = fc.doHTTPRequest(ctx, req)
|
||||
if response != nil {
|
||||
defer response.Body.Close() // nolint: errcheck
|
||||
}
|
||||
|
@ -197,7 +199,7 @@ func (fc *Client) LookupServerKeys( // nolint: gocyclo
|
|||
}
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
|
||||
response, err := fc.client.Do(req.WithContext(ctx))
|
||||
response, err := fc.doHTTPRequest(ctx, req)
|
||||
if response != nil {
|
||||
defer response.Body.Close() // nolint: errcheck
|
||||
}
|
||||
|
@ -244,10 +246,23 @@ func (fc *Client) CreateMediaDownloadRequest(
|
|||
if err != nil {
|
||||
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))
|
||||
if err != nil {
|
||||
logger.Infof("Outgoing request %s %s failed with %v", req.Method, req.URL, 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
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"net/url"
|
||||
|
||||
"github.com/matrix-org/gomatrix"
|
||||
"github.com/matrix-org/util"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
)
|
||||
|
||||
|
@ -33,6 +34,9 @@ func NewFederationClient(
|
|||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
@ -42,16 +46,21 @@ func (ac *FederationClient) doRequest(ctx context.Context, r FederationRequest,
|
|||
return err
|
||||
}
|
||||
|
||||
logger.Infof("Outgoing request %s %s", req.Method, req.URL)
|
||||
res, err := ac.client.Do(req.WithContext(ctx))
|
||||
if res != nil {
|
||||
defer res.Body.Close() // nolint: errcheck
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
logger.Infof("Outgoing request %s %s failed with %v", req.Method, req.URL, err)
|
||||
return err
|
||||
}
|
||||
|
||||
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
|
||||
// Adapted from https://github.com/matrix-org/gomatrix/blob/master/client.go
|
||||
var wrap error
|
||||
|
|
Loading…
Reference in New Issue