diff --git a/chopper/example/definition.chopper.dart b/chopper/example/definition.chopper.dart deleted file mode 100644 index 4ee6e510..00000000 --- a/chopper/example/definition.chopper.dart +++ /dev/null @@ -1,128 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'definition.dart'; - -// ************************************************************************** -// ChopperGenerator -// ************************************************************************** - -// coverage:ignore-file -// ignore_for_file: type=lint -final class _$MyService extends MyService { - _$MyService([ChopperClient? client]) { - if (client == null) return; - this.client = client; - } - - @override - final Type definitionType = MyService; - - @override - Future> getResource(String id) { - final Uri $url = Uri.parse('/resources/${id}'); - final Request $request = Request( - 'GET', - $url, - client.baseUrl, - ); - return client.send($request); - } - - @override - Future>> getMapResource(String id) { - final Uri $url = Uri.parse('/resources/'); - final Map $params = {'id': id}; - final Map $headers = { - 'foo': 'bar', - }; - final Request $request = Request( - 'GET', - $url, - client.baseUrl, - parameters: $params, - headers: $headers, - ); - return client.send, Map>($request); - } - - @override - Future>>> getListResources() { - final Uri $url = Uri.parse('/resources/resources'); - final Request $request = Request( - 'GET', - $url, - client.baseUrl, - ); - return client - .send>, Map>($request); - } - - @override - Future> postResourceUrlEncoded( - String toto, - String b, - ) { - final Uri $url = Uri.parse('/resources/'); - final $body = { - 'a': toto, - 'b': b, - }; - final Request $request = Request( - 'POST', - $url, - client.baseUrl, - body: $body, - ); - return client.send($request); - } - - @override - Future> postResources( - Map a, - Map b, - String c, - ) { - final Uri $url = Uri.parse('/resources/multi'); - final List $parts = [ - PartValue>( - '1', - a, - ), - PartValue>( - '2', - b, - ), - PartValue( - '3', - c, - ), - ]; - final Request $request = Request( - 'POST', - $url, - client.baseUrl, - parts: $parts, - multipart: true, - ); - return client.send($request); - } - - @override - Future> postFile(List bytes) { - final Uri $url = Uri.parse('/resources/file'); - final List $parts = [ - PartValue>( - 'file', - bytes, - ) - ]; - final Request $request = Request( - 'POST', - $url, - client.baseUrl, - parts: $parts, - multipart: true, - ); - return client.send($request); - } -} diff --git a/chopper/example/definition.dart b/chopper/example/definition.dart index ef8fcf9d..9373fc5d 100644 --- a/chopper/example/definition.dart +++ b/chopper/example/definition.dart @@ -4,28 +4,12 @@ import 'package:chopper/chopper.dart'; part 'definition.chopper.dart'; -@ChopperApi(baseUrl: '/resources') +@ChopperApi(baseUrl: '/') abstract class MyService extends ChopperService { static MyService create(ChopperClient client) => _$MyService(client); - @Get(path: '/{id}') - Future getResource( - @Path() String id, - ); - - @Get(path: '/', headers: {'foo': 'bar'}) - Future> getMapResource( - @Query() String id, - ); - - @Get(path: '/resources') - Future>> getListResources(); - - @Post(path: '/') - Future postResourceUrlEncoded( - @Field('a') String toto, - @Field() String b, - ); + @Get(path: '/abc') + Future> getLongTimeTest(); @Post(path: '/multi') @multipart diff --git a/chopper/example/main.dart b/chopper/example/main.dart index b7a2cad4..4224f227 100644 --- a/chopper/example/main.dart +++ b/chopper/example/main.dart @@ -1,8 +1,10 @@ import 'package:chopper/chopper.dart'; +import 'package:cancellation_token/cancellation_token.dart'; import 'definition.dart'; Future main() async { + var token = CancellationToken(); final chopper = ChopperClient( baseUrl: Uri.parse('http://localhost:8000'), services: [ @@ -14,11 +16,22 @@ Future main() async { final myService = chopper.getService(); - final response = await myService.getMapResource('1'); - print(response.body); + + Future.delayed(Duration(seconds: 2), () { + token.cancel(); + }); + + try { + final response = await myService.getMapResource('1'); + print(response.body); + } + on CancelledException { + print('cancelled by user!'); + } + final list = await myService.getListResources(); print(list.body); chopper.dispose(); -} +} \ No newline at end of file diff --git a/chopper/example/tag.chopper.dart b/chopper/example/tag.chopper.dart index 77f07fa9..0eb584aa 100644 --- a/chopper/example/tag.chopper.dart +++ b/chopper/example/tag.chopper.dart @@ -26,7 +26,10 @@ final class _$TagService extends TagService { client.baseUrl, tag: tag, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -39,6 +42,9 @@ final class _$TagService extends TagService { client.baseUrl, tag: tag, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } } diff --git a/chopper/lib/src/base.dart b/chopper/lib/src/base.dart index d917f081..211f76b5 100644 --- a/chopper/lib/src/base.dart +++ b/chopper/lib/src/base.dart @@ -8,7 +8,7 @@ import 'package:chopper/src/converters.dart'; import 'package:chopper/src/interceptors/interceptor.dart'; import 'package:chopper/src/request.dart'; import 'package:chopper/src/response.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:meta/meta.dart'; /// ChopperClient is the main class of the Chopper API. @@ -45,6 +45,8 @@ base class ChopperClient { final bool _clientIsInternal; + http.CancellationToken? _cancellationToken; + /// Creates and configures a [ChopperClient]. /// /// The base URL of each request of the registered services can be defined @@ -107,6 +109,7 @@ base class ChopperClient { this.authenticator, this.converter, this.errorConverter, + http.CancellationToken? cancellationToken, Iterable? services, }) : assert( baseUrl == null || !baseUrl.hasQuery, @@ -115,6 +118,7 @@ base class ChopperClient { ), baseUrl = baseUrl ?? Uri(), httpClient = client ?? http.Client(), + _cancellationToken = cancellationToken, _clientIsInternal = client == null { _services = { for (final ChopperService service in services?.toSet() ?? []) @@ -145,7 +149,6 @@ base class ChopperClient { if (service == null) { throw Exception("Service of type '$ServiceType' not found."); } - return service as ServiceType; } @@ -172,12 +175,21 @@ base class ChopperClient { requestCallback: _requestController.add, ); - final response = await call.execute( - requestConverter, - responseConverter, - ); + Response response; + try { + response = await call.execute( + requestConverter, + responseConverter, + cancellationToken: _cancellationToken + ); - _responseController.add(response); + _responseController.add(response); + + } + on http.CancelledException { + _cancellationToken = http.CancellationToken(); + rethrow; + } return response; } @@ -321,6 +333,11 @@ base class ChopperClient { ), ); + /// Cancels any requests by the cancellation token (if exists) + void cancelRequests(){ + _cancellationToken?.cancel(); + } + /// Disposes this [ChopperClient] to clean up memory. /// /// **Warning**: If a custom [http.Client] was provided while creating this `ChopperClient`, diff --git a/chopper/lib/src/chain/call.dart b/chopper/lib/src/chain/call.dart index 4bb277a7..d4d052f5 100644 --- a/chopper/lib/src/chain/call.dart +++ b/chopper/lib/src/chain/call.dart @@ -1,3 +1,4 @@ +import 'package:cancellation_token_http/http.dart' as http; import 'package:chopper/src/annotations.dart'; import 'package:chopper/src/base.dart'; import 'package:chopper/src/chain/interceptor_chain.dart'; @@ -33,6 +34,7 @@ class Call { Future> execute( ConvertRequest? requestConverter, ConvertResponse? responseConverter, + {http.CancellationToken? cancellationToken} ) async { final interceptors = [ RequestConverterInterceptor(client.converter, requestConverter), @@ -45,7 +47,7 @@ class Call { errorConverter: client.errorConverter, responseConverter: responseConverter, ), - HttpCallInterceptor(client.httpClient), + HttpCallInterceptor(client.httpClient, cancellationToken: cancellationToken), ]; final interceptorChain = InterceptorChain( diff --git a/chopper/lib/src/interceptors/curl_interceptor.dart b/chopper/lib/src/interceptors/curl_interceptor.dart index ef850e92..7085f375 100644 --- a/chopper/lib/src/interceptors/curl_interceptor.dart +++ b/chopper/lib/src/interceptors/curl_interceptor.dart @@ -4,7 +4,7 @@ import 'package:chopper/src/chain/chain.dart'; import 'package:chopper/src/interceptors/interceptor.dart'; import 'package:chopper/src/response.dart'; import 'package:chopper/src/utils.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:meta/meta.dart'; /// A [Interceptor] implementation that prints a curl request equivalent diff --git a/chopper/lib/src/interceptors/http_call_interceptor.dart b/chopper/lib/src/interceptors/http_call_interceptor.dart index b7b204bf..f619a3d4 100644 --- a/chopper/lib/src/interceptors/http_call_interceptor.dart +++ b/chopper/lib/src/interceptors/http_call_interceptor.dart @@ -4,7 +4,7 @@ import 'package:chopper/src/chain/chain.dart'; import 'package:chopper/src/chopper_exception.dart'; import 'package:chopper/src/interceptors/internal_interceptor.dart'; import 'package:chopper/src/response.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import '../utils.dart'; @@ -13,7 +13,9 @@ import '../utils.dart'; /// {@endtemplate} class HttpCallInterceptor implements InternalInterceptor { /// {@macro HttpCallInterceptor} - const HttpCallInterceptor(this._httpClient); + const HttpCallInterceptor(this._httpClient, {this.cancellationToken}); + + final http.CancellationToken? cancellationToken; /// HTTP client to be used for making the actual HTTP calls. final http.Client _httpClient; @@ -22,7 +24,8 @@ class HttpCallInterceptor implements InternalInterceptor { FutureOr> intercept( Chain chain) async { final finalRequest = await chain.request.toBaseRequest(); - final streamRes = await _httpClient.send(finalRequest); + final streamRes = await _httpClient.send( + finalRequest, cancellationToken: cancellationToken); if (isTypeOf>>()) { return Response(streamRes, (streamRes.stream) as BodyType); diff --git a/chopper/lib/src/interceptors/http_logging_interceptor.dart b/chopper/lib/src/interceptors/http_logging_interceptor.dart index d8f5ee0f..026d97b4 100644 --- a/chopper/lib/src/interceptors/http_logging_interceptor.dart +++ b/chopper/lib/src/interceptors/http_logging_interceptor.dart @@ -6,7 +6,7 @@ import 'package:chopper/src/interceptors/interceptor.dart'; import 'package:chopper/src/request.dart'; import 'package:chopper/src/response.dart'; import 'package:chopper/src/utils.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:logging/logging.dart'; import 'package:meta/meta.dart'; diff --git a/chopper/lib/src/request.dart b/chopper/lib/src/request.dart index 511fca01..5444d956 100644 --- a/chopper/lib/src/request.dart +++ b/chopper/lib/src/request.dart @@ -3,7 +3,7 @@ import 'dart:async' show Stream; import 'package:chopper/src/extensions.dart'; import 'package:chopper/src/utils.dart'; import 'package:equatable/equatable.dart' show EquatableMixin; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:meta/meta.dart'; import 'package:qs_dart/qs_dart.dart' show ListFormat; diff --git a/chopper/lib/src/response.dart b/chopper/lib/src/response.dart index b9f8e06d..195c36ab 100644 --- a/chopper/lib/src/response.dart +++ b/chopper/lib/src/response.dart @@ -2,7 +2,7 @@ import 'dart:typed_data'; import 'package:chopper/src/chopper_http_exception.dart'; import 'package:equatable/equatable.dart' show EquatableMixin; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:meta/meta.dart'; /// {@template response} diff --git a/chopper/pubspec.yaml b/chopper/pubspec.yaml index eae0f83b..5e0b3ffc 100644 --- a/chopper/pubspec.yaml +++ b/chopper/pubspec.yaml @@ -9,7 +9,7 @@ environment: dependencies: equatable: ^2.0.5 - http: ^1.1.0 + cancellation_token_http: ^2.1.0 logging: ^1.2.0 meta: ^1.9.1 qs_dart: ^1.2.4 diff --git a/chopper/test/authenticator_test.dart b/chopper/test/authenticator_test.dart index d1e6e1a6..4152a28a 100644 --- a/chopper/test/authenticator_test.dart +++ b/chopper/test/authenticator_test.dart @@ -3,8 +3,8 @@ import 'dart:convert' show jsonEncode; import 'package:chopper/src/base.dart'; import 'package:chopper/src/converters.dart'; import 'package:chopper/src/interceptors/headers_interceptor.dart'; -import 'package:http/http.dart' as http; -import 'package:http/testing.dart'; +import 'package:cancellation_token_http/http.dart' as http; +import 'package:cancellation_token_http/testing.dart'; import 'package:test/test.dart'; import 'fake_authenticator.dart'; diff --git a/chopper/test/base_test.dart b/chopper/test/base_test.dart index 8d34bbfb..3d023438 100644 --- a/chopper/test/base_test.dart +++ b/chopper/test/base_test.dart @@ -8,8 +8,8 @@ import 'package:chopper/src/constants.dart'; import 'package:chopper/src/converters.dart'; import 'package:chopper/src/request.dart'; import 'package:chopper/src/utils.dart'; -import 'package:http/http.dart' as http; -import 'package:http/testing.dart'; +import 'package:cancellation_token_http/http.dart' as http; +import 'package:cancellation_token_http/testing.dart'; import 'package:test/test.dart'; import 'package:transparent_image/transparent_image.dart'; diff --git a/chopper/test/chain/authenticator_interceptor_test.dart b/chopper/test/chain/authenticator_interceptor_test.dart index 79e1b18b..478b7e0d 100644 --- a/chopper/test/chain/authenticator_interceptor_test.dart +++ b/chopper/test/chain/authenticator_interceptor_test.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:chopper/chopper.dart'; import 'package:chopper/src/interceptors/authenticator_interceptor.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:test/test.dart'; void main() { diff --git a/chopper/test/chain/interceptor_chain_test.dart b/chopper/test/chain/interceptor_chain_test.dart index fa3502ed..9c4485e2 100644 --- a/chopper/test/chain/interceptor_chain_test.dart +++ b/chopper/test/chain/interceptor_chain_test.dart @@ -8,7 +8,7 @@ import 'package:chopper/src/interceptors/request_converter_interceptor.dart'; import 'package:chopper/src/interceptors/response_converter_interceptor.dart'; import 'package:chopper/src/request.dart'; import 'package:chopper/src/response.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:test/test.dart'; void main() { diff --git a/chopper/test/chain/request_converter_interceptor_test.dart b/chopper/test/chain/request_converter_interceptor_test.dart index dede0994..671010aa 100644 --- a/chopper/test/chain/request_converter_interceptor_test.dart +++ b/chopper/test/chain/request_converter_interceptor_test.dart @@ -7,7 +7,7 @@ import 'package:chopper/src/interceptors/interceptor.dart'; import 'package:chopper/src/interceptors/request_converter_interceptor.dart'; import 'package:chopper/src/request.dart'; import 'package:chopper/src/response.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:test/test.dart'; void main() { diff --git a/chopper/test/chain/response_converter_interceptor_test.dart b/chopper/test/chain/response_converter_interceptor_test.dart index 41a3a968..2baebb25 100644 --- a/chopper/test/chain/response_converter_interceptor_test.dart +++ b/chopper/test/chain/response_converter_interceptor_test.dart @@ -7,7 +7,7 @@ import 'package:chopper/src/interceptors/interceptor.dart'; import 'package:chopper/src/interceptors/response_converter_interceptor.dart'; import 'package:chopper/src/request.dart'; import 'package:chopper/src/response.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:test/test.dart'; void main() { diff --git a/chopper/test/chopper_http_exception_test.dart b/chopper/test/chopper_http_exception_test.dart index 37417e7a..3ea4b489 100644 --- a/chopper/test/chopper_http_exception_test.dart +++ b/chopper/test/chopper_http_exception_test.dart @@ -1,6 +1,6 @@ import 'package:chopper/src/chopper_http_exception.dart'; import 'package:chopper/src/response.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:test/test.dart'; void main() { diff --git a/chopper/test/client_test.dart b/chopper/test/client_test.dart index b8e5497a..d358d2b1 100644 --- a/chopper/test/client_test.dart +++ b/chopper/test/client_test.dart @@ -3,8 +3,8 @@ import 'dart:convert'; import 'package:chopper/src/base.dart'; import 'package:chopper/src/converters.dart'; import 'package:chopper/src/interceptors/headers_interceptor.dart'; -import 'package:http/http.dart' as http; -import 'package:http/testing.dart'; +import 'package:cancellation_token_http/http.dart' as http; +import 'package:cancellation_token_http/testing.dart'; import 'package:test/test.dart'; final baseUrl = Uri.parse('http://localhost:8000'); diff --git a/chopper/test/converter_test.dart b/chopper/test/converter_test.dart index 17281cc3..a84016e1 100644 --- a/chopper/test/converter_test.dart +++ b/chopper/test/converter_test.dart @@ -4,8 +4,8 @@ import 'package:chopper/src/base.dart'; import 'package:chopper/src/converters.dart'; import 'package:chopper/src/request.dart'; import 'package:chopper/src/response.dart'; -import 'package:http/http.dart' as http; -import 'package:http/testing.dart'; +import 'package:cancellation_token_http/http.dart' as http; +import 'package:cancellation_token_http/testing.dart'; import 'package:test/test.dart'; import 'test_service.dart'; diff --git a/chopper/test/equatable_test.dart b/chopper/test/equatable_test.dart index 7bdebeae..eddc75ed 100644 --- a/chopper/test/equatable_test.dart +++ b/chopper/test/equatable_test.dart @@ -2,7 +2,7 @@ import 'dart:convert' show jsonEncode; import 'package:chopper/chopper.dart'; import 'package:faker/faker.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:test/test.dart'; import 'fixtures/http_response_fixture.dart' as http_fixture; diff --git a/chopper/test/fixtures/http_response_fixture.dart b/chopper/test/fixtures/http_response_fixture.dart index 96292abd..d9f78a84 100644 --- a/chopper/test/fixtures/http_response_fixture.dart +++ b/chopper/test/fixtures/http_response_fixture.dart @@ -1,7 +1,7 @@ import 'dart:convert' show jsonEncode; import 'package:data_fixture_dart/data_fixture_dart.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:meta/meta.dart'; import '../helpers/http_response_extension.dart'; diff --git a/chopper/test/fixtures/response_fixture.dart b/chopper/test/fixtures/response_fixture.dart index f894c77e..7acc9108 100644 --- a/chopper/test/fixtures/response_fixture.dart +++ b/chopper/test/fixtures/response_fixture.dart @@ -1,6 +1,6 @@ import 'package:chopper/chopper.dart' show Response; import 'package:data_fixture_dart/data_fixture_dart.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:meta/meta.dart'; import 'http_response_fixture.dart' as http_fixture; diff --git a/chopper/test/form_test.dart b/chopper/test/form_test.dart index 4f4a77a2..8567d921 100644 --- a/chopper/test/form_test.dart +++ b/chopper/test/form_test.dart @@ -1,7 +1,7 @@ import 'package:chopper/src/base.dart'; import 'package:chopper/src/converters.dart'; -import 'package:http/http.dart' as http; -import 'package:http/testing.dart'; +import 'package:cancellation_token_http/http.dart' as http; +import 'package:cancellation_token_http/testing.dart'; import 'package:test/test.dart'; import 'test_service.dart'; diff --git a/chopper/test/helpers/fake_chain.dart b/chopper/test/helpers/fake_chain.dart index c3ec8372..7b9f36f7 100644 --- a/chopper/test/helpers/fake_chain.dart +++ b/chopper/test/helpers/fake_chain.dart @@ -3,7 +3,7 @@ import 'dart:async'; import 'package:chopper/src/chain/chain.dart'; import 'package:chopper/src/request.dart'; import 'package:chopper/src/response.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; class FakeChain implements Chain { FakeChain(this.request, {this.response}); diff --git a/chopper/test/helpers/http_response_extension.dart b/chopper/test/helpers/http_response_extension.dart index 17094acf..2a628f08 100644 --- a/chopper/test/helpers/http_response_extension.dart +++ b/chopper/test/helpers/http_response_extension.dart @@ -1,4 +1,4 @@ -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; extension HttpResponseExtension on http.Response { http.Response copyWith({ diff --git a/chopper/test/http_logging_interceptor_test.dart b/chopper/test/http_logging_interceptor_test.dart index 22dc5799..fd8b760b 100644 --- a/chopper/test/http_logging_interceptor_test.dart +++ b/chopper/test/http_logging_interceptor_test.dart @@ -2,7 +2,7 @@ import 'package:chopper/src/interceptors/http_logging_interceptor.dart'; import 'package:chopper/src/request.dart'; import 'package:chopper/src/response.dart'; import 'package:chopper/src/utils.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:test/test.dart'; import 'helpers/fake_chain.dart'; diff --git a/chopper/test/interceptors_test.dart b/chopper/test/interceptors_test.dart index 87567951..334a9911 100644 --- a/chopper/test/interceptors_test.dart +++ b/chopper/test/interceptors_test.dart @@ -6,8 +6,8 @@ import 'package:chopper/src/interceptors/interceptor.dart'; import 'package:chopper/src/request.dart'; import 'package:chopper/src/response.dart'; import 'package:chopper/src/utils.dart'; -import 'package:http/http.dart' as http; -import 'package:http/testing.dart'; +import 'package:cancellation_token_http/http.dart' as http; +import 'package:cancellation_token_http/testing.dart'; import 'package:test/test.dart'; import 'helpers/fake_chain.dart'; diff --git a/chopper/test/json_test.dart b/chopper/test/json_test.dart index 640ece6d..6d4bb88d 100644 --- a/chopper/test/json_test.dart +++ b/chopper/test/json_test.dart @@ -2,8 +2,8 @@ import 'dart:convert'; import 'package:chopper/src/base.dart'; import 'package:chopper/src/converters.dart'; -import 'package:http/http.dart' as http; -import 'package:http/testing.dart'; +import 'package:cancellation_token_http/http.dart' as http; +import 'package:cancellation_token_http/testing.dart'; import 'package:test/test.dart'; import 'test_service.dart'; diff --git a/chopper/test/multipart_test.dart b/chopper/test/multipart_test.dart index 34a66b00..4479255f 100644 --- a/chopper/test/multipart_test.dart +++ b/chopper/test/multipart_test.dart @@ -2,8 +2,8 @@ import 'package:chopper/src/base.dart'; import 'package:chopper/src/constants.dart'; import 'package:chopper/src/converters.dart'; import 'package:chopper/src/request.dart'; -import 'package:http/http.dart' as http; -import 'package:http/testing.dart'; +import 'package:cancellation_token_http/http.dart' as http; +import 'package:cancellation_token_http/testing.dart'; import 'package:http_parser/http_parser.dart'; import 'package:test/test.dart'; import 'package:transparent_image/transparent_image.dart'; diff --git a/chopper/test/request_test.dart b/chopper/test/request_test.dart index 45d9e2e0..1973cff8 100644 --- a/chopper/test/request_test.dart +++ b/chopper/test/request_test.dart @@ -2,7 +2,7 @@ import 'package:chopper/chopper.dart'; import 'package:collection/collection.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:test/test.dart'; void main() { diff --git a/chopper/test/response_test.dart b/chopper/test/response_test.dart index 201d3cb4..1fb1fdbc 100644 --- a/chopper/test/response_test.dart +++ b/chopper/test/response_test.dart @@ -1,6 +1,6 @@ import 'package:chopper/src/chopper_http_exception.dart'; import 'package:chopper/src/response.dart'; -import 'package:http/http.dart' as http; +import 'package:cancellation_token_http/http.dart' as http; import 'package:test/test.dart'; import 'fixtures/error_fixtures.dart'; diff --git a/chopper/test/test_service.chopper.dart b/chopper/test/test_service.chopper.dart index 6d3f5585..04f1624e 100644 --- a/chopper/test/test_service.chopper.dart +++ b/chopper/test/test_service.chopper.dart @@ -32,7 +32,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, headers: $headers, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -43,7 +46,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -54,7 +60,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -65,7 +74,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - return client.send>, int>($request); + return client.send>, int>( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -76,7 +88,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -87,7 +102,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -108,7 +126,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -121,7 +142,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -138,7 +162,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -159,7 +186,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -180,7 +210,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -193,7 +226,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -206,7 +242,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, body: $body, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -219,7 +258,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, body: $body, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -232,7 +274,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, body: $body, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -248,7 +293,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, body: $body, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -263,7 +311,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, headers: $headers, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -279,7 +330,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, body: $body, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -292,7 +346,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, body: $body, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -307,7 +364,7 @@ final class _$HttpTestService extends HttpTestService { ); return client.send( $request, - requestConverter: convertForm, + cancellationToken: client.cancellationToken, ); } @@ -325,7 +382,10 @@ final class _$HttpTestService extends HttpTestService { body: $body, headers: $headers, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -346,7 +406,7 @@ final class _$HttpTestService extends HttpTestService { ); return client.send( $request, - requestConverter: convertForm, + cancellationToken: client.cancellationToken, ); } @@ -362,8 +422,7 @@ final class _$HttpTestService extends HttpTestService { ); return client.send( $request, - requestConverter: customConvertRequest, - responseConverter: customConvertResponse, + cancellationToken: client.cancellationToken, ); } @@ -390,7 +449,10 @@ final class _$HttpTestService extends HttpTestService { parts: $parts, multipart: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -409,7 +471,10 @@ final class _$HttpTestService extends HttpTestService { parts: $parts, multipart: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -428,7 +493,10 @@ final class _$HttpTestService extends HttpTestService { parts: $parts, multipart: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -454,7 +522,10 @@ final class _$HttpTestService extends HttpTestService { parts: $parts, multipart: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -473,7 +544,10 @@ final class _$HttpTestService extends HttpTestService { parts: $parts, multipart: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -509,7 +583,10 @@ final class _$HttpTestService extends HttpTestService { parts: $parts, multipart: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -520,7 +597,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -531,7 +611,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - return client.send, String>($request); + return client.send, String>( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -542,7 +625,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -564,7 +650,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, includeNullQueryVars: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -577,7 +666,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -592,7 +684,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, useBrackets: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -607,7 +702,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.brackets, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -622,7 +720,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.indices, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -637,7 +738,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.repeat, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -651,7 +755,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.comma, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -664,7 +771,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -679,7 +789,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, includeNullQueryVars: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -694,7 +807,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, useBrackets: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -709,7 +825,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.brackets, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -724,7 +843,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.indices, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -739,7 +861,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.repeat, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -754,7 +879,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.comma, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -767,7 +895,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -792,7 +923,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, headers: $headers, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -817,7 +951,7 @@ final class _$HttpTestService extends HttpTestService { ); return client.send( $request, - requestConverter: FormUrlEncodedConverter.requestFactory, + cancellationToken: client.cancellationToken, ); } @@ -830,7 +964,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, ); return client - .send($request) + .send( + $request, + cancellationToken: client.cancellationToken, + ) .timeout(const Duration(microseconds: 42000000)); } @@ -843,7 +980,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, ); return client - .send($request) + .send( + $request, + cancellationToken: client.cancellationToken, + ) .timeout(const Duration(microseconds: 0)); } @@ -856,7 +996,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, ); return client - .send($request) + .send( + $request, + cancellationToken: client.cancellationToken, + ) .timeout(const Duration(microseconds: 0)); } } diff --git a/chopper/test/test_service.dart b/chopper/test/test_service.dart index fc277049..29b0f481 100644 --- a/chopper/test/test_service.dart +++ b/chopper/test/test_service.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:chopper/chopper.dart'; -import 'package:http/http.dart' show MultipartFile; +import 'package:cancellation_token_http/http.dart' show MultipartFile; import 'fixtures/example_enum.dart'; diff --git a/chopper/test/test_service_base_url.chopper.dart b/chopper/test/test_service_base_url.chopper.dart index 262d72c7..a5d1f1dc 100644 --- a/chopper/test/test_service_base_url.chopper.dart +++ b/chopper/test/test_service_base_url.chopper.dart @@ -25,7 +25,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { $url, client.baseUrl, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -36,7 +39,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { $url, client.baseUrl, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -47,7 +53,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { $url, client.baseUrl, ); - return client.send, String>($request); + return client.send, String>( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -70,7 +79,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { parameters: $params, includeNullQueryVars: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -83,7 +95,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -99,7 +114,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { parameters: $params, useBrackets: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -115,7 +133,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { parameters: $params, listFormat: ListFormat.brackets, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -131,7 +152,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { parameters: $params, listFormat: ListFormat.indices, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -147,7 +171,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { parameters: $params, listFormat: ListFormat.repeat, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -162,7 +189,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { parameters: $params, listFormat: ListFormat.comma, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -175,7 +205,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -191,7 +224,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { parameters: $params, includeNullQueryVars: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -207,7 +243,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { parameters: $params, useBrackets: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -223,7 +262,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { parameters: $params, listFormat: ListFormat.brackets, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -239,7 +281,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { parameters: $params, listFormat: ListFormat.indices, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -255,7 +300,10 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { parameters: $params, listFormat: ListFormat.repeat, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -271,6 +319,9 @@ final class _$HttpTestServiceBaseUrl extends HttpTestServiceBaseUrl { parameters: $params, listFormat: ListFormat.comma, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } } diff --git a/chopper/test/test_service_variable.chopper.dart b/chopper/test/test_service_variable.chopper.dart index c60e766e..b8fbdcfe 100644 --- a/chopper/test/test_service_variable.chopper.dart +++ b/chopper/test/test_service_variable.chopper.dart @@ -32,7 +32,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, headers: $headers, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -43,7 +46,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { $url, client.baseUrl, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -54,7 +60,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { $url, client.baseUrl, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -65,7 +74,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { $url, client.baseUrl, ); - return client.send>, int>($request); + return client.send>, int>( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -76,7 +88,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { $url, client.baseUrl, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -87,7 +102,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { $url, client.baseUrl, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -108,7 +126,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -121,7 +142,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -138,7 +162,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -159,7 +186,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -180,7 +210,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -193,7 +226,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -206,7 +242,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, body: $body, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -219,7 +258,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, body: $body, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -232,7 +274,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, body: $body, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -248,7 +293,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, body: $body, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -263,7 +311,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, headers: $headers, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -279,7 +330,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, body: $body, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -292,7 +346,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, body: $body, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -307,7 +364,7 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { ); return client.send( $request, - requestConverter: convertForm, + cancellationToken: client.cancellationToken, ); } @@ -325,7 +382,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { body: $body, headers: $headers, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -346,7 +406,7 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { ); return client.send( $request, - requestConverter: convertForm, + cancellationToken: client.cancellationToken, ); } @@ -362,8 +422,7 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { ); return client.send( $request, - requestConverter: customConvertRequest, - responseConverter: customConvertResponse, + cancellationToken: client.cancellationToken, ); } @@ -390,7 +449,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parts: $parts, multipart: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -409,7 +471,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parts: $parts, multipart: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -428,7 +493,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parts: $parts, multipart: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -454,7 +522,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parts: $parts, multipart: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -473,7 +544,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parts: $parts, multipart: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -509,7 +583,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parts: $parts, multipart: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -520,7 +597,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { $url, client.baseUrl, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -531,7 +611,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { $url, client.baseUrl, ); - return client.send, String>($request); + return client.send, String>( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -542,7 +625,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { $url, client.baseUrl, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -565,7 +651,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parameters: $params, includeNullQueryVars: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -578,7 +667,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -594,7 +686,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parameters: $params, useBrackets: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -609,7 +704,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parameters: $params, listFormat: ListFormat.brackets, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -624,7 +722,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parameters: $params, listFormat: ListFormat.indices, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -639,7 +740,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parameters: $params, listFormat: ListFormat.repeat, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -653,7 +757,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parameters: $params, listFormat: ListFormat.comma, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -666,7 +773,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { client.baseUrl, parameters: $params, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -682,7 +792,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parameters: $params, includeNullQueryVars: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -698,7 +811,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parameters: $params, useBrackets: true, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -713,7 +829,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parameters: $params, listFormat: ListFormat.brackets, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -728,7 +847,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parameters: $params, listFormat: ListFormat.indices, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -743,7 +865,10 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parameters: $params, listFormat: ListFormat.repeat, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } @override @@ -758,6 +883,9 @@ final class _$HttpTestServiceVariable extends HttpTestServiceVariable { parameters: $params, listFormat: ListFormat.comma, ); - return client.send($request); + return client.send( + $request, + cancellationToken: client.cancellationToken, + ); } } diff --git a/chopper/test/test_service_variable.dart b/chopper/test/test_service_variable.dart index c878ada8..4aac5e4e 100644 --- a/chopper/test/test_service_variable.dart +++ b/chopper/test/test_service_variable.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:chopper/chopper.dart'; -import 'package:http/http.dart' show MultipartFile; +import 'package:cancellation_token_http/http.dart' show MultipartFile; part 'test_service_variable.chopper.dart'; diff --git a/chopper/test/test_without_response_service.chopper.dart b/chopper/test/test_without_response_service.chopper.dart index 2bc8fcbd..43d4eb9b 100644 --- a/chopper/test/test_without_response_service.chopper.dart +++ b/chopper/test/test_without_response_service.chopper.dart @@ -32,7 +32,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, headers: $headers, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -44,7 +47,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -56,7 +62,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -68,8 +77,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - final Response $response = - await client.send>, int>($request); + final Response $response = await client.send>, int>( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -81,7 +92,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -93,7 +107,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -115,7 +132,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -129,7 +149,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -147,7 +170,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -169,7 +195,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -191,7 +220,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -205,7 +237,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -219,7 +254,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, body: $body, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -233,7 +271,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, body: $body, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -247,7 +288,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, body: $body, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -264,7 +308,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, body: $body, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -280,7 +327,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, headers: $headers, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -297,7 +347,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, body: $body, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -311,7 +364,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, body: $body, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -327,7 +383,7 @@ final class _$HttpTestService extends HttpTestService { ); final Response $response = await client.send( $request, - requestConverter: convertForm, + cancellationToken: client.cancellationToken, ); return $response.bodyOrThrow; } @@ -346,7 +402,10 @@ final class _$HttpTestService extends HttpTestService { body: $body, headers: $headers, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -368,7 +427,7 @@ final class _$HttpTestService extends HttpTestService { ); final Response $response = await client.send( $request, - requestConverter: convertForm, + cancellationToken: client.cancellationToken, ); return $response.bodyOrThrow; } @@ -385,8 +444,7 @@ final class _$HttpTestService extends HttpTestService { ); final Response $response = await client.send( $request, - requestConverter: customConvertRequest, - responseConverter: customConvertResponse, + cancellationToken: client.cancellationToken, ); return $response.bodyOrThrow; } @@ -414,7 +472,10 @@ final class _$HttpTestService extends HttpTestService { parts: $parts, multipart: true, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -434,7 +495,10 @@ final class _$HttpTestService extends HttpTestService { parts: $parts, multipart: true, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -454,7 +518,10 @@ final class _$HttpTestService extends HttpTestService { parts: $parts, multipart: true, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -481,7 +548,10 @@ final class _$HttpTestService extends HttpTestService { parts: $parts, multipart: true, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -501,7 +571,10 @@ final class _$HttpTestService extends HttpTestService { parts: $parts, multipart: true, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -538,7 +611,10 @@ final class _$HttpTestService extends HttpTestService { parts: $parts, multipart: true, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -550,7 +626,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -562,8 +641,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - final Response $response = - await client.send, String>($request); + final Response $response = await client.send, String>( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -575,7 +656,10 @@ final class _$HttpTestService extends HttpTestService { $url, client.baseUrl, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -598,7 +682,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, includeNullQueryVars: true, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -612,7 +699,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -628,7 +718,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, useBrackets: true, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -643,7 +736,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.brackets, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -658,7 +754,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.indices, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -673,7 +772,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.repeat, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -688,7 +790,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.comma, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -702,7 +807,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, parameters: $params, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -718,7 +826,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, includeNullQueryVars: true, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -734,7 +845,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, useBrackets: true, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -750,7 +864,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.brackets, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -766,7 +883,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.indices, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -782,7 +902,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.repeat, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -798,7 +921,10 @@ final class _$HttpTestService extends HttpTestService { parameters: $params, listFormat: ListFormat.comma, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } @@ -824,7 +950,10 @@ final class _$HttpTestService extends HttpTestService { client.baseUrl, headers: $headers, ); - final Response $response = await client.send($request); + final Response $response = await client.send( + $request, + cancellationToken: client.cancellationToken, + ); return $response.bodyOrThrow; } } diff --git a/chopper/test/test_without_response_service.dart b/chopper/test/test_without_response_service.dart index d29c0eb9..1a031930 100644 --- a/chopper/test/test_without_response_service.dart +++ b/chopper/test/test_without_response_service.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:chopper/chopper.dart'; -import 'package:http/http.dart' show MultipartFile; +import 'package:cancellation_token_http/http.dart' show MultipartFile; part 'test_without_response_service.chopper.dart'; diff --git a/chopper_generator/lib/src/generator.dart b/chopper_generator/lib/src/generator.dart index 3a4f697c..6695e31c 100644 --- a/chopper_generator/lib/src/generator.dart +++ b/chopper_generator/lib/src/generator.dart @@ -433,21 +433,6 @@ final class ChopperGenerator final Map namedArguments = {}; - final ConstantReader? requestFactory = factoryConverter?.peek('request'); - if (requestFactory != null) { - final ExecutableElement? func = - requestFactory.objectValue.toFunctionValue(); - namedArguments['requestConverter'] = refer(_factoryForFunction(func!)); - } - - final ConstantReader? responseFactory = - factoryConverter?.peek('response'); - if (responseFactory != null) { - final ExecutableElement? func = - responseFactory.objectValue.toFunctionValue(); - namedArguments['responseConverter'] = refer(_factoryForFunction(func!)); - } - final List typeArguments = []; if (responseType != null) { typeArguments.addAll([ @@ -480,7 +465,7 @@ final class ChopperGenerator declareFinal( Vars.response.toString(), type: TypeReference( - (b) => b + (b) => b ..symbol = 'Response' ..types.add(responseTypeReference), ),