Skip to content

Commit 70d5326

Browse files
committed
fix(edge_http_client): fix invalid content length value in client
1 parent cb6c3cc commit 70d5326

File tree

6 files changed

+43
-8
lines changed

6 files changed

+43
-8
lines changed
Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
1+
import 'dart:convert';
2+
3+
import 'package:edge_http_client/edge_http_client.dart';
4+
import 'package:supabase/supabase.dart';
15
import 'package:supabase_functions/supabase_functions.dart';
6+
import 'package:yet_another_json_isolate/yet_another_json_isolate.dart';
27

38
void main() {
4-
SupabaseFunctions(fetch: (request) {
5-
return Response("Hello from Supabase Edge Functions!");
9+
final client = SupabaseClient(
10+
'https://oqikpqftjankbsrejdhv.supabase.co',
11+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9xaWtwcWZ0amFua2JzcmVqZGh2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NzU5NDY5MTAsImV4cCI6MTk5MTUyMjkxMH0.jK4_Kqi4ZYxg7KbOJKsyHXrwkX_u3Ugp_XQyQW9m_lw',
12+
httpClient: EdgeHttpClient(),
13+
isolate: CurrentIsolate(),
14+
);
15+
16+
SupabaseFunctions(fetch: (request) async {
17+
List messages = await client.from('example').select();
18+
return Response.json(messages);
619
});
720
}
21+
22+
// This will eventually live inside of edge_io
23+
class CurrentIsolate implements YAJsonIsolate {
24+
@override
25+
Future decode(String json) {
26+
return Future.value(jsonDecode(json));
27+
}
28+
29+
@override
30+
Future<void> dispose() async {}
31+
32+
@override
33+
Future<String> encode(Object? json) {
34+
return Future.value(jsonEncode(json));
35+
}
36+
37+
@override
38+
Future<void> initialize() async {}
39+
}

examples/supabase-edge-functions/pubspec.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ environment:
88

99
dependencies:
1010
edge: ^0.0.5
11+
edge_http_client: ^0.0.1
12+
supabase: ^1.6.3
1113
supabase_functions: ^0.0.2
14+
yet_another_json_isolate: ^1.0.2
15+
1216
dev_dependencies:
1317
lints: ^2.0.1
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 0.0.1+1
1+
## 0.0.1
22

3-
- Update a dependency to the latest release.
3+
- Initial version.
44

packages/edge_http_client/lib/edge_http_client.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ class EdgeHttpClient implements http.Client {
150150
req.contentLength = bytes.length;
151151
req.add(bytes);
152152
}
153-
154153
final res = await req.close();
155154
final resHeaders = <String, String>{};
156155

@@ -161,7 +160,8 @@ class EdgeHttpClient implements http.Client {
161160
return http.StreamedResponse(
162161
res,
163162
res.statusCode,
164-
contentLength: res.contentLength,
163+
request: request,
164+
contentLength: res.contentLength == -1 ? null : res.contentLength,
165165
headers: resHeaders,
166166
isRedirect: res.isRedirect,
167167
persistentConnection: res.persistentConnection,

packages/edge_http_client/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: edge_http_client
22
description: A http package implementation for Dart Edge.
33
homepage: https://dartedge.dev
44
repository: https://github.com/invertase/dart_edge/tree/main/packages/edge_http_client
5-
version: 0.0.1+1
5+
version: 0.0.1
66

77
environment:
88
sdk: ">=2.18.5 <3.0.0"

packages/edge_runtime/lib/src/io_http_client.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ class HttpClientRequest implements io.HttpClientRequest {
287287

288288
@override
289289
Future<HttpClientResponse> close() async {
290-
print('close()');
291290
final fetchResponse = await fetch(
292291
_resource,
293292
body: _body != null ? Uint8List.fromList(_body!) : null,

0 commit comments

Comments
 (0)