Skip to content

Commit 8f2be2d

Browse files
authored
Merge pull request #58 from CodingAleCR/develop
0.4.0: Flutter Web, Null-safety, Injectable Client
2 parents 15e37ed + a8a883e commit 8f2be2d

39 files changed

+496
-277
lines changed

CHANGELOG.md

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,75 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- ❗️🛠  Changed: Renamed `HttpClientWithInterceptor` to `InterceptedClient`.
6+
- ❗️🛠  Changed: Renamed `HttpWithInterceptor` to `InterceptedHttp`.
7+
-  Added: Response Transformation (useful for background json decoding/encoding).
8+
-  Added: Support for multipart requests.
9+
- 80% code coverage
10+
11+
## 0.4.0
12+
13+
Check out [our 0.4.0 migration guide](./guides/migration_guide_4.md) for information on how to migrate your code.
14+
15+
- ❗️✨  Added: String extension to allow `toUri()` usage when importing the library. Since `http` dropped support for string url usage and since Dart does not yet support function overloading, we had to implement an alternative through extensions.
16+
-  Added: Flutter web support 🌐   (`badCertificateCallback` and `findProxy` features are not supported on Flutter Web due to browser limitations)
17+
- 🛠  Changed: Upgraded `http` to `0.13.0`.
18+
- 🛠  Changed: Upgraded `effective_dart` to `1.3.0`.
19+
- 🛠&nbsp;&nbsp;Changed: Upgraded Dart `sdk` to `>=2.12.0 <3.0.0`. (Yay! Sound null safety! 🎉)
20+
- 🗑&nbsp;&nbsp;Removed: `meta` is removed since Dart's null safety now covers all uses inside this plugin
21+
322
## 0.3.3
423

5-
* Changed: Plugin no longer depends on the `flutter/foundation.dart`, instead it uses `meta` plugin which allows for usage on non flutter environments.
6-
* Changed: README now features a contribution and a roadmap sections for improving visibility on the project's future.
7-
* Changed: `badCertificateCallback` is now available to use without the experimental tag.
24+
- 🛠&nbsp;&nbsp;Changed: Plugin no longer depends on the `flutter/foundation.dart`, instead it uses `meta` plugin which allows for usage on non flutter environments.
25+
- 🛠&nbsp;&nbsp;Changed: README now features a contribution and a roadmap sections for improving visibility on the project's future.
26+
- 🛠&nbsp;&nbsp;Changed: `badCertificateCallback` is now available to use without the experimental tag.
827

928
## 0.3.2
1029

11-
* Changed: Example now showcases exception handling.
12-
* Changed: README now showcases exception handling.
13-
* Fixed: Interceptor no longer using custom exceptions, instead it rethrows in the case that the retry policy is not set or if it has reached max attempts.
30+
- 🛠&nbsp;&nbsp;Changed: Example now showcases exception handling.
31+
- 🛠&nbsp;&nbsp;Changed: README now showcases exception handling.
32+
- 🐞&nbsp;&nbsp;Fixed: Interceptor no longer using custom exceptions, instead it rethrows in the case that the retry policy is not set or if it has reached max attempts.
1433

1534
## 0.3.1
1635

17-
* Fixed: Retry Policy's `shouldAttemptRetryOnResponse` was synchronous which would not allow async token updates.
18-
* Fixed: Retry Policy would only trigger once when using `HttpClientWithInterceptor`.
19-
* Fixed: Retry Policy would use the `http` Response class, which would force plugin users to add http plugin separately.
20-
* Experimental: `badCertificateCallback` allows you to use self-signing certificates.
36+
- 🐞&nbsp;&nbsp;Fixed: Retry Policy's `shouldAttemptRetryOnResponse` was synchronous which would not allow async token updates.
37+
- 🐞&nbsp;&nbsp;Fixed: Retry Policy would only trigger once when using `HttpClientWithInterceptor`.
38+
- 🐞&nbsp;&nbsp;Fixed: Retry Policy would use the `http` Response class, which would force plugin users to add http plugin separately.
39+
- 🧪&nbsp;&nbsp;Experimental: `badCertificateCallback` allows you to use self-signing certificates.
2140

2241
## 0.3.0
2342

24-
* Added: RetryPolicy. It allows to attempt retries on a request when an exception occurs or when a condition from the response is met.
25-
* Fixed: URI type urls not concatenating parameters.
43+
-&nbsp;&nbsp;Added: RetryPolicy. It allows to attempt retries on a request when an exception occurs or when a condition from the response is met.
44+
- 🐞&nbsp;&nbsp;Fixed: URI type urls not concatenating parameters.
2645

2746
## 0.2.0
2847

29-
* Added: Unit testing for a few of the files.
30-
* Modified: Android and iOS projects both in the plugin and the example now use Kotlin/Swift.
31-
* Modified: Android projects both in the plugin and the example now use AndroidX namespaces.
32-
* Fixed: Last '&' character was not removed from parametized URLs.
33-
* Fixed: Duplicate GET parameters when using `get`.
48+
-&nbsp;&nbsp;Added: Unit testing for a few of the files.
49+
- 🛠&nbsp;&nbsp;Changed: Android and iOS projects both in the plugin and the example now use Kotlin/Swift.
50+
- 🛠&nbsp;&nbsp;Changed: Android projects both in the plugin and the example now use AndroidX namespaces.
51+
- 🐞&nbsp;&nbsp;Fixed: Last ' ' character was not removed from parametized URLs.
52+
- 🐞&nbsp;&nbsp;Fixed: Duplicate GET parameters when using `get`.
3453

3554
## 0.1.1
3655

37-
* Fixed: HTTP Methods have misaligned parameters. Now they are called via named parameters to avoid type mismatch exceptions when being used.
56+
- 🐞&nbsp;&nbsp;Fixed: HTTP Methods have misaligned parameters. Now they are called via named parameters to avoid type mismatch exceptions when being used.
3857

3958
## 0.1.0
4059

41-
* Added: Query Parameters to GET requests, it allows you to set proper parameters without having to add them to the URL beforehand.
42-
* Modified: Documentation for the example to include the new Query Parameters usage.
60+
-&nbsp;&nbsp;Added: Query Parameters to GET requests, it allows you to set proper parameters without having to add them to the URL beforehand.
61+
- 🛠&nbsp;&nbsp;Changed: Documentation for the example to include the new Query Parameters usage.
4362

4463
## 0.0.3
4564

46-
* Added: Documentation for the example.
65+
-&nbsp;&nbsp;Added: Documentation for the example.
4766

4867
## 0.0.2
4968

50-
* Fixed: All the warnings regarding plugin publication.
69+
- 🐞&nbsp;&nbsp;Fixed: All the warnings regarding plugin publication.
5170

5271
## 0.0.1
5372

54-
* Added: Initial plugin implementation.
55-
* Added: Example of usage for the plugin.
56-
* Added: README.md and LICENSE files.
73+
-&nbsp;&nbsp;Added: Initial plugin implementation.
74+
-&nbsp;&nbsp;Added: Example of usage for the plugin.
75+
-&nbsp;&nbsp;Added: README.md and LICENSE files.

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ This is a plugin that lets you intercept the different requests and responses fr
1010

1111
## Quick Reference
1212

13+
**Already using `http_interceptor`? Check out the [0.4.0 migration guide](./guides/migration_guide_4.md) for quick reference on the changes made and how to migrate your code.**
14+
1315
- [Installation](#installation)
1416
- [Usage](#usage)
1517
- [Building your own interceptor](#building-your-own-interceptor)
@@ -25,7 +27,7 @@ This is a plugin that lets you intercept the different requests and responses fr
2527
Include the package with the latest version available in your `pubspec.yaml`.
2628

2729
```dart
28-
http_interceptor: any
30+
http_interceptor: ^0.4.0
2931
```
3032

3133
## Usage
@@ -44,13 +46,13 @@ In order to implement `http_interceptor` you need to implement the `InterceptorC
4446
class LoggingInterceptor implements InterceptorContract {
4547
@override
4648
Future<RequestData> interceptRequest({RequestData data}) async {
47-
print(data);
49+
print(data.toString());
4850
return data;
4951
}
5052
5153
@override
5254
Future<ResponseData> interceptResponse({ResponseData data}) async {
53-
print(data);
55+
print(data.toString());
5456
return data;
5557
}
5658
@@ -98,7 +100,7 @@ class WeatherRepository {
98100
var parsedWeather;
99101
try {
100102
final response =
101-
await client.get("$baseUrl/weather", params: {'id': "$id"});
103+
await client.get("$baseUrl/weather".toUri(), params: {'id': "$id"});
102104
if (response.statusCode == 200) {
103105
parsedWeather = json.decode(response.body);
104106
} else {
@@ -125,8 +127,11 @@ class WeatherRepository {
125127
Future<Map<String, dynamic>> fetchCityWeather(int id) async {
126128
var parsedWeather;
127129
try {
130+
WeatherApiInterceptor http = HttpWithInterceptor.build(interceptors: [
131+
Logger(),
132+
]);
128133
final response =
129-
await client.get("$baseUrl/weather", params: {'id': "$id"});
134+
await http.get("$baseUrl/weather".toUri(), params: {'id': "$id"});
130135
if (response.statusCode == 200) {
131136
parsedWeather = json.decode(response.body);
132137
} else {
@@ -170,9 +175,9 @@ class ExpiredTokenRetryPolicy extends RetryPolicy {
170175

171176
You can also set the maximum amount of retry attempts with `maxRetryAttempts` property or override the `shouldAttemptRetryOnException` if you want to retry the request after it failed with an exception.
172177

173-
### Using self signed certificates
178+
### Using self signed certificates (Only on iOS and Android)
174179

175-
This plugin allows you to override the default `badCertificateCallback` provided by Dart's `io` package, this is really useful when working with self-signed certificates in your server. This can be done by sending a the callback to the HttpInterceptor builder functions. This feature is marked as experimental and **might be subject to change before release 1.0.0 comes**.
180+
This plugin allows you to override the default `badCertificateCallback` provided by Dart's `io` package, this is really useful when working with self-signed certificates in your server. This can be done by sending a the callback to the HttpInterceptor builder functions. This feature is marked as experimental and **will be subject to change before release 1.0.0 comes**.
176181

177182
```dart
178183
class WeatherRepository {

example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OpenWeatherApp
22

3-
Demonstrates how to use the http_interceptor plugin.
3+
Demonstrates how to use the http_interceptor plugin. Due to CORS policies, this example does not fetch data when it is ran on Flutter Web, but it does work if you configure your own server properly or a proxy setup is used like the [CORS anywhere demo on Github](https://github.com/Rob--W/cors-anywhere).
44

55
## Getting Started
66

example/android/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ gradle-wrapper.jar
55
/gradlew.bat
66
/local.properties
77
GeneratedPluginRegistrant.java
8+
9+
# Remember to never publicly share your keystore.
10+
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
key.properties
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Modify this file to customize your launch splash screen -->
3+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="?android:colorBackground" />
5+
6+
<!-- You can insert your own image assets here -->
7+
<!-- <item>
8+
<bitmap
9+
android:gravity="center"
10+
android:src="@mipmap/launch_image" />
11+
</item> -->
12+
</layer-list>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
4+
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
5+
<!-- Show a splash screen on the activity. Automatically removed when
6+
Flutter draws its first frame -->
7+
<item name="android:windowBackground">@drawable/launch_background</item>
8+
</style>
9+
<!-- Theme applied to the Android Window as soon as the process has started.
10+
This theme determines the color of the Android Window while your
11+
Flutter UI initializes, as well as behind your Flutter UI while its
12+
running.
13+
14+
This Theme is only used starting with V2 of Flutter's Android embedding. -->
15+
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
16+
<item name="android:windowBackground">?android:colorBackground</item>
17+
</style>
18+
</resources>

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
1111
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
12-
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
13-
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1412
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
15-
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
16-
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1713
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
1814
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
1915
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
@@ -26,8 +22,6 @@
2622
dstPath = "";
2723
dstSubfolderSpec = 10;
2824
files = (
29-
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */,
30-
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */,
3125
);
3226
name = "Embed Frameworks";
3327
runOnlyForDeploymentPostprocessing = 0;
@@ -38,13 +32,11 @@
3832
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
3933
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
4034
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
41-
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
4235
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
4336
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
4437
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
4538
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
4639
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
47-
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; };
4840
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
4941
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
5042
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -57,8 +49,6 @@
5749
isa = PBXFrameworksBuildPhase;
5850
buildActionMask = 2147483647;
5951
files = (
60-
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
61-
3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
6252
);
6353
runOnlyForDeploymentPostprocessing = 0;
6454
};
@@ -68,9 +58,7 @@
6858
9740EEB11CF90186004384FC /* Flutter */ = {
6959
isa = PBXGroup;
7060
children = (
71-
3B80C3931E831B6300D905FE /* App.framework */,
7261
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
73-
9740EEBA1CF902C7004384FC /* Flutter.framework */,
7462
9740EEB21CF90195004384FC /* Debug.xcconfig */,
7563
7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
7664
9740EEB31CF90195004384FC /* Generated.xcconfig */,
@@ -201,7 +189,7 @@
201189
);
202190
runOnlyForDeploymentPostprocessing = 0;
203191
shellPath = /bin/sh;
204-
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin";
192+
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
205193
};
206194
9740EEB61CF901F6004384FC /* Run Script */ = {
207195
isa = PBXShellScriptBuildPhase;
@@ -253,7 +241,6 @@
253241
/* Begin XCBuildConfiguration section */
254242
249021D3217E4FDB00AE95B9 /* Profile */ = {
255243
isa = XCBuildConfiguration;
256-
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
257244
buildSettings = {
258245
ALWAYS_SEARCH_USER_PATHS = NO;
259246
CLANG_ANALYZER_NONNULL = YES;
@@ -330,7 +317,6 @@
330317
};
331318
97C147031CF9000F007C117D /* Debug */ = {
332319
isa = XCBuildConfiguration;
333-
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
334320
buildSettings = {
335321
ALWAYS_SEARCH_USER_PATHS = NO;
336322
CLANG_ANALYZER_NONNULL = YES;
@@ -386,7 +372,6 @@
386372
};
387373
97C147041CF9000F007C117D /* Release */ = {
388374
isa = XCBuildConfiguration;
389-
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
390375
buildSettings = {
391376
ALWAYS_SEARCH_USER_PATHS = NO;
392377
CLANG_ANALYZER_NONNULL = YES;

example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>PreviewsEnabled</key>
6+
<false/>
7+
</dict>
8+
</plist>

0 commit comments

Comments
 (0)