From b7687310fe00d7f3644e872dbb71caf72e21e140 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 29 Sep 2017 15:14:17 +0100 Subject: [PATCH] gb vendor update github.com/matrix-org/gomatrixserverlib --- vendor/manifest | 2 +- .../matrix-org/gomatrixserverlib/client.go | 19 +++++++++++++++++-- .../gomatrixserverlib/federationclient.go | 9 +++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/vendor/manifest b/vendor/manifest index d20b4fa9..28432d0e 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -141,7 +141,7 @@ { "importpath": "github.com/matrix-org/gomatrixserverlib", "repository": "https://github.com/matrix-org/gomatrixserverlib", - "revision": "f3be4cb492f23eb30a9f2ab5fc5bd85ee9c3add6", + "revision": "27d214da42f51906c2038ad3ddcffac9103c8e8f", "branch": "master" }, { diff --git a/vendor/src/github.com/matrix-org/gomatrixserverlib/client.go b/vendor/src/github.com/matrix-org/gomatrixserverlib/client.go index 87cc4753..2b9e5a8b 100644 --- a/vendor/src/github.com/matrix-org/gomatrixserverlib/client.go +++ b/vendor/src/github.com/matrix-org/gomatrixserverlib/client.go @@ -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 } diff --git a/vendor/src/github.com/matrix-org/gomatrixserverlib/federationclient.go b/vendor/src/github.com/matrix-org/gomatrixserverlib/federationclient.go index 7a5d1bf9..8732a3a2 100644 --- a/vendor/src/github.com/matrix-org/gomatrixserverlib/federationclient.go +++ b/vendor/src/github.com/matrix-org/gomatrixserverlib/federationclient.go @@ -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