Skip to content
This repository was archived by the owner on May 13, 2023. It is now read-only.

Commit 4b16f2e

Browse files
authored
fix: use utf8 encoding for text response type (#18)
* fix: use utf8 encoding for text response type * chore: release v1.1.1
1 parent 3f613ea commit 4b16f2e

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [1.1.1]
2+
3+
- fix: use utf8 encoding for text response
4+
15
## [1.1.0]
26

37
- feat: add `method` parameter to `invoke()` to support all GET, POST, PUT, PATCH, DELETE methods

lib/src/functions_client.dart

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:convert';
2+
13
import 'package:functions_client/src/constants.dart';
24
import 'package:functions_client/src/types.dart';
35
import 'package:http/http.dart' as http;
@@ -49,57 +51,48 @@ class FunctionsClient {
4951
final bodyStr = body == null ? null : await _isolate.encode(body);
5052

5153
late final Response response;
54+
final uri = Uri.parse('$_url/$functionName');
55+
56+
final finalHeaders = <String, String>{
57+
..._headers,
58+
if (headers != null) ...headers
59+
};
5260

5361
switch (method) {
5462
case HttpMethod.post:
5563
response = await (_httpClient?.post ?? http.post)(
56-
Uri.parse('$_url/$functionName'),
57-
headers: <String, String>{
58-
..._headers,
59-
if (headers != null) ...headers
60-
},
64+
uri,
65+
headers: finalHeaders,
6166
body: bodyStr,
6267
);
6368
break;
6469

6570
case HttpMethod.get:
6671
response = await (_httpClient?.get ?? http.get)(
67-
Uri.parse('$_url/$functionName'),
68-
headers: <String, String>{
69-
..._headers,
70-
if (headers != null) ...headers
71-
},
72+
uri,
73+
headers: finalHeaders,
7274
);
7375
break;
7476

7577
case HttpMethod.put:
7678
response = await (_httpClient?.put ?? http.put)(
77-
Uri.parse('$_url/$functionName'),
78-
headers: <String, String>{
79-
..._headers,
80-
if (headers != null) ...headers
81-
},
79+
uri,
80+
headers: finalHeaders,
8281
body: bodyStr,
8382
);
8483
break;
8584

8685
case HttpMethod.delete:
8786
response = await (_httpClient?.delete ?? http.delete)(
88-
Uri.parse('$_url/$functionName'),
89-
headers: <String, String>{
90-
..._headers,
91-
if (headers != null) ...headers
92-
},
87+
uri,
88+
headers: finalHeaders,
9389
);
9490
break;
9591

9692
case HttpMethod.patch:
9793
response = await (_httpClient?.patch ?? http.patch)(
98-
Uri.parse('$_url/$functionName'),
99-
headers: <String, String>{
100-
..._headers,
101-
if (headers != null) ...headers
102-
},
94+
uri,
95+
headers: finalHeaders,
10396
body: bodyStr,
10497
);
10598
break;
@@ -114,7 +107,7 @@ class FunctionsClient {
114107
} else if (responseType == ResponseType.arraybuffer) {
115108
data = response.bodyBytes;
116109
} else if (responseType == ResponseType.text) {
117-
data = response.body;
110+
data = utf8.decode(response.bodyBytes);
118111
} else {
119112
data = response.body;
120113
}

lib/src/version.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
const version = '1.1.0';
1+
const version = '1.1.1';

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: functions_client
22
description: A dart client library for the Supabase functions.
3-
version: 1.1.0
3+
version: 1.1.1
44
homepage: 'https://supabase.io'
55
repository: 'https://github.com/supabase-community/functions-dart'
66

0 commit comments

Comments
 (0)