-
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.
Fix return type of OnHttpClientCreate (cfug#1812)
The return type of `OnHttpClientCreate` has been changed from `HttpClient?` to `HttpClient`. While technically a breaking change, it is considered a bug because the callback was actually a no-op when the provided client was modified but not returned. Fixes 1. of cfug#1811 ### 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) - [ ] 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
- Loading branch information
Showing
11 changed files
with
85 additions
and
38 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
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,20 +1,39 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:dio/dio.dart'; | ||
import 'package:dio/io.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group(HttpClientAdapter, () { | ||
test( | ||
'IOHttpClientAdapter.onHttpClientCreate is only executed once per request', | ||
() async { | ||
int onHttpClientCreateInvokeCount = 0; | ||
final dio = Dio(); | ||
dio.httpClientAdapter = IOHttpClientAdapter(onHttpClientCreate: (client) { | ||
onHttpClientCreateInvokeCount++; | ||
return client; | ||
group( | ||
IOHttpClientAdapter, | ||
() { | ||
test('onHttpClientCreate is only executed once per request', () async { | ||
int onHttpClientCreateInvokeCount = 0; | ||
final dio = Dio(); | ||
dio.httpClientAdapter = IOHttpClientAdapter( | ||
onHttpClientCreate: (client) { | ||
onHttpClientCreateInvokeCount++; | ||
return client; | ||
}, | ||
); | ||
await dio.get('https://pub.dev'); | ||
expect(onHttpClientCreateInvokeCount, 1); | ||
}); | ||
|
||
test('createHttpClientCount is only executed once per request', () async { | ||
int createHttpClientCount = 0; | ||
final dio = Dio(); | ||
dio.httpClientAdapter = IOHttpClientAdapter( | ||
createHttpClient: () { | ||
createHttpClientCount++; | ||
return HttpClient(); | ||
}, | ||
); | ||
await dio.get('https://pub.dev'); | ||
expect(createHttpClientCount, 1); | ||
}); | ||
await dio.get('https://pub.dev'); | ||
expect(onHttpClientCreateInvokeCount, 1); | ||
}); | ||
}); | ||
}, | ||
testOn: 'vm', | ||
); | ||
} |
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
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