From c0d4d723423258502b51ce60933f5754e5a364bd Mon Sep 17 00:00:00 2001 From: jenow Date: Thu, 25 Feb 2021 15:05:17 +0100 Subject: [PATCH 1/4] add an option to accept bad SSL certificate --- doc/2/protocols/http/constructor/index.md | 3 ++- lib/src/protocols/http.dart | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/doc/2/protocols/http/constructor/index.md b/doc/2/protocols/http/constructor/index.md index 4023aeb5..44703188 100644 --- a/doc/2/protocols/http/constructor/index.md +++ b/doc/2/protocols/http/constructor/index.md @@ -13,7 +13,7 @@ Use this constructor to create a new instance of the `Http` protocol with specif ## Arguments ```dart -HttpProtocol(Uri); +HttpProtocol(Uri, {bool acceptUnsignedCertificate = false}); ```
@@ -21,6 +21,7 @@ HttpProtocol(Uri); | Argument | Type | Description | | --------- | ----------------- | ---------------------------- | | `uri` |
Uri
| URI pointing to a Kuzzle server. See more: [https://api.dart.dev/stable/2.10.5/dart-core/Uri-class.html](https://api.dart.dev/stable/2.10.5/dart-core/Uri-class.html) | +| `acceptUnsignedCertificate` |
bool(false)
| Accept or not bad certificate when using https ## Return diff --git a/lib/src/protocols/http.dart b/lib/src/protocols/http.dart index 57f313e4..b2cf7a02 100644 --- a/lib/src/protocols/http.dart +++ b/lib/src/protocols/http.dart @@ -1,18 +1,27 @@ import 'dart:convert'; +import 'dart:io'; +import 'package:http/io_client.dart'; import 'package:kuzzle/src/kuzzle/request.dart'; import 'package:kuzzle/src/kuzzle/response.dart'; import 'package:kuzzle/src/protocols/abstract.dart'; -import 'package:http/http.dart' as http; class HttpProtocol extends KuzzleProtocol { - HttpProtocol(Uri uri) : super(uri); + HttpProtocol(Uri uri, {bool acceptUnsignedCertificate = false}) : super(uri) { + _client = HttpClient() + ..badCertificateCallback = + ((cert, host, port) => acceptUnsignedCertificate); + _ioClient = IOClient(_client); + } + + HttpClient _client; + IOClient _ioClient; @override Future connect() async { await super.connect(); - final res = await http.get('${uri.toString()}/_query'); + final res = await _ioClient.get('${uri.toString()}/_query'); if (res.statusCode == 401 || res.statusCode == 403) { return Future.error('You must have permission on the _query route.'); } @@ -32,7 +41,7 @@ class HttpProtocol extends KuzzleProtocol { headers['x-kuzzle-volatile'] = jsonEncode(request.volatile); } - final res = await http.post( + final res = await _ioClient.post( '${uri.toString()}/_query', headers: headers, body: jsonEncode(request), From 4b79819d6338ef9406424d1075f8291c22375a68 Mon Sep 17 00:00:00 2001 From: jenow Date: Thu, 25 Feb 2021 15:11:11 +0100 Subject: [PATCH 2/4] rename acceptUnsignedCertificate to acceptBadCertificate --- doc/2/protocols/http/constructor/index.md | 2 +- lib/src/protocols/http.dart | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/2/protocols/http/constructor/index.md b/doc/2/protocols/http/constructor/index.md index 44703188..54e2c8bb 100644 --- a/doc/2/protocols/http/constructor/index.md +++ b/doc/2/protocols/http/constructor/index.md @@ -21,7 +21,7 @@ HttpProtocol(Uri, {bool acceptUnsignedCertificate = false}); | Argument | Type | Description | | --------- | ----------------- | ---------------------------- | | `uri` |
Uri
| URI pointing to a Kuzzle server. See more: [https://api.dart.dev/stable/2.10.5/dart-core/Uri-class.html](https://api.dart.dev/stable/2.10.5/dart-core/Uri-class.html) | -| `acceptUnsignedCertificate` |
bool(false)
| Accept or not bad certificate when using https +| `acceptBadCertificate` |
bool(false)
| Accept or not bad certificate when using https ## Return diff --git a/lib/src/protocols/http.dart b/lib/src/protocols/http.dart index b2cf7a02..6083b2f7 100644 --- a/lib/src/protocols/http.dart +++ b/lib/src/protocols/http.dart @@ -7,10 +7,10 @@ import 'package:kuzzle/src/kuzzle/response.dart'; import 'package:kuzzle/src/protocols/abstract.dart'; class HttpProtocol extends KuzzleProtocol { - HttpProtocol(Uri uri, {bool acceptUnsignedCertificate = false}) : super(uri) { + HttpProtocol(Uri uri, {bool acceptBadCertificate = false}) : super(uri) { _client = HttpClient() ..badCertificateCallback = - ((cert, host, port) => acceptUnsignedCertificate); + ((cert, host, port) => acceptBadCertificate); _ioClient = IOClient(_client); } From bac14d0257a9b56792dc484c63de8dd5757b6c14 Mon Sep 17 00:00:00 2001 From: jenow Date: Thu, 25 Feb 2021 15:13:11 +0100 Subject: [PATCH 3/4] rename acceptUnsignedCertificate to acceptBadCertificate --- doc/2/protocols/http/constructor/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/2/protocols/http/constructor/index.md b/doc/2/protocols/http/constructor/index.md index 54e2c8bb..bb3df7e3 100644 --- a/doc/2/protocols/http/constructor/index.md +++ b/doc/2/protocols/http/constructor/index.md @@ -13,7 +13,7 @@ Use this constructor to create a new instance of the `Http` protocol with specif ## Arguments ```dart -HttpProtocol(Uri, {bool acceptUnsignedCertificate = false}); +HttpProtocol(Uri, {bool acceptBadCertificate = false}); ```
From 78b09345aae580685172f089a747ab3932855ef6 Mon Sep 17 00:00:00 2001 From: jenow Date: Thu, 25 Feb 2021 15:37:57 +0100 Subject: [PATCH 4/4] Release 2.3.0 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index e5423618..003d0f04 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: kuzzle -version: 2.2.1 +version: 2.3.0 description: A library to interact with kuzzle API. A backend software, self-hostable and ready to use to power modern cross-platform apps. homepage: https://github.com/kuzzleio/sdk-dart