Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added eightctl-fixed
Binary file not shown.
17 changes: 14 additions & 3 deletions internal/client/eightsleep.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"bytes"
"compress/gzip"
"context"
"crypto/tls"
"encoding/json"
Expand Down Expand Up @@ -120,8 +121,8 @@ func (c *Client) authTokenEndpoint(ctx context.Context) error {
"grant_type": "password",
"username": c.Email,
"password": c.Password,
"client_id": "sleep-client",
"client_secret": "",
"client_id": c.ClientID,
"client_secret": c.ClientSecret,
}
body, _ := json.Marshal(payload)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, authURL, bytes.NewReader(body))
Expand Down Expand Up @@ -305,7 +306,17 @@ func (c *Client) do(ctx context.Context, method, path string, query url.Values,
return fmt.Errorf("api %s %s: %s", method, path, string(b))
}
if out != nil {
return json.NewDecoder(resp.Body).Decode(out)
// Handle gzip-compressed responses
var reader io.Reader = resp.Body
if resp.Header.Get("Content-Encoding") == "gzip" {
gzReader, err := gzip.NewReader(resp.Body)
if err != nil {
return fmt.Errorf("failed to create gzip reader: %w", err)
}
defer gzReader.Close()
reader = gzReader
}
return json.NewDecoder(reader).Decode(out)
}
return nil
}
Expand Down