zekfad / fetch_client Goto Github PK
View Code? Open in Web Editor NEWFetch based Client for HTTP package.
Home Page: https://pub.dev/packages/fetch_client
License: ISC License
Fetch based Client for HTTP package.
Home Page: https://pub.dev/packages/fetch_client
License: ISC License
I'm getting this error with the new Chrome 117
TypeError: Instance of 'Headers Iterator': type 'JavaScriptObject' is not a subtype of type 'Iterator0<any>'
at Object.wrapException (chrome-extension://bpjhagkkjkejoamnbkldnahdabfldfao/popup.dart.js:1084:43)
at Object._failedAsCheck (chrome-extension://bpjhagkkjkejoamnbkldnahdabfldfao/popup.dart.js:2595:15)
at Rti._generalAsCheckImplementation [as _as] (chrome-extension://bpjhagkkjkejoamnbkldnahdabfldfao/popup.dart.js:2584:9)
at Rti._installSpecializedAsCheck (chrome-extension://bpjhagkkjkejoamnbkldnahdabfldfao/popup.dart.js:2507:22)
at Object.HeadersInstanceMembers_entries (chrome-extension://bpjhagkkjkejoamnbkldnahdabfldfao/popup.dart.js:8638:43)
at chrome-extension://bpjhagkkjkejoamnbkldnahdabfldfao/popup.dart.js:23323:27
at _wrapJsFunctionForAsync_closure.$protected (chrome-extension://bpjhagkkjkejoamnbkldnahdabfldfao/popup.dart.js:4016:15)
at _wrapJsFunctionForAsync_closure.call$2 (chrome-extension://bpjhagkkjkejoamnbkldnahdabfldfao/popup.dart.js:14309:12)
at _awaitOnObject_closure.call$1 (chrome-extension://bpjhagkkjkejoamnbkldnahdabfldfao/popup.dart.js:14297:32)
at _RootZone.runUnary$2$2 (chrome-extension://bpjhagkkjkejoamnbkldnahdabfldfao/popup.dart.js:16853:18)
If I comment-out these lines it works
fetch_client/lib/src/fetch_client.dart
Lines 157 to 158 in 6631e5b
It's not triggering all the time, I have to investigate to provide a reproducible example.
Hello!
Thanks for the package, it's really useful.
I've wasted a couple of hours debugging failing requests and they ended up being caused by the fact that the request size was > 64KiB. I did read your 'Large payload' section in the README but it took me a while to realize that that was the problem as the error message was not helpful at all.
I was wondering what would be the downside of automatically setting persistentConnection
to false if the request size is > 64KiB?
Something like:
// If the request if bigger than 60KiB set persistentConnection to false
if ((request.contentLength ?? 0) > 61440) {
request.persistentConnection = false;
}
What do you think?
when i run project on chrome in debug mode it will through error at below second line
client = FetchClient(mode: RequestMode.cors, streamRequests: true);
final response = await client.send(http.Request("GET", uri));
it works perfectly on release mode
how to solve it??
This is my first project using http client so it could be a dumb mistake on my part.
Been working on a flutter app that downloads a file from a remote server using Get; the app uses the standard http client for Windows and Fetch client for web.
The Windows app downloads the file with no issues but the Fetch version running on Chrome fails.
Here's a minimal test app that shows the issue (modified version of fetch_client_example.dart
The first Get request succeeds, but the second fails.
import 'package:fetch_client/fetch_client.dart';
import 'package:http/http.dart';
void test(String auth, String path) async {
try {
final client = FetchClient(mode: RequestMode.cors);
final uri = Uri.https(auth, path);
final response = await client.send(Request('GET', uri));
print(' $path statusCode: ${response.statusCode}');
} catch (e) {
print('$path exception: $e');
}
}
void main() {
test('jsonplaceholder.typicode.com', '/todos/1');
test('link.testfile.org', '/PDF10MB');
}
here's the test app output:
/todos/1 statusCode: 200
/PDF10MB exception: ClientException: Failed to execute fetch: TypeError: Failed to fetch, uri=https://link.testfile.org/PDF10MB
version info:
fetch_client: ^1.0.2
http: ^1.2.1
Windows 11 23H2
Chrome Version 123.0.6312.59 (Official Build) (64-bit)
Flutter 3.19.4 • channel stable
Framework • revision 68bfaea224 (2 days ago) • 2024-03-20 15:36:31 -0700
Engine • revision a5c24f538d
Tools • Dart 3.3.2 • DevTools 2.31.1
NotSupportedError: ReadableStream uploading is not supported
This error occurs in Safari on iOS and macOS, but everything works fine on other platforms.
If the listener of fetch's response stream is slower at processing the data than the download speed, then the listener stream's sink grows in size indefinitely.
Is there any way to bridge the nice flow control of dart streams with fetch on the JS side?
Hi,
Given that this package is web only, do you have any recommendation how to use this package in multi-platform flutter env?
So how can we make flutter web fallback on this package, and use dart:http on other platforms ?
I'm using pocketbase realtime for web using this client as the developer mentioned here
But when I try to upload file with MultipartFile from http
await pb.collection('games').update(
model.id,
body: body,
files: files,
)
It seems to break only when uploading files that are bigger than 1mb and gives me this error
ClientException: {url: https://url/api/collections/test/records/3gc4a6fn6hgi4nh, isAbort: true, statusCode: 0, response: {}, originalError: Failed to execute fetch: TypeError: Failed to fetch}
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:49 throw_
packages/pocketbase/src/client.dart 200:9 send
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 60:31 <fn>
dart-sdk/lib/async/zone.dart 1666:54 runBinary
dart-sdk/lib/async/future_impl.dart 162:22 handleError
dart-sdk/lib/async/future_impl.dart 796:46 handleError
dart-sdk/lib/async/future_impl.dart 817:13 _propagateToListeners
dart-sdk/lib/async/future_impl.dart 592:5 [_completeError]
dart-sdk/lib/async/future_impl.dart 683:7 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 177:15 <fn>
Hi, thank you for your work, the package is very helpful, I wonder if there is something I can help with here.
Anas.
Pausing the stream has no immediate downsides, even if stream will buffer events, it wont make difference because data would still be buffered but on JS side otherwise.
Example implementation on JS, it uses pull
to resume the stream, we could do the same:
https://streams.spec.whatwg.org/#example-rs-push-backpressure
Checklist:
fetch_api
.It's too late, let me briefly record the problem first
A 5-second timeout was set at the call location
_httpClient ??= FetchClient();
final response = await _httpClient!.send(request).timeout(_timeout);�
fetch_client.dart
The program will get stuck in this sentence of code 5m return
response = await fetch(request.url.toString(), init);
I added a cancellation callback abort1
final abort1 = () {
_abortCallbacks.remove(abort1);
abortController.abort();
};
_abortCallbacks.add(abort1);
final Response response;
try {
print({1, request.url});
response = await fetch(request.url.toString(), init);
print({2, request.url});
if (response.type == 'opaqueredirect' &&
!request.followRedirects &&
redirectPolicy != RedirectPolicy.alwaysFollow)
return _probeRedirect(
request: request,
initialResponse: response,
init: init,
abortController: abortController,
);
} catch (e) {
throw ClientException('Failed to execute fetch: $e', request.url);
}�
Hi, I am having trouble fetching the stream on Flutter Web. I tried a lot, but it didn't work
log("FETCH CLIENT ++++++++++++++++++");
final client = FetchClient(
mode: RequestMode.cors,
streamRequests: true,
);
final uri =
Uri.parse("https://my uri");
final stream = (() async* {
yield Uint8List.fromList(
'''
{
"name": "My cool data",
"data": {
"data_part_1": "part_1",
'''
.codeUnits,
);
await Future<void>.delayed(const Duration(seconds: 1));
yield Uint8List.fromList(
'''
"data_part_2": "part_2"
}
}
'''
.codeUnits,
);
})();
final request = StreamedRequest('POST', uri)
..headers.addAll({
"Authorization": "Bearer $idToken",
'content-type': 'application/json',
})
..sink.add(utf8.encode(json.encode(body)));
// body is the map of data that I've to pass with post request
stream.listen(
request.sink.add,
onDone: request.sink.close,
onError: request.sink.addError,
);
final response = await client.send(request);
log(await utf8.decodeStream(response.stream));
return;
Log Error: error Failed to execute fetch: TypeError: Failed to fetch
There are still some errors pop up, due to language version restrictions.
To allow generics in JS interop - language must be set to 3.3.
Current version of client 1.0.2
will be the last to support Dart >=2.19 <4, in the next version I'll set minimum language version to 3.3.
Public API won't change, but it will be feature update, Dart >=3.3 users will benefit from updated interop, while old versions will continue to use >=1.0.2 <1.1.0
, default caret constraint on fetch_api
will leave place for critical fixes to the old branch.
Checklist:
dart:js_interop
fetch_api
fetch_client
fetch_api
With the latest Flutter stable version, now get this error when using "FetchClient(mode: RequestMode.cors)":
"Expected a value of type 'Iterator', but got one of type 'DomIterator'"
Setup:
• Flutter version 3.13.4 on channel stable at /Users/andy/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 367f9ea16b (28 hours ago), 2023-09-12 23:27:53 -0500
• Engine revision 9064459a8b
• Dart version 3.1.2
• DevTools version 2.25.0
Hello, first of all, thanks for the library and its maintenance. :)
We are experiencing an issue when uploading using the StreamedRequest
. We are sending the file as the body of the request. Sometimes, for large files, for example, 500MiB, it causes the following error:
TypeError: Failed to fetch
POST https://example.com/upload net::ERR_FAILED
Here are the steps to reproduce it - Using Chrome
openRead
API from the File
object.Possibly related to: w3c/ServiceWorker#1246
Currently package uses http ^0.13.5 which prevents package usage in projects with http ^1.0.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.