Skip to content

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

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

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

Conversation

@wuzhengu
Copy link
Copy Markdown

@wuzhengu wuzhengu commented Apr 14, 2026

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

@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 14, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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 updates the webview_flutter_android and webview_flutter_platform_interface packages to include request headers in NavigationRequest and introduces an isDownloadRequest getter to identify attachment downloads. The Android implementation is updated to populate these headers during download events. Feedback suggests making the 'attachment' string comparison case-insensitive to comply with RFC 6266 and adjusting Dart formatting.

Comment on lines +1683 to +1685
if(!contentDisposition.startsWith('attachment')) {
contentDisposition = 'attachment; $contentDisposition'.trim();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The check for the attachment prefix should be case-insensitive, as HTTP header values are case-insensitive per RFC 6266. Also, there should be a space after the if keyword to follow standard Dart styling.

Suggested change
if(!contentDisposition.startsWith('attachment')) {
contentDisposition = 'attachment; $contentDisposition'.trim();
}
if (!contentDisposition.toLowerCase().startsWith('attachment')) {
contentDisposition = 'attachment; $contentDisposition'.trim();
}

final Map<String, String>? headers;

/// Indicates whether the request was made to download an attachment.
bool get isDownloadRequest => headers?['content-disposition']?.startsWith('attachment') ?? false;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The isDownloadRequest getter should perform a case-insensitive check for the attachment disposition type to comply with RFC 6266.

Suggested change
bool get isDownloadRequest => headers?['content-disposition']?.startsWith('attachment') ?? false;
bool get isDownloadRequest => headers?['content-disposition']?.toLowerCase().startsWith('attachment') ?? false;

@wuzhengu wuzhengu marked this pull request as draft April 14, 2026 11:07
@wuzhengu wuzhengu closed this Apr 14, 2026
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.

1 participant