Skip to content

feat: warn about CORS preflight requests on Web#2556

Open
CaiJingLong wants to merge 1 commit into
mainfrom
feat/web-cors-preflight-warning
Open

feat: warn about CORS preflight requests on Web#2556
CaiJingLong wants to merge 1 commit into
mainfrom
feat/web-cors-preflight-warning

Conversation

@CaiJingLong

Copy link
Copy Markdown
Contributor

Summary

  • Detect when a request is not a CORS "simple request" and will trigger a preflight (OPTIONS) request on the Web platform, then emit a warningLog explaining why (non-safelisted method, custom headers, non-simple Content-Type, upload progress listener, or withCredentials).
  • Enrich the XMLHttpRequest.onError error message with CORS guidance when the request was preflighted, so users see a actionable hint instead of a generic network error.
  • Extract the pure detection logic into lib/src/cors.dart (corsPreflightReason) so it can be unit-tested on the VM without a browser.

Closes #2201.

Test plan

  • dart analyze — no issues
  • dart format — applied
  • dart test test/cors_preflight_test.dart -p vm — 15 tests pass
  • Browser CI (CORS preflight tests in dio_test) — existing corsTests still cover runtime behavior

Generated with Devin

Detect when a request is not a CORS "simple request" and will trigger a
preflight (OPTIONS) request, then emit a warning log and enrich the
XMLHttpRequest.onError message with CORS guidance.

Closes #2201

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Report: Only Changed Files listed

Package Base Coverage New Coverage Difference
plugins/web_adapter/lib/src/adapter_impl.dart 🔴 19.27% 🔴 22.41% 🟢 3.14%
plugins/web_adapter/lib/src/cors.dart 🔴 0% 🟢 100% 🟢 100%
Overall Coverage 🟢 85.55% 🟢 85.61% 🟢 0.06%

Minimum allowed coverage is 0%, this run produced 85.61%

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.

Prompt for not simple requests on Web

1 participant