Skip to content

feat(cupertino): add task-level delegate impl#1884

Merged
brianquinlan merged 9 commits intodart-lang:masterfrom
mertalev:chore/cupertino-task-level-delegate
Mar 16, 2026
Merged

feat(cupertino): add task-level delegate impl#1884
brianquinlan merged 9 commits intodart-lang:masterfrom
mertalev:chore/cupertino-task-level-delegate

Conversation

@mertalev
Copy link
Contributor

@mertalev mertalev commented Feb 25, 2026

This PR introduces a taskDelegate builder and exposes NSURLSessionTask's delegate property to enable use of task-level delegates. They are not used anywhere yet to minimize the scope of the PR, but will be used in cupertino_client.dart to replace the existing session-level delegate implementation.


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

Note: The Dart team is trialing Gemini Code Assist. Don't take its comments as final Dart team feedback. Use the suggestions if they're helpful; otherwise, wait for a human reviewer.

@github-actions github-actions bot added the package:cupertino_http Issues related to package:cupertino_http label Feb 25, 2026
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

PR Health

Coverage ⚠️
File Coverage
pkgs/cupertino_http/example/integration_test/url_session_delegate_test.dart 💔 Not covered
pkgs/cupertino_http/example/integration_test/url_session_task_test.dart 💔 Not covered
pkgs/cupertino_http/lib/src/cupertino_api.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.

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
cupertino_http Breaking 2.4.0 3.0.0-wip 3.0.0-wip ✔️

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

Unused Dependencies ⚠️
Package Status
cupertino_http
❗ Show Issues
These packages are used outside lib/ but are not dev_dependencies:
* convert
* crypto
* flutter_test
* http_client_conformance_tests
* http_image_provider
* integration_test
* provider
* test
* web_socket_conformance_tests
These packages are only used outside lib/ and should be downgraded to dev_dependencies:
* flutter
These packages may be unused, or you may be using assets from these packages:
* dart_flutter_team_lints
Failed to update packages.

For details on how to fix these, see dependency_validator.

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

Changelog Entry ✔️
Package Changed Files

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

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

License Headers ⚠️
""
Files
pkgs/cupertino_http/example/integration_test/url_session_delegate_test.dart
pkgs/cupertino_http/example/integration_test/url_session_task_test.dart
pkgs/cupertino_http/lib/src/cupertino_api.dart

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/cronet_http/example/integration_test/client_profile_test.dart
pkgs/cronet_http/example/integration_test/client_test.dart
pkgs/cronet_http/example/integration_test/cronet_engine_test.dart
pkgs/cronet_http/example/lib/book.dart
pkgs/cronet_http/example/lib/main.dart
pkgs/cronet_http/lib/cronet_http.dart
pkgs/cronet_http/lib/src/cronet_client.dart
pkgs/cupertino_http/example/integration_test/client_conformance_test.dart
pkgs/cupertino_http/example/integration_test/client_profile_test.dart
pkgs/cupertino_http/example/integration_test/client_test.dart
pkgs/cupertino_http/example/integration_test/http_url_response_test.dart
pkgs/cupertino_http/example/integration_test/main.dart
pkgs/cupertino_http/example/integration_test/mutable_url_request_test.dart
pkgs/cupertino_http/example/integration_test/ns_error_client_exception.dart
pkgs/cupertino_http/example/integration_test/url_cache_test.dart
pkgs/cupertino_http/example/integration_test/url_request_test.dart
pkgs/cupertino_http/example/integration_test/url_response_test.dart
pkgs/cupertino_http/example/integration_test/url_session_configuration_test.dart
pkgs/cupertino_http/example/integration_test/url_session_test.dart
pkgs/cupertino_http/example/integration_test/web_socket_conformance_test.dart
pkgs/cupertino_http/example/integration_test/web_socket_test.dart
pkgs/cupertino_http/example/lib/book.dart
pkgs/cupertino_http/example/lib/main.dart
pkgs/cupertino_http/lib/cupertino_http.dart
pkgs/cupertino_http/lib/src/cupertino_client.dart
pkgs/cupertino_http/lib/src/cupertino_web_socket.dart
pkgs/flutter_http_example/lib/book.dart
pkgs/flutter_http_example/lib/http_client_factory.dart
pkgs/flutter_http_example/lib/http_client_factory_web.dart
pkgs/flutter_http_example/lib/main.dart
pkgs/flutter_http_example/test/widget_test.dart
pkgs/http/example/main.dart
pkgs/http/example/retry.dart
pkgs/http/lib/browser_client.dart
pkgs/http/lib/http.dart
pkgs/http/lib/io_client.dart
pkgs/http/lib/retry.dart
pkgs/http/lib/src/abortable.dart
pkgs/http/lib/src/base_client.dart
pkgs/http/lib/src/base_request.dart
pkgs/http/lib/src/base_response.dart
pkgs/http/lib/src/boundary_characters.dart
pkgs/http/lib/src/browser_client.dart
pkgs/http/lib/src/byte_stream.dart
pkgs/http/lib/src/client.dart
pkgs/http/lib/src/client_stub.dart
pkgs/http/lib/src/exception.dart
pkgs/http/lib/src/io_client.dart
pkgs/http/lib/src/io_streamed_response.dart
pkgs/http/lib/src/mock_client.dart
pkgs/http/lib/src/multipart_file.dart
pkgs/http/lib/src/multipart_file_io.dart
pkgs/http/lib/src/multipart_file_stub.dart
pkgs/http/lib/src/multipart_request.dart
pkgs/http/lib/src/request.dart
pkgs/http/lib/src/response.dart
pkgs/http/lib/src/streamed_request.dart
pkgs/http/lib/src/streamed_response.dart
pkgs/http/lib/src/utils.dart
pkgs/http/test/html/client_conformance_test.dart
pkgs/http/test/html/client_test.dart
pkgs/http/test/html/streamed_request_test.dart
pkgs/http/test/html/utils.dart
pkgs/http/test/http_retry_test.dart
pkgs/http/test/io/client_conformance_test.dart
pkgs/http/test/io/client_test.dart
pkgs/http/test/io/http_test.dart
pkgs/http/test/io/multipart_test.dart
pkgs/http/test/io/request_test.dart
pkgs/http/test/io/streamed_request_test.dart
pkgs/http/test/mock_client_test.dart
pkgs/http/test/multipart_test.dart
pkgs/http/test/no_default_http_client_test.dart
pkgs/http/test/request_test.dart
pkgs/http/test/response_test.dart
pkgs/http/test/streamed_request_test.dart
pkgs/http/test/stub_server.dart
pkgs/http/test/utils.dart
pkgs/http2/example/display_headers.dart
pkgs/http2/lib/http2.dart
pkgs/http2/lib/multiprotocol_server.dart
pkgs/http2/lib/src/artificial_server_socket.dart
pkgs/http2/lib/src/async_utils/async_utils.dart
pkgs/http2/lib/src/byte_utils.dart
pkgs/http2/lib/src/connection.dart
pkgs/http2/lib/src/connection_preface.dart
pkgs/http2/lib/src/error_handler.dart
pkgs/http2/lib/src/flowcontrol/connection_queues.dart
pkgs/http2/lib/src/flowcontrol/queue_messages.dart
pkgs/http2/lib/src/flowcontrol/stream_queues.dart
pkgs/http2/lib/src/flowcontrol/window.dart
pkgs/http2/lib/src/flowcontrol/window_handler.dart
pkgs/http2/lib/src/frames/frame_defragmenter.dart
pkgs/http2/lib/src/frames/frame_reader.dart
pkgs/http2/lib/src/frames/frame_types.dart
pkgs/http2/lib/src/frames/frame_utils.dart
pkgs/http2/lib/src/frames/frame_writer.dart
pkgs/http2/lib/src/frames/frames.dart
pkgs/http2/lib/src/hpack/hpack.dart
pkgs/http2/lib/src/hpack/huffman.dart
pkgs/http2/lib/src/hpack/huffman_table.dart
pkgs/http2/lib/src/ping/ping_handler.dart
pkgs/http2/lib/src/settings/settings.dart
pkgs/http2/lib/src/streams/stream_handler.dart
pkgs/http2/lib/src/sync_errors.dart
pkgs/http2/lib/transport.dart
pkgs/http2/manual_test/out_of_stream_ids_test.dart
pkgs/http2/test/client_test.dart
pkgs/http2/test/multiprotocol_server_test.dart
pkgs/http2/test/server_test.dart
pkgs/http2/test/src/async_utils/async_utils_test.dart
pkgs/http2/test/src/connection_preface_test.dart
pkgs/http2/test/src/error_matchers.dart
pkgs/http2/test/src/flowcontrol/connection_queues_test.dart
pkgs/http2/test/src/flowcontrol/mocks.dart
pkgs/http2/test/src/flowcontrol/stream_queues_test.dart
pkgs/http2/test/src/flowcontrol/window_handler_test.dart
pkgs/http2/test/src/frames/frame_defragmenter_test.dart
pkgs/http2/test/src/frames/frame_reader_test.dart
pkgs/http2/test/src/frames/frame_writer_reader_test.dart
pkgs/http2/test/src/frames/frame_writer_test.dart
pkgs/http2/test/src/hpack/hpack_test.dart
pkgs/http2/test/src/hpack/huffman_table_test.dart
pkgs/http2/test/src/ping/ping_handler_test.dart
pkgs/http2/test/src/settings/settings_handler_test.dart
pkgs/http2/test/src/streams/helper.dart
pkgs/http2/test/src/streams/simple_flow_test.dart
pkgs/http2/test/src/streams/simple_push_test.dart
pkgs/http2/test/src/streams/streams_test.dart
pkgs/http2/test/transport_test.dart
pkgs/http_client_conformance_tests/example/client_test.dart
pkgs/http_client_conformance_tests/lib/http_client_conformance_tests.dart
pkgs/http_client_conformance_tests/lib/src/abort_server.dart
pkgs/http_client_conformance_tests/lib/src/abort_tests.dart
pkgs/http_client_conformance_tests/lib/src/close_tests.dart
pkgs/http_client_conformance_tests/lib/src/compressed_response_body_server.dart
pkgs/http_client_conformance_tests/lib/src/compressed_response_body_tests.dart
pkgs/http_client_conformance_tests/lib/src/dummy_isolate.dart
pkgs/http_client_conformance_tests/lib/src/isolate_test.dart
pkgs/http_client_conformance_tests/lib/src/multipart_server.dart
pkgs/http_client_conformance_tests/lib/src/multipart_tests.dart
pkgs/http_client_conformance_tests/lib/src/multiple_clients_server.dart
pkgs/http_client_conformance_tests/lib/src/multiple_clients_tests.dart
pkgs/http_client_conformance_tests/lib/src/redirect_server.dart
pkgs/http_client_conformance_tests/lib/src/redirect_tests.dart
pkgs/http_client_conformance_tests/lib/src/request_body_server.dart
pkgs/http_client_conformance_tests/lib/src/request_body_streamed_server.dart
pkgs/http_client_conformance_tests/lib/src/request_body_streamed_tests.dart
pkgs/http_client_conformance_tests/lib/src/request_body_tests.dart
pkgs/http_client_conformance_tests/lib/src/request_cookies_server.dart
pkgs/http_client_conformance_tests/lib/src/request_cookies_test.dart
pkgs/http_client_conformance_tests/lib/src/request_headers_server.dart
pkgs/http_client_conformance_tests/lib/src/request_headers_tests.dart
pkgs/http_client_conformance_tests/lib/src/request_methods_server.dart
pkgs/http_client_conformance_tests/lib/src/request_methods_tests.dart
pkgs/http_client_conformance_tests/lib/src/response_body_server.dart
pkgs/http_client_conformance_tests/lib/src/response_body_streamed_server.dart
pkgs/http_client_conformance_tests/lib/src/response_body_streamed_test.dart
pkgs/http_client_conformance_tests/lib/src/response_body_tests.dart
pkgs/http_client_conformance_tests/lib/src/response_cookies_server.dart
pkgs/http_client_conformance_tests/lib/src/response_cookies_test.dart
pkgs/http_client_conformance_tests/lib/src/response_headers_server.dart
pkgs/http_client_conformance_tests/lib/src/response_status_line_server.dart
pkgs/http_client_conformance_tests/lib/src/response_status_line_tests.dart
pkgs/http_client_conformance_tests/lib/src/server_errors_server.dart
pkgs/http_client_conformance_tests/lib/src/server_errors_test.dart
pkgs/http_client_conformance_tests/lib/src/server_queue_helpers.dart
pkgs/http_multi_server/example/main.dart
pkgs/http_multi_server/lib/http_multi_server.dart
pkgs/http_multi_server/lib/src/multi_headers.dart
pkgs/http_multi_server/lib/src/utils.dart
pkgs/http_multi_server/test/cert.dart
pkgs/http_multi_server/test/http_multi_server_test.dart
pkgs/http_parser/example/example.dart
pkgs/http_parser/lib/http_parser.dart
pkgs/http_parser/lib/src/authentication_challenge.dart
pkgs/http_parser/lib/src/case_insensitive_map.dart
pkgs/http_parser/lib/src/chunked_coding.dart
pkgs/http_parser/lib/src/chunked_coding/charcodes.dart
pkgs/http_parser/lib/src/chunked_coding/decoder.dart
pkgs/http_parser/lib/src/chunked_coding/encoder.dart
pkgs/http_parser/lib/src/http_date.dart
pkgs/http_parser/lib/src/media_type.dart
pkgs/http_parser/lib/src/scan.dart
pkgs/http_parser/lib/src/utils.dart
pkgs/http_parser/test/authentication_challenge_test.dart
pkgs/http_parser/test/case_insensitive_map_test.dart
pkgs/http_parser/test/chunked_coding_test.dart
pkgs/http_parser/test/example_test.dart
pkgs/http_parser/test/http_date_test.dart
pkgs/http_parser/test/media_type_test.dart
pkgs/http_profile/lib/http_profile.dart
pkgs/http_profile/lib/src/http_client_request_profile.dart
pkgs/http_profile/lib/src/http_profile.dart
pkgs/http_profile/lib/src/http_profile_request_data.dart
pkgs/http_profile/lib/src/http_profile_response_data.dart
pkgs/http_profile/lib/src/utils.dart
pkgs/http_profile/test/close_test.dart
pkgs/http_profile/test/http_client_request_profile_test.dart
pkgs/http_profile/test/http_profile_request_data_test.dart
pkgs/http_profile/test/http_profile_response_data_test.dart
pkgs/http_profile/test/utils_test.dart
pkgs/ok_http/example/integration_test/certificate_test.dart
pkgs/ok_http/example/integration_test/client_configuration_test.dart
pkgs/ok_http/example/integration_test/client_profile_test.dart
pkgs/ok_http/example/integration_test/client_test.dart
pkgs/ok_http/example/integration_test/web_socket_test.dart
pkgs/ok_http/example/lib/book.dart
pkgs/ok_http/example/lib/main.dart
pkgs/ok_http/lib/ok_http.dart
pkgs/ok_http/lib/src/ok_http_client.dart
pkgs/ok_http/lib/src/ok_http_web_socket.dart
pkgs/web_socket/example/web_socket_example.dart
pkgs/web_socket/lib/browser_web_socket.dart
pkgs/web_socket/lib/io_web_socket.dart
pkgs/web_socket/lib/src/browser_web_socket.dart
pkgs/web_socket/lib/src/connect_stub.dart
pkgs/web_socket/lib/src/fake_web_socket.dart
pkgs/web_socket/lib/src/io_web_socket.dart
pkgs/web_socket/lib/src/utils.dart
pkgs/web_socket/lib/src/web_socket.dart
pkgs/web_socket/lib/testing.dart
pkgs/web_socket/lib/web_socket.dart
pkgs/web_socket/test/browser_web_socket_conformance_test.dart
pkgs/web_socket/test/exceptions_test.dart
pkgs/web_socket/test/fake_web_socket_test.dart
pkgs/web_socket/test/io_web_socket_conformance_test.dart
pkgs/web_socket/test/io_web_socket_test.dart
pkgs/web_socket/test/websocket_test.dart
pkgs/web_socket_channel/example/example.dart
pkgs/web_socket_channel/lib/adapter_web_socket_channel.dart
pkgs/web_socket_channel/lib/html.dart
pkgs/web_socket_channel/lib/io.dart
pkgs/web_socket_channel/lib/src/channel.dart
pkgs/web_socket_channel/lib/src/exception.dart
pkgs/web_socket_channel/lib/src/sink_completer.dart
pkgs/web_socket_channel/lib/status.dart
pkgs/web_socket_channel/lib/web_socket_channel.dart
pkgs/web_socket_channel/test/adapter_web_socket_channel_test.dart
pkgs/web_socket_channel/test/echo_server_vm.dart
pkgs/web_socket_channel/test/echo_server_web.dart
pkgs/web_socket_channel/test/html_test.dart
pkgs/web_socket_channel/test/io_test.dart
pkgs/web_socket_conformance_tests/example/client_test.dart
pkgs/web_socket_conformance_tests/lib/src/close_local_server.dart
pkgs/web_socket_conformance_tests/lib/src/close_local_tests.dart
pkgs/web_socket_conformance_tests/lib/src/close_remote_server.dart
pkgs/web_socket_conformance_tests/lib/src/close_remote_tests.dart
pkgs/web_socket_conformance_tests/lib/src/connect_uri_tests.dart
pkgs/web_socket_conformance_tests/lib/src/continuously_writing_server.dart
pkgs/web_socket_conformance_tests/lib/src/disconnect_after_upgrade_server.dart
pkgs/web_socket_conformance_tests/lib/src/disconnect_after_upgrade_tests.dart
pkgs/web_socket_conformance_tests/lib/src/echo_server.dart
pkgs/web_socket_conformance_tests/lib/src/no_upgrade_server.dart
pkgs/web_socket_conformance_tests/lib/src/no_upgrade_tests.dart
pkgs/web_socket_conformance_tests/lib/src/payload_transfer_tests.dart
pkgs/web_socket_conformance_tests/lib/src/peer_protocol_errors_server.dart
pkgs/web_socket_conformance_tests/lib/src/peer_protocol_errors_tests.dart
pkgs/web_socket_conformance_tests/lib/src/protocol_server.dart
pkgs/web_socket_conformance_tests/lib/src/protocol_tests.dart
pkgs/web_socket_conformance_tests/lib/web_socket_conformance_tests.dart

This check can be disabled by tagging the PR with skip-license-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 symbol Leaking sources

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

@brianquinlan
Copy link
Collaborator

brianquinlan commented Mar 2, 2026

@mertalev Thanks!

Why didn't you just expose the delegate property on NSURLSessionTask?

@mertalev
Copy link
Contributor Author

mertalev commented Mar 3, 2026

@mertalev Thanks!

Why didn't you just expose the delegate property on NSURLSessionTask?

The StreamingTask and WebSocketTask wrapped the earlier Swift-based implementation. I guess you're right that they aren't really needed since it's using Dart bindings now.

@mertalev
Copy link
Contributor Author

mertalev commented Mar 3, 2026

I changed it to expose a taskDelegate property and added a URLSessionTask.delegate builder that shares its logic with the existing URLSession.delegate builder. Both CupertinoClient and CupertinoWebSocket can use this, which is nicer than what I originally had.

@brianquinlan
Copy link
Collaborator

Could you fix the analysis errors:

warning • The '!' will have no effect because the receiver can't be null • example/integration_test/url_session_delegate_test.dart:648:38 • unnecessary_non_null_assertion
warning • The '!' will have no effect because the receiver can't be null • example/integration_test/url_session_delegate_test.dart:694:38 • unnecessary_non_null_assertion
warning • The '!' will have no effect because the receiver can't be null • example/integration_test/url_session_delegate_test.dart:740:38 • unnecessary_non_null_assertion

Could you remove the @pragmas for now unless you have reason to believe that they actually improve performance?

Could you add tests for the delegates to https://github.com/dart-lang/http/blob/master/pkgs/cupertino_http/example/integration_test/url_session_task_test.dart ?

@mertalev
Copy link
Contributor Author

Will do! Regarding the pragmas, they do make the disassembly look better with fewer closure allocations and all the if conditions get removed and dead-code eliminated. It's a micro-optimization in the grand scheme of things, though, so I can remove them if you prefer?

@brianquinlan
Copy link
Collaborator

Will do! Regarding the pragmas, they do make the disassembly look better with fewer closure allocations and all the if conditions get removed and dead-code eliminated. It's a micro-optimization in the grand scheme of things, though, so I can remove them if you prefer?

If you need to look at the disassembly and they make it easier, you can keep them. Thanks!

@mertalev
Copy link
Contributor Author

I added the tests and removed the null assertions, so it should be good now.

@brianquinlan
Copy link
Collaborator

I'm doing a review now. Could you rebase/merge so that the CI will run?

BTW, I love your tests. They are amazing!

@mertalev mertalev force-pushed the chore/cupertino-task-level-delegate branch from a81660e to 133dbb9 Compare March 16, 2026 21:59
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.

Amazing job!

@brianquinlan brianquinlan merged commit fdf45ad into dart-lang:master Mar 16, 2026
50 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package:cupertino_http Issues related to package:cupertino_http

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants