Skip to content

Commit

Permalink
Merge pull request #69 from kuzzleio/2.3.0-proposal
Browse files Browse the repository at this point in the history
Release 2.3.0
  • Loading branch information
jenow authored Feb 25, 2021
2 parents 0961c86 + ae7344c commit d0a657e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2.3.0]

- Add an option to accept bad SSL certificate

## [2.2.2]

- Bugfix: Handle HTTP Errors
Expand Down
3 changes: 2 additions & 1 deletion doc/2/protocols/http/constructor/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ Use this constructor to create a new instance of the `Http` protocol with specif
## Arguments

```dart
HttpProtocol(Uri);
HttpProtocol(Uri, {bool acceptBadCertificate = false});
```

<br/>

| Argument | Type | Description |
| --------- | ----------------- | ---------------------------- |
| `uri` | <pre>Uri</pre> | 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) |
| `acceptBadCertificate` | <pre>bool(false)</pre> | Accept or not bad certificate when using https


## Return
Expand Down
17 changes: 13 additions & 4 deletions lib/src/protocols/http.dart
Original file line number Diff line number Diff line change
@@ -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 acceptBadCertificate = false}) : super(uri) {
_client = HttpClient()
..badCertificateCallback =
((cert, host, port) => acceptBadCertificate);
_ioClient = IOClient(_client);
}

HttpClient _client;
IOClient _ioClient;

@override
Future<void> 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.');
}
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: kuzzle
version: 2.2.2
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
Expand Down

0 comments on commit d0a657e

Please sign in to comment.