Skip to content
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

Switch browser_client.dart to use fetch #1401

Merged
merged 5 commits into from
Nov 14, 2024

Conversation

mraleph
Copy link
Member

@mraleph mraleph commented Nov 8, 2024

Rewrite browser_client.dart to use fetch instead of XHR.

Copy link

github-actions bot commented Nov 8, 2024

Package publishing

Package Version Status Publish tag (post-merge)
package:http2 2.3.1 ready to publish http2-v2.3.1
package:cronet_http 1.3.3-wip WIP (no publish necessary)
package:cupertino_http 2.0.1 already published at pub.dev
package:http 1.3.0-wip WIP (no publish necessary)
package:http_parser 4.1.1 already published at pub.dev
package:http_profile 0.1.1-wip WIP (no publish necessary)
package:ok_http 0.1.1-wip WIP (no publish necessary)
package:web_socket 0.1.6 already published at pub.dev

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

Copy link

github-actions bot commented Nov 8, 2024

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
http None 1.2.3-wip 1.3.0-wip 1.3.0-wip ✔️
Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

Coverage ⚠️
File Coverage
pkgs/http/lib/src/browser_client.dart 💔 Not covered

This check for test coverage is informational (issues shown here will not fail the PR).

This check can be disabled by tagging the PR with skip-coverage-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbols
License Headers ✔️
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/cronet_http/lib/src/jni/jni_bindings.dart
pkgs/cupertino_http/lib/src/native_cupertino_bindings.dart
pkgs/http/example/main.dart
pkgs/http2/test/src/flowcontrol/mocks.mocks.dart
pkgs/http_client_conformance_tests/example/client_test.dart
pkgs/http_client_conformance_tests/lib/src/compressed_response_body_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/compressed_response_body_server_web.dart
pkgs/http_client_conformance_tests/lib/src/dummy_isolate.dart
pkgs/http_client_conformance_tests/lib/src/multipart_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/multipart_server_web.dart
pkgs/http_client_conformance_tests/lib/src/multiple_clients_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/multiple_clients_server_web.dart
pkgs/http_client_conformance_tests/lib/src/redirect_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/redirect_server_web.dart
pkgs/http_client_conformance_tests/lib/src/request_body_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/request_body_server_web.dart
pkgs/http_client_conformance_tests/lib/src/request_body_streamed_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/request_body_streamed_server_web.dart
pkgs/http_client_conformance_tests/lib/src/request_cookies_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/request_cookies_server_web.dart
pkgs/http_client_conformance_tests/lib/src/request_headers_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/request_headers_server_web.dart
pkgs/http_client_conformance_tests/lib/src/request_methods_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/request_methods_server_web.dart
pkgs/http_client_conformance_tests/lib/src/response_body_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/response_body_server_web.dart
pkgs/http_client_conformance_tests/lib/src/response_body_streamed_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/response_body_streamed_server_web.dart
pkgs/http_client_conformance_tests/lib/src/response_cookies_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/response_cookies_server_web.dart
pkgs/http_client_conformance_tests/lib/src/response_headers_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/response_headers_server_web.dart
pkgs/http_client_conformance_tests/lib/src/response_status_line_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/response_status_line_server_web.dart
pkgs/http_client_conformance_tests/lib/src/server_errors_server_vm.dart
pkgs/http_client_conformance_tests/lib/src/server_errors_server_web.dart
pkgs/http_parser/test/example_test.dart
pkgs/http_profile/lib/http_profile.dart
pkgs/ok_http/lib/src/jni/bindings.dart
pkgs/web_socket/example/web_socket_example.dart
pkgs/web_socket/lib/testing.dart
pkgs/web_socket_conformance_tests/example/client_test.dart
pkgs/web_socket_conformance_tests/lib/src/close_local_server_vm.dart
pkgs/web_socket_conformance_tests/lib/src/close_local_server_web.dart
pkgs/web_socket_conformance_tests/lib/src/close_remote_server_vm.dart
pkgs/web_socket_conformance_tests/lib/src/close_remote_server_web.dart
pkgs/web_socket_conformance_tests/lib/src/continuously_writing_server_vm.dart
pkgs/web_socket_conformance_tests/lib/src/continuously_writing_server_web.dart
pkgs/web_socket_conformance_tests/lib/src/disconnect_after_upgrade_server_vm.dart
pkgs/web_socket_conformance_tests/lib/src/disconnect_after_upgrade_server_web.dart
pkgs/web_socket_conformance_tests/lib/src/echo_server_vm.dart
pkgs/web_socket_conformance_tests/lib/src/echo_server_web.dart
pkgs/web_socket_conformance_tests/lib/src/no_upgrade_server_vm.dart
pkgs/web_socket_conformance_tests/lib/src/no_upgrade_server_web.dart
pkgs/web_socket_conformance_tests/lib/src/peer_protocol_errors_server_vm.dart
pkgs/web_socket_conformance_tests/lib/src/peer_protocol_errors_server_web.dart
pkgs/web_socket_conformance_tests/lib/src/protocol_server_vm.dart
pkgs/web_socket_conformance_tests/lib/src/protocol_server_web.dart

@brianquinlan
Copy link
Collaborator

Nice!

There are some lints to fix here.
Do you want to increase the browser test coverage?
I also noticed that you aren't supporting streaming uploads - presumably that is because it is not well supported across browser versions?

@mraleph
Copy link
Member Author

mraleph commented Nov 8, 2024

Fixing the lints now. I am a bit surprised that I don't get them in the IDE.

I also noticed that you aren't supporting streaming uploads - presumably that is because it is not well supported across browser versions?

Yeah, I am typing the comment on the issue now. tldr is that even when browser supports streaming request it can still refuse to do it if the server is not HTTP/2 or QUIC... Which means we can't really use it by default because it will potentially cause existing code to fail (even if we sniff browser compatibility - which by itself is a non-trivial thing to do :-/). I am honestly surprised how nasty browser implementation is - it does not even provide any useful information in the error message when this happens and you need to go look into the console to see ERR_H2_OR_QUIC_REQUIRED there.

@mraleph mraleph mentioned this pull request Nov 8, 2024
Copy link
Collaborator

@brianquinlan brianquinlan left a comment

Choose a reason for hiding this comment

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

I want to be you when I grow up.

pkgs/http/CHANGELOG.md Outdated Show resolved Hide resolved
pkgs/http/lib/src/browser_client.dart Outdated Show resolved Hide resolved
pkgs/http/lib/src/browser_client.dart Outdated Show resolved Hide resolved
pkgs/http/lib/src/browser_client.dart Outdated Show resolved Hide resolved
pkgs/http/lib/src/browser_client.dart Outdated Show resolved Hide resolved
pkgs/http/lib/src/browser_client.dart Outdated Show resolved Hide resolved
pkgs/http/lib/src/browser_client.dart Outdated Show resolved Hide resolved
@mraleph
Copy link
Member Author

mraleph commented Nov 11, 2024

I will wait landing this before we can get dev coverage. Don't want to land it with a broken CI.

Do you want to increase the browser test coverage?

Do you have something specific in mind?

I have tested firefox and safari locally and both work (though package:test is currently broken in different ways for these two browsers - -p firefox tries to use a binary which does not exist anymore and -p safari requires user intervention1 to run tests).

Footnotes

  1. I wasted couple of hours trying to come up with some way to launch and shutdown Safari cleanly after tests - but the only thing that really works requires using safaridriver. There is no clean equivalent to a simple "open target URL in new process" we get in other browsers.

@brianquinlan
Copy link
Collaborator

I will wait landing this before we can get dev coverage. Don't want to land it with a broken CI.

Do you want to increase the browser test coverage?

Do you have something specific in mind?

I have tested firefox and safari locally and both work (though package:test is currently broken in different ways for these two browsers - -p firefox tries to use a binary which does not exist anymore and -p safari requires user intervention1 to run tests).

Yeah, that was what I was thinking - but I guess that won't work out right now. It looks like the checks are exceeding except for these tests:
https://github.com/dart-lang/http/actions/runs/11778289469/job/32896956901?pr=1401

Footnotes

  1. I wasted couple of hours trying to come up with some way to launch and shutdown Safari cleanly after tests - but the only thing that really works requires using safaridriver. There is no clean equivalent to a simple "open target URL in new process" we get in other browsers.

@mraleph
Copy link
Member Author

mraleph commented Nov 14, 2024

I fixed 3.4 tests

@mraleph mraleph merged commit e509abb into dart-lang:master Nov 14, 2024
32 checks passed
@mraleph mraleph deleted the switch-to-fetch branch November 14, 2024 21:24
@kevmoo
Copy link
Member

kevmoo commented Nov 14, 2024

What's the associated bug? Can resolve/close as well?

@jezell
Copy link

jezell commented Nov 14, 2024

Thanks @mraleph! This is great.

I think reading request into memory still means it's going to blow up even when StreamedRequest could be streamed:

https://github.com/mraleph/http/blob/49f3b3cd83b38944722c2d4a1d60b70c1fb21eb9/pkgs/http/lib/src/browser_client.dart#L64

But, at least it puts the parts in place to enable some solutions to those problems.

Think what needs to be figured out is how do we get something other than a byte array to here:

https://github.com/mraleph/http/blob/49f3b3cd83b38944722c2d4a1d60b70c1fb21eb9/pkgs/http/lib/src/browser_client.dart#L71

Not sure the proper platform neutral abstraction for the library, but if there was a way to go something like:

import "package:http/web.dart";
import "package:web/web.dart" as web;

client.send(WebRequest(web.RequestBody));

RequestBody

At least that would provide some kind of path to do a file upload or manually pass a stream if you want.

@mraleph
Copy link
Member Author

mraleph commented Nov 14, 2024

I am planning to look at request streaming as well, because I have already loaded the context into my head so it makes sense to do something before it gets paged out.

copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Nov 19, 2024
Revisions updated by `dart tools/rev_sdk_deps.dart`.

dartdoc (https://github.com/dart-lang/dartdoc/compare/6bbd3d7..f8a55e4):
  f8a55e4b  2024-11-18  Parker Lougheed  Remove unused build config (dart-lang/dartdoc#3923)
  fa339a10  2024-11-15  Sam Rawlins  Refactor how Object and Pragma are discovered and handled (dart-lang/dartdoc#3929)

http (https://github.com/dart-lang/http/compare/2f954e1..e37093f):
  e37093f  2024-11-15  Brian Quinlan  Upgrade to `package:`objective_c` 4.0 (dart-lang/http#1406)
  e509abb  2024-11-14  Slava Egorov  Switch browser_client.dart to use fetch (dart-lang/http#1401)

yaml_edit (https://github.com/dart-lang/yaml_edit/compare/3d1421b..8bd0fdf):
  8bd0fdf  2024-11-18  Kevin Moore  Fix unused param in a private ctor lint (dart-lang/yaml_edit#99)

Change-Id: I12a74dc3bce629c213d26fbb6e76fc3c19a443dd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396422
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Devon Carew <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants