Skip to content

feat(http): Apply overrideUserAgent to requests #7906

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 12 commits into from
Mar 31, 2025
Merged

feat(http): Apply overrideUserAgent to requests #7906

merged 12 commits into from
Mar 31, 2025

Conversation

theproducer
Copy link
Contributor

@theproducer theproducer commented Mar 5, 2025

Take the Cap Config values of overrideUserAgent (or ios.overrideUserAgent | android.overrideUserAgent) and apply them to CapacitorHttp requests. Also handles User-Agent headers set from JavaScript on Android.

closes #7063

@theproducer theproducer changed the title feat(http): Apply overrideUserAgent to requests fix(http): Apply overrideUserAgent to requests Mar 6, 2025
@theproducer theproducer marked this pull request as ready for review March 6, 2025 19:46
@theproducer theproducer changed the title fix(http): Apply overrideUserAgent to requests feat!(http): Apply overrideUserAgent to requests Mar 14, 2025
@theproducer theproducer changed the title feat!(http): Apply overrideUserAgent to requests feat(http): Apply overrideUserAgent to requests Mar 14, 2025
Copy link
Member

@markemer markemer left a comment

Choose a reason for hiding this comment

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

Re-upping my approval here. That's a heck of an android bug, but looks like it works.

Copy link
Member

@jcesarmobile jcesarmobile left a comment

Choose a reason for hiding this comment

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

Added some minor comments

// https://issues.chromium.org/issues/40450316
// x-cap-user-agent contains the user agent set in JavaScript
String userAgentValue = headers.getString("x-cap-user-agent");
if (userAgentValue != null && !userAgentValue.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (userAgentValue != null && !userAgentValue.isEmpty()) {
if (userAgentValue != null) {

I noticed iOS allows empty strings, so we should also allow them for Android

@jcesarmobile jcesarmobile merged commit 52482c9 into main Mar 31, 2025
6 checks passed
@jcesarmobile jcesarmobile deleted the RDMR-554 branch March 31, 2025 12:18
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.

bug: CapacitorHTTP no longer passes user-agent header in fetch requests on Android
3 participants