Skip to content

Commit 24fd71f

Browse files
author
Rohit R. Abbadi
committed
fix for https: infitio#3
1 parent 4e51d76 commit 24fd71f

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.3.5 - 13th September, 2010
2+
3+
* Fix for [issue related to https: CERTIFICATE_VERIFY_FAILED](https://github.com/infitio/flutter-adhara/issues/3)
4+
https CERTIFICATE_VERIFY_FAILED is handled by suppressing error and showing necessary information in logs.
5+
A warning log will be printed stating the same
6+
7+
* Customize HTTP client by overriding `IOClient get http`
8+
19
## [0.3.4] - 26th March, 2019
210

311
* String Resources now supports placeholders

lib/datainterface/data/network_provider.dart

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import 'dart:convert';
33

44
import 'package:adhara/config.dart';
55
import 'package:adhara/datainterface/data/data_provider.dart';
6-
import 'package:http/http.dart' as http;
6+
import 'package:http/io_client.dart';
7+
import 'dart:io';
8+
import 'package:http/http.dart' as default_http;
9+
710

811
class NetworkProvider extends DataProvider {
12+
13+
IOClient _http;
914
NetworkProvider(Config config)
1015
: assert(config.baseURL.endsWith("/")),
1116
super(config);
@@ -16,8 +21,27 @@ class NetworkProvider extends DataProvider {
1621
return data;
1722
}
1823

24+
bool badCertCallback(X509Certificate cert, String host, int port) {
25+
print("---------------------CERTIFICATE_VERIFY_FAILED---------------------\n"
26+
"SSL Certificate seems to invalid/self signed.\n"
27+
" to suppress these logs, override\n"
28+
"\t`bool badCertCallback(X509Certificate cert, String host, int port)`\n"
29+
"in your NetworkProvider class and `return true`\n"
30+
"-------------------------------------------------------------------");
31+
return true;
32+
}
33+
34+
IOClient get http {
35+
if(_http==null) {
36+
HttpClient client = new HttpClient();
37+
client.badCertificateCallback = badCertCallback;
38+
_http = IOClient(client);
39+
}
40+
return _http;
41+
}
42+
1943
dynamic extractResponse(dynamic response) {
20-
response = response as http.Response;
44+
response = response as default_http.Response;
2145
if (response.statusCode >= 400) {
2246
throw response;
2347
}
@@ -47,13 +71,13 @@ class NetworkProvider extends DataProvider {
4771

4872
postResponseIntercept(
4973
String method, String url, dynamic data, dynamic response) async {
50-
response = response as http.Response;
74+
response = response as default_http.Response;
5175
return;
5276
}
5377

5478
_postResponseIntercept(
5579
String method, String url, dynamic data, dynamic response) async {
56-
response = response as http.Response;
80+
response = response as default_http.Response;
5781
print(
5882
"http: $method $url with data: ${data ?? data.toString()} response: ${response.statusCode} \n ${response.body}");
5983
postResponseIntercept(method, url, data, response);
@@ -62,16 +86,15 @@ class NetworkProvider extends DataProvider {
6286
Future<dynamic> get(String url, {Map headers}) async {
6387
url = this.formatURL(url);
6488
_preFlightIntercept("GET", url, null);
65-
http.Response r =
66-
await http.get(url, headers: headers ?? this.defaultHeaders);
89+
default_http.Response r = await http.get(url, headers: headers ?? this.defaultHeaders);
6790
await _postResponseIntercept("GET", url, null, r);
6891
return this.extractResponse(r);
6992
}
7093

7194
Future<dynamic> post(String url, Map data, {Map headers}) async {
7295
url = this.formatURL(url);
7396
_preFlightIntercept("POST", url, data);
74-
http.Response r = await http.post(url,
97+
default_http.Response r = await http.post(url,
7598
body: json.encode(data), headers: headers ?? this.defaultHeaders);
7699
await _postResponseIntercept("POST", url, data, r);
77100
return this.extractResponse(r);
@@ -80,7 +103,7 @@ class NetworkProvider extends DataProvider {
80103
Future<dynamic> put(String url, Map data, {Map headers}) async {
81104
url = this.formatURL(url);
82105
_preFlightIntercept("PUT", url, data);
83-
http.Response r = await http.put(url,
106+
default_http.Response r = await http.put(url,
84107
body: json.encode(data), headers: headers ?? this.defaultHeaders);
85108
await _postResponseIntercept("PUT", url, data, r);
86109
return this.extractResponse(r);
@@ -89,9 +112,9 @@ class NetworkProvider extends DataProvider {
89112
Future<dynamic> delete(String url, {Map headers}) async {
90113
url = this.formatURL(url);
91114
_preFlightIntercept("DELETE", url, null);
92-
http.Response r =
93-
await http.delete(url, headers: headers ?? this.defaultHeaders);
115+
default_http.Response r = await http.delete(url, headers: headers ?? this.defaultHeaders);
94116
await _postResponseIntercept("DELETE", url, null, r);
95117
return this.extractResponse(r);
96118
}
119+
97120
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: adhara
22
description: Base framework for Flutter Apps with intense networking and data interactivity
3-
version: 0.3.4
3+
version: 0.3.5
44
author: Rohit R. Abbadi <[email protected]>
55
homepage: https://github.com/infitio/flutter-adhara
66

0 commit comments

Comments
 (0)