Check if host works first before assigning random host

This commit is contained in:
Ben Sarmiento
2024-01-27 00:27:28 +01:00
parent 49b524ada6
commit 4bb0234d8f
4 changed files with 32 additions and 36 deletions

View File

@@ -308,7 +308,7 @@ func (rd *RealDebrid) UnrestrictLink(link string, checkFirstByte bool) (*Downloa
return nil, fmt.Errorf("undecodable response: %v", err)
}
if checkFirstByte && !rd.CanFetchFirstByte(response.Download) {
if checkFirstByte && !rd.client.CanFetchFirstByte(response.Download) {
return nil, fmt.Errorf("can't fetch first byte")
}

View File

@@ -1,30 +0,0 @@
package realdebrid
import (
"net/http"
)
func (rd *RealDebrid) CanFetchFirstByte(url string) bool {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return false
}
req.Header.Set("Range", "bytes=0-0")
resp, err := rd.client.Do(req)
if err != nil {
return false
}
defer resp.Body.Close()
// If server supports partial content
if resp.StatusCode/100 == 2 {
buffer := make([]byte, 1)
_, err = resp.Body.Read(buffer)
if err == nil {
return true
}
}
return false
}