@@ -10,9 +10,9 @@ import 'package:web/web.dart'
1010 AbortController,
1111 HeadersInit,
1212 ReadableStreamDefaultReader,
13+ RequestInfo,
1314 RequestInit,
14- Response,
15- window;
15+ Response;
1616
1717import 'base_client.dart' ;
1818import 'base_request.dart' ;
@@ -30,6 +30,12 @@ BaseClient createClient() {
3030 return BrowserClient ();
3131}
3232
33+ @JS ('fetch' )
34+ external JSPromise <Response > _fetch (
35+ RequestInfo input, [
36+ RequestInit init,
37+ ]);
38+
3339/// A `package:web` -based HTTP client that runs in the browser and is backed by
3440/// [`window.fetch`] (https://fetch.spec.whatwg.org/).
3541///
@@ -63,24 +69,22 @@ class BrowserClient extends BaseClient {
6369
6470 final bodyBytes = await request.finalize ().toBytes ();
6571 try {
66- final response = await window
67- .fetch (
68- '${request .url }' .toJS,
69- RequestInit (
70- method: request.method,
71- body: bodyBytes.isNotEmpty ? bodyBytes.toJS : null ,
72- credentials: withCredentials ? 'include' : 'same-origin' ,
73- headers: {
74- if (request.contentLength case final contentLength? )
75- 'content-length' : contentLength,
76- for (var header in request.headers.entries)
77- header.key: header.value,
78- }.jsify ()! as HeadersInit ,
79- signal: _abortController.signal,
80- redirect: request.followRedirects ? 'follow' : 'error' ,
81- ),
82- )
83- .toDart;
72+ final response = await _fetch (
73+ '${request .url }' .toJS,
74+ RequestInit (
75+ method: request.method,
76+ body: bodyBytes.isNotEmpty ? bodyBytes.toJS : null ,
77+ credentials: withCredentials ? 'include' : 'same-origin' ,
78+ headers: {
79+ if (request.contentLength case final contentLength? )
80+ 'content-length' : contentLength,
81+ for (var header in request.headers.entries)
82+ header.key: header.value,
83+ }.jsify ()! as HeadersInit ,
84+ signal: _abortController.signal,
85+ redirect: request.followRedirects ? 'follow' : 'error' ,
86+ ),
87+ ).toDart;
8488
8589 final contentLengthHeader = response.headers.get ('content-length' );
8690
0 commit comments