-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
refactor: fethcer interface & download flow #1229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Applied commit 6756d82: Changed url.QueryUnescape to url.PathUnescape for handling %2B correctly - Applied commit abd16d5: Added HTML entity decoding for filenames (handling & etc.) - Resolved conflicts in fetcher.go by keeping refactored architecture - Changes applied to internal/protocol/http/helper.go as functions moved during refactoring
- 添加 unescapeHTMLEntities 函数: 解码 & < 等 HTML 实体 - 添加 findParamValueEnd 函数: 正确处理带引号和 HTML 实体的参数值 - 添加 isValidHTMLEntityChars 函数: 验证 HTML 实体字符 - 更新 parseFilenameExtended: 使用 url.PathUnescape 替代 QueryUnescape 以正确处理 %2B - 更新 parseFilenameFallback: 使用 findParamValueEnd 正确分割参数 - 更新 decodeFilenameParam: 先解码 HTML 实体,再使用 PathUnescape 这些改进确保文件名中的特殊字符(如 &, +)能被正确解析
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1229 +/- ##
==========================================
+ Coverage 70.11% 71.74% +1.62%
==========================================
Files 48 47 -1
Lines 5147 5712 +565
==========================================
+ Hits 3609 4098 +489
- Misses 1177 1222 +45
- Partials 361 392 +31 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This was referenced Jan 8, 2026
Closed
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fetcher Refactor: Download Flow & Slow-Start Connections
Motivation
The previous
Fetcherinterface design had a critical limitation: theResolvemethod did not acceptOptionsas a parameter, making it impossible to determine the download directory during the resolve phase. This architectural constraint created several maintenance challenges:No connection reuse: HTTP fetchers couldn't reuse the initial resolve request's response body for actual downloading. Unlike modern browsers that start downloading immediately upon resolving metadata, Gopeed had to open a new connection in the
Startphase, wasting the initial request.Directory determination mismatch: The download path could only be finalized after resolve completed, but the BT (BitTorrent) library required the storage path to be set during torrent spec creation. This forced us to maintain hacky workarounds to change the directory post-resolve.
Inefficient resource utilization: The resolve connection was discarded entirely, even for single-file downloads where that connection could have downloaded the complete file.
By moving
Optionsinto theResolvesignature, we unify directory decision-making with resource acquisition, enabling immediate download initiation and eliminating the need for library patches.Technical Changes
1. Resolve & Start Pipeline Redesign
HTTP Fetcher:
Resolvenow accepts bothRequestandOptionsparameters, allowing immediate directory determinationStartcan be called before resolve completes; internally it waits for resolve to finish before launching additional connectionsBT Fetcher:
TorrentSpecstorage configuration since download path is known at resolve time2. Slow-Start Connection Expansion
Replaced fixed upfront connection spawning with gradual slow-start expansion:
maxConnections3. Dynamic Chunk Allocation & Helper Logic
4. Intelligent Retry & Error Handling
Error Classification:
Enhanced Failure Reporting:
retryTimesper connection separately from failure count"connection 2 failed: retries=3, http code=403, msg=Forbidden"Benefits
Faster Downloads
Smoother Progress
Better Reliability
Server-Friendly