-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Reduce cases in which browsers would trigger a CORS preflight request #1955
Conversation
Signed-off-by: Dmitry Semenov <[email protected]>
Signed-off-by: Dmitry Semenov <[email protected]>
Interesting, I didn't know this about CORS. I think this makes sense in any case. Just wondering about the |
e3bf9e9
to
69d784a
Compare
Can we run tests only for Firefox? I'm not aware of any corresponding flags. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From an overall look, this change affects some timeout behavior which might introduce regression. And the change itself requires tests.
I think we can with I'll start adding a browser test which checks if OPTIONS request gets sent to the server for requests that should've been "simple". |
Can you elaborate on that? As I understand from the code comment, the |
uploadStopwatch.start(); | ||
if (requestStream != null) { | ||
xhr.upload.onProgress.listen((event) { | ||
// This event will only be triggered if a request body exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexV525 Regarding the timeouts, I think this comment is the key here. If there is no body, the following code never runs. But we should add a general test for that.
@lonelyteapot It would be great if you can setup firefox handling. I think this should be possible on ubuntu in CI.
Yea, after looking at the code again, this became more obvious to me :) |
I've run into a blocker while enabling tests on Firefox. Basic tests fail with CORS errors. This is due to a problem with httpbun.com which is used in tests. I've filed an issue there: sharat87/httpbun#10. This error happens in Chrome too, but Dio tests are not affected because they launch Chrome with And I think web security shouldn't be disabled, so not to hide issues like this. |
Thanks for creating the httpbun issue. My last tickets there were resolved and deployed quickly. |
I have created #1966 to update test configuration for firefox. |
@kuhnroyal, thanks, but I've already done it locally for this PR. Sorry for not pushing for so long. Right now I'm debugging some stuff and making sure new changes aren't breaking things. I think you may also want to add |
No worries. I think it would be good to have a baseline from the other PR so we don't mingle changes for the CORS problem with other fixes for Firefox tests. |
69d784a
to
a35dfc3
Compare
I've extended the scope of this PR. Previously there was only a check for empty request body to handle the majority of use cases, but now there are more tighter conditions to register an upload listener. The logic itself should remain unchanged, but a thorough review is needed. I've manually verified that I've also noticed that there was a bug which caused receiveTimeout not to work. Please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the above comments are resolved to me gracefully. Thanks!
This is interesting. Without your changes, there are failing tests on firefox in #1966. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great work, thanks!
@kuhnroyal interested indeed. I don't think lack of my changes could be the cause here. I haven't encountered any issues while running tests locally. That might have been a random failure. |
No, it is not random. All status code tests (4xx/5xx) fail with firefox on develop. |
@kuhnroyal oh, yes, you're right. Since in these tests the server expectedly responds with non-successful HTTP status codes, preflight requests fail. Turns out there wasn't a single test for a request that should both be preflighted and fail. |
Certain requests are considered "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:
HEAD
/GET
/POST
requesttext/plain
,multipart/form-data
,application/x-www-form-urlencoded
connectTimeout
is not specifiedsendTimeout
is not specifiedonSendProgress
is not specifiedResolves #1954.
New Pull Request Checklist
main
branch to avoid conflicts (via merge from master or rebase)CHANGELOG.md
in the corresponding packageAdditional 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.