mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-02 12:26:36 +08:00
fix: improve qbittorrent host connectivity
This commit is contained in:
@@ -107,7 +107,10 @@ func (q *QBitClient) Login(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
req.Header.Set("Referer", q.cfg.BaseURL)
|
||||
baseURL := strings.TrimRight(q.cfg.BaseURL, "/")
|
||||
req.Header.Set("Referer", baseURL)
|
||||
req.Header.Set("Origin", baseURL)
|
||||
req.Header.Set("User-Agent", "MediaStationGo/0.1")
|
||||
|
||||
resp, err := q.client.Do(req)
|
||||
if err != nil {
|
||||
@@ -115,8 +118,12 @@ func (q *QBitClient) Login(ctx context.Context) error {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
if resp.StatusCode >= 400 || strings.TrimSpace(string(body)) != "Ok." {
|
||||
return fmt.Errorf("qbittorrent login failed: %s", strings.TrimSpace(string(body)))
|
||||
text := strings.TrimSpace(string(body))
|
||||
if resp.StatusCode == http.StatusForbidden {
|
||||
return errors.New("qbittorrent login forbidden: check username/password, WebUI IP ban, CSRF/Host header validation, and allowed subnets")
|
||||
}
|
||||
if resp.StatusCode >= 400 || text != "Ok." {
|
||||
return fmt.Errorf("qbittorrent login failed: status=%d body=%s", resp.StatusCode, text)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -284,6 +284,8 @@ func (a *QBitAdapter) loginLocked(ctx context.Context) error {
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
req.Header.Set("Referer", baseURL)
|
||||
req.Header.Set("Origin", baseURL)
|
||||
req.Header.Set("User-Agent", "MediaStationGo/0.1")
|
||||
|
||||
resp, err := a.client.Do(req)
|
||||
if err != nil {
|
||||
@@ -291,8 +293,12 @@ func (a *QBitAdapter) loginLocked(ctx context.Context) error {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
if resp.StatusCode >= 400 || strings.TrimSpace(string(body)) != "Ok." {
|
||||
return fmt.Errorf("qbittorrent login failed: %s", strings.TrimSpace(string(body)))
|
||||
text := strings.TrimSpace(string(body))
|
||||
if resp.StatusCode == http.StatusForbidden {
|
||||
return fmt.Errorf("qbittorrent login forbidden: check username/password, WebUI IP ban, CSRF/Host header validation, and allowed subnets")
|
||||
}
|
||||
if resp.StatusCode >= 400 || text != "Ok." {
|
||||
return fmt.Errorf("qbittorrent login failed: status=%d body=%s", resp.StatusCode, text)
|
||||
}
|
||||
a.LoggedIn = true
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user