From b8bed260d7e0779fc87f4757ab4ee28479fe7e53 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Tue, 9 Jan 2024 18:22:58 -0800 Subject: [PATCH] s/BaseResposeV2/BaseResponseWithUrl --- pkgs/http/CHANGELOG.md | 2 +- pkgs/http/lib/src/base_request.dart | 4 ++-- pkgs/http/lib/src/base_response.dart | 14 ++++++++------ pkgs/http/lib/src/io_client.dart | 3 ++- pkgs/http/lib/src/streamed_response.dart | 2 +- pkgs/http/test/io/request_test.dart | 6 +++--- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/pkgs/http/CHANGELOG.md b/pkgs/http/CHANGELOG.md index c2987adc38..a52b584c0e 100644 --- a/pkgs/http/CHANGELOG.md +++ b/pkgs/http/CHANGELOG.md @@ -1,7 +1,7 @@ ## 1.2.0 * Add `MockClient.pngResponse`, which makes it easier to fake image responses. -* Added the ability to fetch the URL of the response through `BaseResponseV2`. +* Added the ability to fetch the URL of the response through `BaseResponseWithUrl`. ## 1.1.2 diff --git a/pkgs/http/lib/src/base_request.dart b/pkgs/http/lib/src/base_request.dart index ece1541783..3125178a93 100644 --- a/pkgs/http/lib/src/base_request.dart +++ b/pkgs/http/lib/src/base_request.dart @@ -133,13 +133,13 @@ abstract class BaseRequest { var response = await client.send(this); var stream = onDone(response.stream, client.close); - if (response is BaseResponseV2) { + if (response is BaseResponseWithUrl) { return StreamedResponseV2(ByteStream(stream), response.statusCode, contentLength: response.contentLength, request: response.request, headers: response.headers, isRedirect: response.isRedirect, - url: (response as BaseResponseV2).url, + url: (response as BaseResponseWithUrl).url, persistentConnection: response.persistentConnection, reasonPhrase: response.reasonPhrase); } else { diff --git a/pkgs/http/lib/src/base_response.dart b/pkgs/http/lib/src/base_response.dart index 89d66e80f1..0e7a0ee9a3 100644 --- a/pkgs/http/lib/src/base_response.dart +++ b/pkgs/http/lib/src/base_response.dart @@ -72,11 +72,10 @@ abstract class BaseResponse { } } -/// Fields and methods that will be added to [BaseResponse] when `package:http` -/// version 2 is released. +/// A [BaseResponse] with a [url] field. /// /// [Client] methods that return a [BaseResponse] subclass, such as [Response] -/// or [StreamedResponse], **may** return a [BaseResponseV2]. +/// or [StreamedResponse], **may** return a [BaseResponseWithUrl]. /// /// For example: /// @@ -84,13 +83,16 @@ abstract class BaseResponse { /// final client = Client(); /// final response = client.get(Uri.https('example.com', '/')); /// Uri? finalUri; -/// if (response is BaseResponseV2) { -/// finalUri = (response as BaseResponseV2).uri; +/// if (response is BaseResponseWithUrl) { +/// finalUri = (response as BaseResponseWithUrl).url; /// } /// // Do something with `finalUri`. /// client.close(); /// ``` -mixin BaseResponseV2 on BaseResponse { +/// +/// [url] will be added to [BaseResponse] when `package:http` version 2 is +/// released and this mixin will be deprecated. +mixin BaseResponseWithUrl on BaseResponse { /// The [Uri] of the response returned by the server. /// /// If no redirects were followed, [url] will be the same as the requested diff --git a/pkgs/http/lib/src/io_client.dart b/pkgs/http/lib/src/io_client.dart index 70164090e9..ef9d7318f8 100644 --- a/pkgs/http/lib/src/io_client.dart +++ b/pkgs/http/lib/src/io_client.dart @@ -47,7 +47,8 @@ class _ClientSocketException extends ClientException String toString() => 'ClientException with $cause, uri=$uri'; } -class _IOStreamedResponseV2 extends IOStreamedResponse with BaseResponseV2 { +class _IOStreamedResponseV2 extends IOStreamedResponse + with BaseResponseWithUrl { @override final Uri? url; diff --git a/pkgs/http/lib/src/streamed_response.dart b/pkgs/http/lib/src/streamed_response.dart index 2d6f61ff35..4b81f67fb4 100644 --- a/pkgs/http/lib/src/streamed_response.dart +++ b/pkgs/http/lib/src/streamed_response.dart @@ -29,7 +29,7 @@ class StreamedResponse extends BaseResponse { /// This class is private to `package:http` and will be removed when /// `package:http` v2 is released. -class StreamedResponseV2 extends StreamedResponse with BaseResponseV2 { +class StreamedResponseV2 extends StreamedResponse with BaseResponseWithUrl { @override final Uri? url; diff --git a/pkgs/http/test/io/request_test.dart b/pkgs/http/test/io/request_test.dart index b07a0f4898..90caaaa718 100644 --- a/pkgs/http/test/io/request_test.dart +++ b/pkgs/http/test/io/request_test.dart @@ -46,8 +46,8 @@ void main() { final response = await request.send(); expect(response.statusCode, equals(302)); - expect( - (response as http.BaseResponseV2).url, serverUrl.resolve('/redirect')); + expect((response as http.BaseResponseWithUrl).url, + serverUrl.resolve('/redirect')); }); test('with redirects', () async { @@ -56,7 +56,7 @@ void main() { expect(response.statusCode, equals(200)); final bytesString = await response.stream.bytesToString(); expect(bytesString, parse(containsPair('path', '/'))); - expect((response as http.BaseResponseV2).url, serverUrl.resolve('/')); + expect((response as http.BaseResponseWithUrl).url, serverUrl.resolve('/')); }); test('exceeding max redirects', () async {