Skip to content

fix(http): name a redirected download after the URL that answered - #620

Merged
linroid merged 2 commits into
mainfrom
fix/http-name-after-redirect
Oct 23, 2026
Merged

linroid merged 2 commits into
mainfrom
fix/http-name-after-redirect

Conversation

@linroid

@linroid linroid commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Found while downloading real links with the CLI. Mozilla's official Firefox link

https://download.mozilla.org/?product=firefox-latest-ssl&os=osx&lang=en-US
  302 -> https://download-installer.cdn.mozilla.net/pub/firefox/releases/158.0.1/mac/en-US/Firefox%20158.0.1.dmg

was saved as download, with no extension, because Ketch named files after the URL it was given. Mozilla sends no Content-Disposition. Browsers name such files after the URL that answered: Firefox 158.0.1.dmg. Links that redirect to the real file are everywhere (…/download?id=5, file.php?id=3, "latest" links).

What changes

  • ServerInfo.url: the URL that answered, after the redirects the engine followed. KtorHttpEngine sets it for HEAD and the GET probe; engines that don't say leave it null.
  • Without Content-Disposition, which still wins, HttpDownloadSource.resolve names the file with DefaultFileNameResolver.fromUrls(requested, answered):
    1. the answering URL's name when it has an extension (download → Firefox 158.0.1.dmg, file.php → report.pdf);
    2. else the requested URL's name when it has one (asset.zip served from an opaque storage key such as objects/4f1d…?X-Amz-… keeps its name);
    3. else whichever there is.

Verification

  • ketch from this branch: the Firefox link is saved as Firefox 158.0.1.dmg (before: download). GitHub release assets (named by Content-Disposition), plain URLs and redirects that keep their name are unchanged.
  • New tests: DefaultFileNameResolverTest.fromUrls_* (redirect targets with and without extensions, script links, no answered URL), HttpDownloadSourceTest.resolve_redirectedLink_isNamedAfterTheAnsweringUrl, and KtorHttpEngineRedirectTest now checks ServerInfo.url after a redirect to another port.
  • ./gradlew :library:core:jvmTest --tests '*DefaultFileNameResolverTest*' --tests '*HttpDownloadSourceTest*' --tests '*ResolveUrlTest*' --tests '*ServerInfoTest*' :library:ktor:jvmTest passes.

A link that redirects to the file, such as Mozilla's
https://download.mozilla.org/?product=firefox-latest-ssl&os=osx, was saved
as "download", without an extension, as Ketch named files after the URL
it was given. Browsers name them after the URL that answered, here
"Firefox 158.0.1.dmg". ServerInfo now carries that URL, and without a
Content-Disposition the download is named after it when its name has an
extension, else after the requested URL when that one has one, so a link
like asset.zip served from an opaque storage key keeps its name.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T15:37:19.729587Z 9dd31ec PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 23, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9dd31ece81

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…irect

.mobileconfig and .safetensors are extensions too: drop the ten-character
limit, keeping extensions of letters and digits.
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 2 194 files  ± 0   2 222 suites  ±0   58m 9s ⏱️ + 1m 25s
15 288 tests +12  15 020 ✅ +12  268 💤 ±0  0 ❌ ±0 
18 641 runs  +12  18 373 ✅ +12  268 💤 ±0  0 ❌ ±0 

Results for commit 254a6b2. ± Comparison against base commit a3b60ac.

@linroid
linroid merged commit e6d2fe1 into main Oct 23, 2026
14 checks passed
@linroid
linroid deleted the fix/http-name-after-redirect branch October 23, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant