summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/matrix-org/gomatrix/client.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2021-04-03 19:16:46 +0200
committerGitHub <noreply@github.com>2021-04-03 19:16:46 +0200
commit21eb37e471c338a90f2e23c86106f7e49e2d1196 (patch)
treee7d1cfa89f31fcf0578edae7727f2230bba744a2 /vendor/github.com/matrix-org/gomatrix/client.go
parentd3b60cc445e5871971b543fde9483dba3924bf68 (diff)
downloadmatterbridge-msglm-21eb37e471c338a90f2e23c86106f7e49e2d1196.tar.gz
matterbridge-msglm-21eb37e471c338a90f2e23c86106f7e49e2d1196.tar.bz2
matterbridge-msglm-21eb37e471c338a90f2e23c86106f7e49e2d1196.zip
Update vendor (#1446)
* Update vendor * Use upstream emoji lib again
Diffstat (limited to 'vendor/github.com/matrix-org/gomatrix/client.go')
-rw-r--r--vendor/github.com/matrix-org/gomatrix/client.go23
1 files changed, 17 insertions, 6 deletions
diff --git a/vendor/github.com/matrix-org/gomatrix/client.go b/vendor/github.com/matrix-org/gomatrix/client.go
index fd77fce0..d0bb0c5e 100644
--- a/vendor/github.com/matrix-org/gomatrix/client.go
+++ b/vendor/github.com/matrix-org/gomatrix/client.go
@@ -53,13 +53,13 @@ func (e HTTPError) Error() string {
return fmt.Sprintf("contents=%v msg=%s code=%d wrapped=%s", e.Contents, e.Message, e.Code, wrappedErrMsg)
}
-// BuildURL builds a URL with the Client's homserver/prefix/access_token set already.
+// BuildURL builds a URL with the Client's homeserver/prefix set already.
func (cli *Client) BuildURL(urlPath ...string) string {
ps := append([]string{cli.Prefix}, urlPath...)
return cli.BuildBaseURL(ps...)
}
-// BuildBaseURL builds a URL with the Client's homeserver/access_token set already. You must
+// BuildBaseURL builds a URL with the Client's homeserver set already. You must
// supply the prefix in the path.
func (cli *Client) BuildBaseURL(urlPath ...string) string {
// copy the URL. Purposefully ignore error as the input is from a valid URL already
@@ -72,9 +72,6 @@ func (cli *Client) BuildBaseURL(urlPath ...string) string {
hsURL.Path = hsURL.Path + "/"
}
query := hsURL.Query()
- if cli.AccessToken != "" {
- query.Set("access_token", cli.AccessToken)
- }
if cli.AppServiceUserID != "" {
query.Set("user_id", cli.AppServiceUserID)
}
@@ -82,7 +79,7 @@ func (cli *Client) BuildBaseURL(urlPath ...string) string {
return hsURL.String()
}
-// BuildURLWithQuery builds a URL with query parameters in addition to the Client's homeserver/prefix/access_token set already.
+// BuildURLWithQuery builds a URL with query parameters in addition to the Client's homeserver/prefix set already.
func (cli *Client) BuildURLWithQuery(urlPath []string, urlQuery map[string]string) string {
u, _ := url.Parse(cli.BuildURL(urlPath...))
q := u.Query()
@@ -203,7 +200,13 @@ func (cli *Client) MakeRequest(method string, httpURL string, reqBody interface{
if err != nil {
return err
}
+
req.Header.Set("Content-Type", "application/json")
+
+ if cli.AccessToken != "" {
+ req.Header.Set("Authorization", "Bearer "+cli.AccessToken)
+ }
+
res, err := cli.Client.Do(req)
if res != nil {
defer res.Body.Close()
@@ -687,15 +690,21 @@ func (cli *Client) UploadToContentRepo(content io.Reader, contentType string, co
if err != nil {
return nil, err
}
+
req.Header.Set("Content-Type", contentType)
+ req.Header.Set("Authorization", "Bearer "+cli.AccessToken)
+
req.ContentLength = contentLength
+
res, err := cli.Client.Do(req)
if res != nil {
defer res.Body.Close()
}
+
if err != nil {
return nil, err
}
+
if res.StatusCode != 200 {
contents, err := ioutil.ReadAll(res.Body)
if err != nil {
@@ -710,10 +719,12 @@ func (cli *Client) UploadToContentRepo(content io.Reader, contentType string, co
Code: res.StatusCode,
}
}
+
var m RespMediaUpload
if err := json.NewDecoder(res.Body).Decode(&m); err != nil {
return nil, err
}
+
return &m, nil
}