-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[http2_adapter] HTTP/2 proxy (cfug#1386)
### New Pull Request Checklist - [X] I have read the [Documentation](https://pub.dartlang.org/packages/dio) - [X] I have searched for a similar pull request in the [project](https://github.com/flutterchina/dio/pulls) and found none - [X] I have updated this branch with the latest `develop` to avoid conflicts (via merge from master or rebase) - [x] I have added the required tests to prove the fix/feature I am adding - [X] I have updated the documentation (if necessary) - [X] I have run the tests and they pass This merge request fixes / refers to the following issues: cfug#1259 cfug#905 ### Pull Request Description Added proxy tunnel to http2 adaptor --------- Signed-off-by: Alexey Z <[email protected]> Signed-off-by: Alex Li <[email protected]> Co-authored-by: Alexey Zdorovykh <[email protected]> Co-authored-by: Alex Li <[email protected]>
- Loading branch information
1 parent
ae90d7d
commit 7664127
Showing
7 changed files
with
166 additions
and
33 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 |
---|---|---|
|
@@ -19,20 +19,52 @@ dependencies: | |
import 'package:dio/dio.dart'; | ||
import 'package:dio_http2_adapter/dio_http2_adapter.dart'; | ||
|
||
void main() async { | ||
final dio = Dio() | ||
..options.baseUrl = 'https://pub.dev' | ||
..interceptors.add(LogInterceptor()) | ||
..httpClientAdapter = Http2Adapter( | ||
ConnectionManager(idleTimeout: Duration(seconds: 10)), | ||
); | ||
|
||
Response<String> response; | ||
response = await dio.get('/?xx=6'); | ||
for (final e in response.redirects) { | ||
print('redirect: ${e.statusCode} ${e.location}'); | ||
} | ||
print(response.data); | ||
} | ||
``` | ||
|
||
### Ignoring a bad certificate | ||
|
||
```dart | ||
void main() async { | ||
final dio = Dio() | ||
..options.baseUrl = 'https://pub.dev' | ||
..interceptors.add(LogInterceptor()) | ||
..httpClientAdapter = Http2Adapter( | ||
ConnectionManager( | ||
idleTimeout: 10000, | ||
// Ignore bad certificate | ||
idleTimeout: Duration(seconds: 10), | ||
onClientCreate: (_, config) => config.onBadCertificate = (_) => true, | ||
), | ||
); | ||
final response = await dio.get('/?xx=something'); | ||
print(response.data?.length); | ||
print(response.redirects.length); | ||
print(response.data); | ||
} | ||
``` | ||
|
||
### Configuring the proxy | ||
|
||
```dart | ||
void main() async { | ||
final dio = Dio() | ||
..options.baseUrl = 'https://pub.dev' | ||
..interceptors.add(LogInterceptor()) | ||
..httpClientAdapter = Http2Adapter( | ||
ConnectionManager( | ||
idleTimeout: Duration(seconds: 10), | ||
onClientCreate: (_, config) => | ||
config.proxy = Uri.parse('http://login:[email protected]:8888'), | ||
), | ||
); | ||
} | ||
``` |
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
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