-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce cases in which browsers would trigger a CORS preflight request (…
…cfug#1955) Certain requests are considered **["simple requests"](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests)** by the CORS spec - they do not require a preflight request. The old logic unconditionally registered `XMLHttpRequest.upload` progress event listener, which made it impossible for requests to be considered "simple". This mostly affected Firefox, because it correctly followed the spec. This PR adds more conditions around registering the handler, reducing dio's impact on CORS handling. Now, a request is NOT preflighted if: - It is a `HEAD` / `GET` / `POST` request - Its Content-Type is one of `text/plain`, `multipart/form-data`, `application/x-www-form-urlencoded` - It doesn't contain any headers which are not [safelisted](https://fetch.spec.whatwg.org/#cors-safelisted-request-header) - `connectTimeout` is not specified - `sendTimeout` is not specified - `onSendProgress` is not specified - _It otherwise satisfies the spec as determined by the browser_ Resolves cfug#1954. ### New Pull Request Checklist - [x] I have read the [Documentation](https://pub.dev/documentation/dio/latest/) - [x] I have searched for a similar pull request in the [project](https://github.com/cfug/dio/pulls) and found none - [x] I have updated this branch with the latest `main` branch to avoid conflicts (via merge from master or rebase) - [x] I have added the required tests to prove the fix/feature I'm adding - [ ] I have updated the documentation (if necessary) - [x] I have run the tests without failures - [x] I have updated the `CHANGELOG.md` in the corresponding package ### Additional context and info (if any) This is my first time contributing to dio. I don't really know what I'm doing. I have no idea of the global implications of this change. Any assistance and scrutiny would be appreciated. _This fix has worked for my original use case._ --------- Signed-off-by: Dmitry Semenov <[email protected]>
- Loading branch information
1 parent
765ca7b
commit 5076208
Showing
6 changed files
with
157 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
sdk: [ 2.15.0, stable, beta ] | ||
platform: [ vm, chrome ] | ||
platform: [ vm, chrome, firefox ] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: dart-lang/[email protected] | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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