Skip to content

[webview_flutter_android] Add headers to NavigationRequest to tell if it isDownloadRequest from onDownloadStart#11502

Draft
wuzhengu wants to merge 2 commits intoflutter:mainfrom
wuzhengu:main
Draft

[webview_flutter_android] Add headers to NavigationRequest to tell if it isDownloadRequest from onDownloadStart#11502
wuzhengu wants to merge 2 commits intoflutter:mainfrom
wuzhengu:main

Conversation

@wuzhengu
Copy link
Copy Markdown

Add headers and isDownloadRequest to NavigationRequest,so we can easily tell if it was made to download an attachment from onDownloadStart.

List which issues are fixed by this PR. You must list at least one issue.
132738

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a headers field to the NavigationRequest class and introduces an isDownloadRequest property derived from the content-disposition header. The Android implementation is updated to populate these headers during download events. Feedback indicates that deriving isDownloadRequest from headers creates a fragile dependency and that the logic prepending 'attachment; ' to the content-disposition header may result in invalid header values; it is recommended to use an explicit boolean field instead.

@stuartmorgan-g
Copy link
Copy Markdown
Collaborator

stuartmorgan-g commented Apr 14, 2026

The Gemini review is correct; this is not how we would implement this.

Also, per https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#platform-support, the first step here would be investigating whether there is a way to support this on iOS, as we prefer not to add platform-specific features when the behavior is something that would apply to other platforms.

If you would like to move forward with this, the next step would be to evaluate how this could work on iOS.

@stuartmorgan-g stuartmorgan-g marked this pull request as draft April 14, 2026 18:39
@wuzhengu
Copy link
Copy Markdown
Author

wuzhengu commented Apr 15, 2026

@stuartmorgan-g

Thanks for the feedback. I’d like to clarify a few key points about the implementation:

  • onDownloadStart behavior: In Android WebView, onDownloadStart is only triggered when the WebView itself has already determined that the request is a download. At that point, the Content-Disposition header is either set to attachment; filename=... or left empty. If the header were inline, the WebView would render the resource instead of calling onDownloadStart.
    → This means there is no risk of producing a malformed value like "attachment; inline; filename=...".

  • Scope of modification: The PR only touches requests that come through onDownloadStart. It does not alter normal navigation requests. This ensures the change is minimal and targeted exclusively at download scenarios.

  • Minimal change principle: By adding isDownloadRequest and exposing headers for these cases, developers gain a clear signal to distinguish downloads from navigations without having to parse headers themselves. This reduces complexity while keeping the API surface small.

  • Forward-looking value: Although the implementation may still need optimization, it lays the groundwork for future cross‑platform consistency. Rather than waiting until every platform confirms support, it makes sense to let Android users benefit now and then iterate toward broader alignment.

  • Issue context: The related issue has been open for a long time without much attention. This PR provides a concrete step forward, ensuring progress instead of leaving Android developers blocked indefinitely.

In short, the modification is safe because it applies only to download-triggered requests, where Content-Disposition is already attachment or empty. It achieves the intended functionality with the smallest possible change, while also providing a foundation for eventual cross‑platform unification.

@stuartmorgan-g
Copy link
Copy Markdown
Collaborator

This means there is no risk of producing a malformed value like "attachment; inline; filename=...".

I was referring to the other part of the Gemini review, about modifying headers to pass around magic strings.

This ensures the change is minimal and targeted exclusively at download scenarios.

This is not related to anything in my comment, so I'm not sure why you've included this section.

This reduces complexity while keeping the API surface small.

This is also not responsive to my comment.

Rather than waiting until every platform confirms support, it makes sense to let Android users benefit now and then iterate toward broader alignment.

You (and/or your AI agent) are certainly welcome to that opinion, but we have a documented policy on this for a reason. If you would like to move forward with this PR, just stating an opinion that our policy is wrong is not productive.

The related issue has been open for a long time without much attention.

Our bar for contribution does not change based on the age of the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants