Skip to content

Commit

Permalink
fix(listenbrainz): set json header
Browse files Browse the repository at this point in the history
closes #216

related #216
related krateng/maloja#141
  • Loading branch information
sentriz committed May 2, 2022
1 parent f6687df commit e883de8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scrobble/listenbrainz/listenbrainz.go
Expand Up @@ -76,19 +76,22 @@ func (s *Scrobbler) Scrobble(user *db.User, track *db.Track, stamp time.Time, su
} else {
scrobble.ListenType = listenTypePlayingNow
}
payloadBuf := bytes.Buffer{}

var payloadBuf bytes.Buffer
if err := json.NewEncoder(&payloadBuf).Encode(scrobble); err != nil {
return err
}
submitURL := fmt.Sprintf("%s%s", user.ListenBrainzURL, submitPath)
authHeader := fmt.Sprintf("Token %s", user.ListenBrainzToken)
req, _ := http.NewRequest(http.MethodPost, submitURL, &payloadBuf)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", authHeader)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("http post: %w", err)
}
defer resp.Body.Close()

respBytes, _ := httputil.DumpResponse(resp, true)
switch {
case resp.StatusCode == http.StatusUnauthorized:
Expand Down

0 comments on commit e883de8

Please sign in to comment.