-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[http2] Fix Http2Adapter not redirecting for relative URLs (#2101)
Fixes a redirect bug discovered during #2077 where the adapter would fail to properly redirect if the location header contains a relative URL. <!-- Write down your pull request descriptions. --> ### New Pull Request Checklist - [x] I have read the [Documentation](https://pub.dev/documentation/dio/latest/) - [x] I have searched for a similar pull request in the [project](https://github.com/cfug/dio/pulls) and found none - [x] I have updated this branch with the latest `main` branch to avoid conflicts (via merge from master or rebase) - [x] I have added the required tests to prove the fix/feature I'm adding - [x] I have updated the documentation (if necessary) - [x] I have run the tests without failures - [x] I have updated the `CHANGELOG.md` in the corresponding package ### Additional context and info (if any) <!-- Provide more context and info about the PR. -->
- Loading branch information
Showing
8 changed files
with
128 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ environment: | |
|
||
dependencies: | ||
http2: ^2.1.0 | ||
meta: ^1.9.1 | ||
dio: ^5.2.0 | ||
|
||
dev_dependencies: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
@TestOn('vm') | ||
import 'dart:io'; | ||
|
||
import 'package:crypto/crypto.dart'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'package:dio_http2_adapter/dio_http2_adapter.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group(Http2Adapter.resolveRedirectUri, () { | ||
test('empty location', () async { | ||
final current = Uri.parse('https://example.com'); | ||
final result = Http2Adapter.resolveRedirectUri( | ||
current, | ||
Uri.parse(''), | ||
); | ||
|
||
expect(result, current.toString()); | ||
}); | ||
|
||
test('relative location 1', () async { | ||
final result = Http2Adapter.resolveRedirectUri( | ||
Uri.parse('https://example.com/foo'), | ||
Uri.parse('/bar'), | ||
); | ||
|
||
expect(result, 'https://example.com/bar'); | ||
}); | ||
|
||
test('relative location 2', () async { | ||
final result = Http2Adapter.resolveRedirectUri( | ||
Uri.parse('https://example.com/foo'), | ||
Uri.parse('../bar'), | ||
); | ||
|
||
expect(result, 'https://example.com/bar'); | ||
}); | ||
|
||
test('different location', () async { | ||
final current = Uri.parse('https://example.com/foo'); | ||
final target = 'https://somewhere.com/bar'; | ||
final result = Http2Adapter.resolveRedirectUri( | ||
current, | ||
Uri.parse(target), | ||
); | ||
|
||
expect(result, target); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
@TestOn('vm') | ||
import 'dart:io'; | ||
|
||
import 'package:dio/dio.dart'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
@TestOn('vm') | ||
import 'dart:async'; | ||
|
||
import 'package:dio/dio.dart'; | ||
|