Skip to content

Commit

Permalink
fix: http download timeout (GopeedLab#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie authored Aug 25, 2023
1 parent e1684e7 commit b6d60f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 4 additions & 5 deletions internal/protocol/http/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"os"
"path"
"strconv"
"time"
)

type RequestError struct {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/download/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b6d60f6

Please sign in to comment.