From dc5901b0394c0337f789e05c4466c53d0183d97b Mon Sep 17 00:00:00 2001 From: Alex Li Date: Sun, 10 Dec 2023 11:07:18 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20Add=20`redirects`=20in=20`IOStr?= =?UTF-8?q?eamedResponse`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/http/lib/src/io_client.dart | 1 + pkgs/http/lib/src/io_streamed_response.dart | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/pkgs/http/lib/src/io_client.dart b/pkgs/http/lib/src/io_client.dart index db66b028c4..ca0213290b 100644 --- a/pkgs/http/lib/src/io_client.dart +++ b/pkgs/http/lib/src/io_client.dart @@ -127,6 +127,7 @@ class IOClient extends BaseClient { request: request, headers: headers, isRedirect: response.isRedirect, + redirects: response.redirects, persistentConnection: response.persistentConnection, reasonPhrase: response.reasonPhrase, inner: response); diff --git a/pkgs/http/lib/src/io_streamed_response.dart b/pkgs/http/lib/src/io_streamed_response.dart index 95b818c2b3..b74a9232f1 100644 --- a/pkgs/http/lib/src/io_streamed_response.dart +++ b/pkgs/http/lib/src/io_streamed_response.dart @@ -23,9 +23,16 @@ class IOStreamedResponse extends StreamedResponse { super.isRedirect, super.persistentConnection, super.reasonPhrase, + this.redirects = const [], HttpClientResponse? inner}) : _inner = inner; + /// Returns the series of redirects this connection has been through. + /// The list will be empty if no redirects were followed. + /// [redirects] will be updated both in the case of + /// an automatic and a manual redirect. + final List redirects; + /// Detaches the underlying socket from the HTTP server. /// /// Will throw if `inner` was not set or `null` when `this` was created. From 9a7ed956d6b1401cc8847f552f5ea88869a5a975 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Sun, 10 Dec 2023 11:29:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=85=20Add=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/http/test/io/request_test.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkgs/http/test/io/request_test.dart b/pkgs/http/test/io/request_test.dart index ac6b44c3fd..65503ae1f0 100644 --- a/pkgs/http/test/io/request_test.dart +++ b/pkgs/http/test/io/request_test.dart @@ -5,7 +5,10 @@ @TestOn('vm') library; +import 'dart:io'; + import 'package:http/http.dart' as http; +import 'package:http/io_client.dart' as http_io; import 'package:test/test.dart'; import '../utils.dart'; @@ -65,4 +68,14 @@ void main() { throwsA(isA() .having((e) => e.message, 'message', 'Redirect limit exceeded'))); }); + + test('contains redirects', () async { + var ioClient = HttpClient(); + var client = http_io.IOClient(ioClient); + var request = http.Request('GET', serverUrl.resolve('/redirect')); + var response = await client.send(request); + expect(response.statusCode, equals(200)); + expect(response.redirects.length, equals(1)); + expect(response.redirects.first.location, serverUrl.resolve('/')); + }); } From 09a0a71ceb8ae53d03f7f3741b3a6aeffe5a65b0 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Tue, 12 Dec 2023 10:31:45 +0800 Subject: [PATCH 3/3] Update CHANGELOG.md --- pkgs/http/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/http/CHANGELOG.md b/pkgs/http/CHANGELOG.md index 9bbbb05a2d..650b3e3a2b 100644 --- a/pkgs/http/CHANGELOG.md +++ b/pkgs/http/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.3-wip + +* Add `redirects` in `IOStreamedResponse`. + ## 1.1.2 * Allow `web: '>=0.3.0 <0.5.0'`.