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

fix: use utf8 encoding for text response type #18

Merged
merged 2 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.1.1]

- fix: use utf8 encoding for text response

## [1.1.0]

- feat: add `method` parameter to `invoke()` to support all GET, POST, PUT, PATCH, DELETE methods
Expand Down
45 changes: 19 additions & 26 deletions lib/src/functions_client.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:functions_client/src/constants.dart';
import 'package:functions_client/src/types.dart';
import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -49,57 +51,48 @@ class FunctionsClient {
final bodyStr = body == null ? null : await _isolate.encode(body);

late final Response response;
final uri = Uri.parse('$_url/$functionName');

final finalHeaders = <String, String>{
..._headers,
if (headers != null) ...headers
};

switch (method) {
case HttpMethod.post:
response = await (_httpClient?.post ?? http.post)(
Uri.parse('$_url/$functionName'),
headers: <String, String>{
..._headers,
if (headers != null) ...headers
},
uri,
headers: finalHeaders,
body: bodyStr,
);
break;

case HttpMethod.get:
response = await (_httpClient?.get ?? http.get)(
Uri.parse('$_url/$functionName'),
headers: <String, String>{
..._headers,
if (headers != null) ...headers
},
uri,
headers: finalHeaders,
);
break;

case HttpMethod.put:
response = await (_httpClient?.put ?? http.put)(
Uri.parse('$_url/$functionName'),
headers: <String, String>{
..._headers,
if (headers != null) ...headers
},
uri,
headers: finalHeaders,
body: bodyStr,
);
break;

case HttpMethod.delete:
response = await (_httpClient?.delete ?? http.delete)(
Uri.parse('$_url/$functionName'),
headers: <String, String>{
..._headers,
if (headers != null) ...headers
},
uri,
headers: finalHeaders,
);
break;

case HttpMethod.patch:
response = await (_httpClient?.patch ?? http.patch)(
Uri.parse('$_url/$functionName'),
headers: <String, String>{
..._headers,
if (headers != null) ...headers
},
uri,
headers: finalHeaders,
body: bodyStr,
);
break;
Expand All @@ -114,7 +107,7 @@ class FunctionsClient {
} else if (responseType == ResponseType.arraybuffer) {
data = response.bodyBytes;
} else if (responseType == ResponseType.text) {
data = response.body;
data = utf8.decode(response.bodyBytes);
} else {
data = response.body;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const version = '1.1.0';
const version = '1.1.1';
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: functions_client
description: A dart client library for the Supabase functions.
version: 1.1.0
version: 1.1.1
homepage: 'https://supabase.io'
repository: 'https://github.com/supabase-community/functions-dart'

Expand Down