diff --git a/plugins/http2_adapter/CHANGELOG.md b/plugins/http2_adapter/CHANGELOG.md index 3b49c2e88..8e3ef62ce 100644 --- a/plugins/http2_adapter/CHANGELOG.md +++ b/plugins/http2_adapter/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Implement `sendTimeout` and `receiveTimeout` for the adapter. +- Fix redirect not working when requestStream is null. ## 2.3.1+1 diff --git a/plugins/http2_adapter/lib/src/http2_adapter.dart b/plugins/http2_adapter/lib/src/http2_adapter.dart index 6aa4ed822..e235d0e4a 100644 --- a/plugins/http2_adapter/lib/src/http2_adapter.dart +++ b/plugins/http2_adapter/lib/src/http2_adapter.dart @@ -129,7 +129,7 @@ class Http2Adapter implements HttpClientAdapter { if (status != null) { statusCode = int.parse(status); responseHeaders.removeAll(':status'); - needRedirect = list != null && _needRedirect(options, statusCode); + needRedirect = _needRedirect(options, statusCode); needResponse = !needRedirect && options.validateStatus(statusCode) || options.receiveDataWhenStatusError; @@ -182,7 +182,7 @@ class Http2Adapter implements HttpClientAdapter { ); return _fetch( options.copyWith(path: url, maxRedirects: --options.maxRedirects), - Stream.fromIterable(list!), + list != null ? Stream.fromIterable(list) : null, cancelFuture, redirects, ); diff --git a/plugins/http2_adapter/test/http2_test.dart b/plugins/http2_adapter/test/http2_test.dart index b3a777c58..bbe69fb0d 100644 --- a/plugins/http2_adapter/test/http2_test.dart +++ b/plugins/http2_adapter/test/http2_test.dart @@ -117,4 +117,13 @@ void main() { await dio.get('/drip?delay=1&numbytes=1'); }); + + test('request with redirect', () async { + final dio = Dio() + ..options.baseUrl = 'https://httpbun.com/' + ..httpClientAdapter = Http2Adapter(ConnectionManager()); + + final res = await dio.get('absolute-redirect/2'); + expect(res.statusCode, 200); + }); }