diff --git a/internal/protocol/http/fetcher.go b/internal/protocol/http/fetcher.go index 82e65aa7..1d3def5a 100644 --- a/internal/protocol/http/fetcher.go +++ b/internal/protocol/http/fetcher.go @@ -162,9 +162,6 @@ func (f *Fetcher) Resolve(req *base.Request) error { func (f *Fetcher) Create(opts *base.Options) error { f.meta.Opts = opts - if err := base.ParseReqExtra[fhttp.ReqExtra](f.meta.Req); err != nil { - return err - } if err := base.ParseOptsExtra[fhttp.OptsExtra](f.meta.Opts); err != nil { return err } @@ -198,6 +195,12 @@ func (f *Fetcher) Start() (err error) { if err != nil { return err } + + // Avoid request extra modified by extension + if err = base.ParseReqExtra[fhttp.ReqExtra](f.meta.Req); err != nil { + return err + } + if f.chunks == nil { f.chunks = f.splitChunk() } diff --git a/pkg/download/extension.go b/pkg/download/extension.go index 5a64920f..ced73f2a 100644 --- a/pkg/download/extension.go +++ b/pkg/download/extension.go @@ -703,31 +703,37 @@ type OnDoneContext struct { } type ExtensionTask struct { - *Task - download *Downloader + task *Task + + Meta *ExtensionTaskMeta `json:"meta"` +} + +// ExtensionTaskMeta restricts extension scripts to only modify request info +type ExtensionTaskMeta struct { + Req *base.Request `json:"req"` } func NewExtensionTask(download *Downloader, task *Task) *ExtensionTask { newTask := task.clone() - // Assign the pointer of the properties that the extension supports modification - newTask.Meta = task.Meta - newTask.Status = task.Status return &ExtensionTask{ - Task: newTask, + task: newTask, download: download, + Meta: &ExtensionTaskMeta{ + Req: task.Meta.Req, + }, } } func (t *ExtensionTask) Continue() error { return t.download.Continue(&TaskFilter{ - IDs: []string{t.ID}, + IDs: []string{t.task.ID}, }) } func (t *ExtensionTask) Pause() error { return t.download.Pause(&TaskFilter{ - IDs: []string{t.ID}, + IDs: []string{t.task.ID}, }) }