From ae7d503bf7d7858f00af91a468f89c4e58e15b55 Mon Sep 17 00:00:00 2001 From: airium Date: Mon, 23 Mar 2026 14:48:05 +0800 Subject: [PATCH] fix(qbittorrent): handle non-200 response during login to prevent long startup waits --- pkg/qbittorrent/client.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/qbittorrent/client.go b/pkg/qbittorrent/client.go index 102b445df..cc8be8707 100644 --- a/pkg/qbittorrent/client.go +++ b/pkg/qbittorrent/client.go @@ -43,7 +43,7 @@ func New(webuiUrl string) (Client, error) { IdleConnTimeout: 30 * time.Second, DisableKeepAlives: false, // Enable connection reuse } - + var c = &client{ url: u, client: http.Client{ @@ -98,6 +98,13 @@ func (c *client) login() error { } defer resp.Body.Close() + // avoid long waiting time if being upgraded to websocket connections (e.g. 101 responses) + // as per API documentation, qBittorrent returns only 200 on successful login + // so we safely treat any non-200 response as a failure + if resp.StatusCode != http.StatusOK { + return errors.New("failed to login into qBittorrent webui with status code: " + resp.Status) + } + // check result body := make([]byte, 2) _, err = resp.Body.Read(body)