mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-06 00:25:43 +00:00
fix: http download timeout (#188)
This commit is contained in:
2 files changed
+7
-6
No files matched your search
@@ -17,7 +17,6 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RequestError struct {
|
||||
@@ -85,13 +84,14 @@ func (f *Fetcher) Resolve(req *base.Request) error {
|
||||
return err
|
||||
}
|
||||
client := buildClient()
|
||||
// 只访问一个字节,测试资源是否支持Range请求
|
||||
// send Range request to check whether the server supports breakpoint continuation
|
||||
// just test one byte, Range: bytes=0-0
|
||||
httpReq.Header.Set(base.HttpHeaderRange, fmt.Sprintf(base.HttpHeaderRangeFormat, 0, 0))
|
||||
httpResp, err := client.Do(httpReq)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 拿到响应头就关闭,不用加defer
|
||||
// close response body immediately
|
||||
httpResp.Body.Close()
|
||||
res := &base.Resource{
|
||||
Range: false,
|
||||
@@ -395,8 +395,7 @@ func buildClient() *http.Client {
|
||||
// Cookie handle
|
||||
jar, _ := cookiejar.New(nil)
|
||||
return &http.Client{
|
||||
Jar: jar,
|
||||
Timeout: time.Second * 60,
|
||||
Jar: jar,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -528,7 +528,9 @@ func (d *Downloader) watch(task *Task) {
|
||||
d.emit(EventKeyDone, task)
|
||||
}
|
||||
d.emit(EventKeyFinally, task, err)
|
||||
d.notifyRunning()
|
||||
if task.Status == EventKeyDone {
|
||||
d.notifyRunning()
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Downloader) restoreFetcher(task *Task) error {
|
||||
|
||||
Reference in new issue
Block a user