Skip to content

fix: support URL-encoded form data in qBittorrent add endpoint - #2

Merged
MrJoiny merged 2 commits into
MrJoiny:mainfrom
calmcacil:fix/multipart-content-type
Jul 20, 2026
Merged

fix: support URL-encoded form data in qBittorrent add endpoint#2
MrJoiny merged 2 commits into
MrJoiny:mainfrom
calmcacil:fix/multipart-content-type

Conversation

@calmcacil

@calmcacil calmcacil commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Sonarr/Radarr send application/x-www-form-urlencoded (not multipart/form-data) when adding magnet links via the qBittorrent API. The handler unconditionally calls r.ParseMultipartForm() which returns a 400 Bad Request when the Content-Type is URL-encoded.

Check Content-Type at the top of the handler and fall back to r.ParseForm() when the request is not multipart. The existing r.PostFormValue() calls and the if r.MultipartForm != nil guard for file uploads are compatible with both parsers.

Closes #1

Sonarr/Radarr send URL-encoded form data (not multipart) when adding magnet
links. Check Content-Type and fall back to ParseForm when the request is
not multipart, instead of unconditionally calling ParseMultipartForm.
@calmcacil

Copy link
Copy Markdown
Contributor Author

Tested on my local system with Sonarr sending magnet links. Both multipart (file uploads) and URL-encoded (magnet links) content types are handled correctly.

@MrJoiny

MrJoiny commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Looks good to me.
We could use mime.ParseMediaType from the std lib https://pkg.go.dev/mime#ParseMediaType to cover cases where the Multipart/Form-Data is uppercase. This would be unlikely to happen from Sonarr/Radarr.
What do you think about that? Otherwise I would just merge it and #4 after that.

… detection

Covers uppercase Multipart/Form-Data and extra params (e.g. boundary),
per upstream review feedback on PR MrJoiny#2.
@calmcacil

Copy link
Copy Markdown
Contributor Author

Sounds good — mime.ParseMediaType is the more robust way to read the header anyway, so I've applied it. I also rebased #4 onto the updated #2 branch so it doesn't accidentally revert the Content-Type change when both get merged.

@MrJoiny
MrJoiny merged commit 68f3433 into MrJoiny:main Jul 20, 2026
4 checks passed
@calmcacil
calmcacil deleted the fix/multipart-content-type branch July 20, 2026 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

POST /api/v2/torrents/add rejects application/x-www-form-urlencoded (breaks magnet links from *arr)

2 participants