Repository navigation
Conversation
CloudFront only replaces the viewer's `User-Agent` with `Amazon CloudFront` when the header is not part of the cache/origin request policy. When it is forwarded (e.g. with an `AllViewer` policy), the module ignored the `CloudFront-Is-*-Viewer` headers and fell back to user-agent parsing. Detect the CloudFront device headers by presence instead, so detection works regardless of the user agent. The headers are still prioritized over user-agent parsing and the existing mobile/tablet/desktop precedence is preserved. Closes nuxt-modules#141
…er-detection # Conflicts: # test/basic.test.ts
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
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.
Description
Closes #141.
CloudFront's device detection headers (
CloudFront-Is-*-Viewer) were only honored when the incomingUser-Agentwas exactlyAmazon CloudFront:Per the AWS docs, CloudFront only replaces the viewer's
User-AgentwithAmazon CloudFrontwhen the header is not part of the cache/origin request policy. WhenUser-Agentis forwarded (e.g. with anAllViewerpolicy), the origin sees the real browser user agent, the check fails, and the module silently ignores the CloudFront device headers in favor of user-agent parsing.This change detects the CloudFront device headers by presence instead of keying off the user agent, so detection is configuration-independent. The headers still take precedence over user-agent parsing, and the existing mobile/tablet/desktop precedence is preserved.
Changes
src/runtime/generateFlags.ts: detect CloudFront via the presence of anyCloudFront-Is-*-Viewerheader rather than theUser-Agent.test/basic.test.ts: exercise the CloudFront headers with a real browser user agent (desktop UA for mobile/tablet/ios/android, iPhone UA for desktop) so the header precedence is actually covered, plus keep a case for the replacedAmazon CloudFrontUA and a negative case with no headers.README.md: clarify that detection no longer requires theAmazon CloudFrontuser agent, and that platform/browser flags are unavailable only when CloudFront replaces the user agent.Backward compatibility
Both configurations are covered:
User-Agent: Amazon CloudFront+ device headers (Unchanged)User-Agent+ device headers (Now detected)Verification