Skip to content
Merged
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
31 changes: 31 additions & 0 deletions crates/brumm/src/provider/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ impl Client {
rb = rb
.header("Content-Type", "application/json")
.body(serde_json::to_vec(&b)?);
} else if method == Method::POST {
// Library additions carry IDs in the query, but Apple still
// requires an explicit length for the empty POST body.
rb = rb.header(reqwest::header::CONTENT_LENGTH, 0);
}
let resp = rb.send().await?;
let status = resp.status();
Expand Down Expand Up @@ -801,6 +805,33 @@ mod tests {
assert!(parse_link("https://example.com/x").is_none());
}

#[tokio::test]
async fn add_to_library_sends_zero_content_length() {
let (base, seen) = serve(Arc::new(|s: &Seen| {
if s.headers.get("content-length").map(String::as_str) != Some("0") {
return (411, String::new());
}
(204, String::new())
}))
.await;
let client = Client::with_base(&base, "dev", "user");
for kind in ["songs", "albums", "playlists"] {
client
.add_to_library(kind, &["123".into(), "456".into()])
.await
.unwrap();
}
let seen = seen.lock().unwrap();
assert_eq!(seen.len(), 3);
for (s, kind) in seen.iter().zip(["songs", "albums", "playlists"]) {
assert_eq!(s.method, "POST");
let (path, query) = split(&s.target);
assert_eq!(path, "/v1/me/library");
assert_eq!(query[&format!("ids[{kind}]")], "123,456");
assert!(s.body.is_empty());
}
}

#[tokio::test]
async fn library_pagination_keeps_favorites_and_limit() {
let (base, seen) = serve(Arc::new(|s: &Seen| {
Expand Down
Loading