Skip to content

Commit bfda719

Browse files
authored
fix(qbittorrent): handle non-200 response during login to prevent long startup waits (#2248)
1 parent 7e37c40 commit bfda719

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

pkg/qbittorrent/client.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func New(webuiUrl string) (Client, error) {
4343
IdleConnTimeout: 30 * time.Second,
4444
DisableKeepAlives: false, // Enable connection reuse
4545
}
46-
46+
4747
var c = &client{
4848
url: u,
4949
client: http.Client{
@@ -98,6 +98,13 @@ func (c *client) login() error {
9898
}
9999
defer resp.Body.Close()
100100

101+
// avoid long waiting time if being upgraded to websocket connections (e.g. 101 responses)
102+
// as per API documentation, qBittorrent returns only 200 on successful login
103+
// so we safely treat any non-200 response as a failure
104+
if resp.StatusCode != http.StatusOK {
105+
return errors.New("failed to login into qBittorrent webui with status code: " + resp.Status)
106+
}
107+
101108
// check result
102109
body := make([]byte, 2)
103110
_, err = resp.Body.Read(body)

0 commit comments

Comments
 (0)