mirror of
https://git.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-25 13:21:28 +00:00
Request compressed api
This commit is contained in:
parent
8995edec91
commit
9621a49db8
|
@ -5,6 +5,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"compress/gzip"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -144,6 +145,7 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in
|
||||||
}
|
}
|
||||||
req = req.WithContext(ctx)
|
req = req.WithContext(ctx)
|
||||||
req.Header.Set("Authorization", "Bearer "+c.config.AccessToken)
|
req.Header.Set("Authorization", "Bearer "+c.config.AccessToken)
|
||||||
|
req.Header.Set("accept-encoding", "gzip")
|
||||||
if params != nil {
|
if params != nil {
|
||||||
req.Header.Set("Content-Type", ct)
|
req.Header.Set("Content-Type", ct)
|
||||||
}
|
}
|
||||||
|
@ -167,7 +169,15 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in
|
||||||
*pg = *pg2
|
*pg = *pg2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return json.NewDecoder(resp.Body).Decode(&res)
|
var reader io.ReadCloser
|
||||||
|
switch resp.Header.Get("Content-Encoding") {
|
||||||
|
case "gzip":
|
||||||
|
reader, err = gzip.NewReader(resp.Body)
|
||||||
|
defer reader.Close()
|
||||||
|
default:
|
||||||
|
reader = resp.Body
|
||||||
|
}
|
||||||
|
return json.NewDecoder(reader).Decode(&res)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient return new mastodon API client.
|
// NewClient return new mastodon API client.
|
||||||
|
|
Loading…
Reference in a new issue