refactor(resolve): use Fetcher.Close for preview cancellation

This commit is contained in:
Levi committed 2026-11-15 11:38:27 +08:00
1 parent 8161042b93
commit 882f0cbc84
3 files changed
+4 -71

No files matched your search

-12
View File
@@ -418,16 +418,6 @@ func (f *Fetcher) updateMaxConnTime(d time.Duration) {
}
func (f *Fetcher) Resolve(req *base.Request) error {
return f.ResolveContext(context.Background(), req)
}
// ResolveContext cancels the initial request while waiting for headers. Once
// Resolve has returned, the retained response belongs to the fetcher and its
// existing Pause/Close lifecycle controls the body and prefetch.
func (f *Fetcher) ResolveContext(ctx context.Context, req *base.Request) error {
if err := ctx.Err(); err != nil {
return err
}
if err := base.ParseReqExtra[fhttp.ReqExtra](req); err != nil {
return err
}
@@ -439,8 +429,6 @@ func (f *Fetcher) ResolveContext(ctx context.Context, req *base.Request) error {
// This allows the response to be reused for downloading (important for one-time URLs)
// The body outlives Resolve, so the read timeout gets its own cancel func.
reqCtx, reqCancel := context.WithCancel(context.Background())
stopCancel := context.AfterFunc(ctx, reqCancel)
defer stopCancel()
httpReq, err := f.buildRequest(reqCtx, req)
if err != nil {
reqCancel()