mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-25 06:09:22 +02:00
Request compressed api
This commit is contained in:
parent
8995edec91
commit
9621a49db8
|
@ -5,6 +5,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"compress/gzip"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -144,6 +145,7 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in
|
|||
}
|
||||
req = req.WithContext(ctx)
|
||||
req.Header.Set("Authorization", "Bearer "+c.config.AccessToken)
|
||||
req.Header.Set("accept-encoding", "gzip")
|
||||
if params != nil {
|
||||
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
|
||||
}
|
||||
}
|
||||
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.
|
||||
|
|
Loading…
Reference in New Issue