GithubHelp home page GithubHelp logo

zekfad / fetch_client Goto Github PK

View Code? Open in Web Editor NEW
19.0 3.0 10.0 58 KB

Fetch based Client for HTTP package.

Home Page: https://pub.dev/packages/fetch_client

License: ISC License

Dart 100.00%
dart dart-web fetch fetch-api dart-package

fetch_client's Issues

Instance of 'Headers Iterator': type 'JavaScriptObject' is not a subtype of type 'Iterator0<any>'

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

for (final header in response.headers.entries())
header.first: header.last,

It's not triggering all the time, I have to investigate to provide a reproducible example.

Automatically setting persistentConnection to false if request size > 64KiB

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?

Get request failure

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

Support for flow control?

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?

Usage with muli-platform apps

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 ?

Large payload with keep alive (default) causes errors

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>

[BUG] The timeout setting will be invalid when the server does not return data

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);
    }�

Failed to fetch stream on web

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

Backwards compatibility

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:

  • Fetch API migrate to dart:js_interop
  • Bump major and language version for fetch_api
  • Remove compatibility layer
  • Bump feature and language for fetch_client
  • Migrate internals to new fetch_api

FetchClient(mode: RequestMode.cors) error

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

StreamedRequest Fails on Large File Upload in Chrome When Tab Not in Focus

Hello, first of all, thanks for the library and its maintenance. :)

Issue

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

Steps to reproduce

Here are the steps to reproduce it - Using Chrome

  • Open a new instance
  • Try uploading a file of 600MB. You can use the openRead API from the File object.
  • As soon as the file starts uploading, switch to another app.
  • Let the page lose focus for at least 3 or 4 minutes and the upload fails.
  • If we come back after 3 or 4 minutes and it hasn't failed, let's switch away from the page for another 1 or 2 minutes.
  • Then, let's return to our page.
  • Upload fails.

Related Issues/PRs:

Possibly related to: w3c/ServiceWorker#1246

Upgrade http to ^1.0.0

Currently package uses http ^0.13.5 which prevents package usage in projects with http ^1.0.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.