From 5579550b8da66ad61e3490e3534516e1af85b947 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Thu, 24 Oct 2024 04:54:00 -0400 Subject: [PATCH 1/8] update curl/wolfssl, add per host connection limit --- README.md | 2 +- client/fragments/fix_socket_limit.js | 5 +++++ client/javascript/http.js | 2 +- client/javascript/session.js | 4 ++-- client/libcurl/session.c | 3 ++- client/tools/curl.sh | 2 +- client/tools/wolfssl.sh | 4 ++-- server/wisp_server | 2 +- 8 files changed, 15 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9360016..d2db609 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ The valid HTTP session settings are: Each HTTP session has the following methods available: - `fetch` - Identical to the `libcurl.fetch` function but only creates connections in this session. -- `set_connections` - Set the connection limits. This takes two arguments, the first being the limit for the connection cache, and the second being the max number of active connections. +- `set_connections` - Set the connection limits. This takes three arguments: the first [is the hard limit of active connections](https://curl.se/libcurl/c/CURLMOPT_MAX_TOTAL_CONNECTIONS.html) (default 60), the second is limit for the connection cache (default 50), and the third is the [max connections per host](https://curl.se/libcurl/c/CURLMOPT_MAXCONNECTS.html) (default 6). - `export_cookies` - Export any cookies which were recorded in the session. This will return an empty string if cookies are disabled or no cookies have been set yet. - `close` - Close all connections and clean up the session. You must call this after you are done using the session, otherwise it will leak memory. diff --git a/client/fragments/fix_socket_limit.js b/client/fragments/fix_socket_limit.js index e3af9ae..85f576c 100644 --- a/client/fragments/fix_socket_limit.js +++ b/client/fragments/fix_socket_limit.js @@ -1,3 +1,8 @@ /* DELETE assert\(sock\.stream\.fd ?< ?64\); */ + + +/* DELETE +assert\(!exceptfds, ?['"]exceptfds not supported['"]\); +*/ diff --git a/client/javascript/http.js b/client/javascript/http.js index fa36f4b..64273fb 100644 --- a/client/javascript/http.js +++ b/client/javascript/http.js @@ -4,7 +4,7 @@ class HTTPSession extends CurlSession { this.options = options; this.base_url = undefined; - this.set_connections(50, 40); + this.set_connections(50, 40, 6); this.import_cookies(); } diff --git a/client/javascript/session.js b/client/javascript/session.js index 3d7fce5..c6c8d9a 100644 --- a/client/javascript/session.js +++ b/client/javascript/session.js @@ -28,9 +28,9 @@ class CurlSession { } } - set_connections(connections_limit, cache_limit) { + set_connections(connections_limit, cache_limit, host_conn_limit=0) { this.assert_ready(); - _session_set_options(this.session_ptr, connections_limit, cache_limit); + _session_set_options(this.session_ptr, connections_limit, cache_limit, host_conn_limit); } end_callback(request_id, error) { diff --git a/client/libcurl/session.c b/client/libcurl/session.c index fc28b09..f20948f 100644 --- a/client/libcurl/session.c +++ b/client/libcurl/session.c @@ -27,9 +27,10 @@ void session_perform(struct SessionInfo *session) { } } -void session_set_options(struct SessionInfo *session, int connections_limit, int cache_limit) { +void session_set_options(struct SessionInfo *session, int connections_limit, int cache_limit, int host_conn_limit) { curl_multi_setopt(session->multi_handle, CURLMOPT_MAX_TOTAL_CONNECTIONS, connections_limit); curl_multi_setopt(session->multi_handle, CURLMOPT_MAXCONNECTS, cache_limit); + curl_multi_setopt(session->multi_handle, CURLMOPT_MAX_HOST_CONNECTIONS, host_conn_limit); } void session_add_request(struct SessionInfo *session, CURL* http_handle) { diff --git a/client/tools/curl.sh b/client/tools/curl.sh index 4b9255a..7f7282f 100755 --- a/client/tools/curl.sh +++ b/client/tools/curl.sh @@ -14,7 +14,7 @@ NGHTTP2_PREFIX=$(realpath build/nghttp2-wasm) cd build rm -rf curl -git clone -b curl-8_9_1 --depth=1 https://github.com/curl/curl +git clone -b curl-8_10_1 --depth=1 https://github.com/curl/curl cd curl autoreconf -fi diff --git a/client/tools/wolfssl.sh b/client/tools/wolfssl.sh index 897da09..20b78a9 100755 --- a/client/tools/wolfssl.sh +++ b/client/tools/wolfssl.sh @@ -12,11 +12,11 @@ mkdir -p $PREFIX cd build rm -rf wolfssl -git clone -b v5.6.6-stable --depth=1 https://github.com/wolfSSL/wolfssl wolfssl +git clone -b v5.7.2-stable --depth=1 https://github.com/wolfSSL/wolfssl wolfssl cd wolfssl autoreconf -fi -export CFLAGS="-Oz -DSP_WORD_SIZE=32 -DWOLFSSL_NO_ATOMICS -DWOLFSSL_TICKET_NONCE_MALLOC" +export CFLAGS="-Oz -DSP_WORD_SIZE=32 -DWOLFSSL_NO_ATOMICS -DWOLFSSL_MAX_ALT_NAMES=1024" emconfigure ./configure --prefix=$PREFIX --enable-curl --enable-static --disable-shared --host=i686-linux --disable-examples --disable-asm --enable-sni --enable-alpn --enable-truncatedhmac --enable-oldtls --enable-tlsv12 --enable-all-crypto --disable-asyncthreads --disable-threadlocal --enable-tlsx emmake make -j$CORE_COUNT make install diff --git a/server/wisp_server b/server/wisp_server index 78f872c..f931adf 160000 --- a/server/wisp_server +++ b/server/wisp_server @@ -1 +1 @@ -Subproject commit 78f872c8e5b180e26ec09cc126e841e12ac75c36 +Subproject commit f931adf9fea476fefffb1f0c3789cafda58d54ba From b5c6ae4dc7846eb2ded4c989a939e163d3c46b26 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Thu, 24 Oct 2024 06:25:17 -0400 Subject: [PATCH 2/8] compile wolfssl with more reasonable options --- CHANGELOG.md | 5 +++++ client/package.json | 2 +- client/tools/wolfssl.sh | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1f99b3..2ef3ab6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Libcurl.js Changelog: +## v0.6.17 (10/2/24): +- Enable a per host connection limit. This defaults to 6, which is the same as most web browsers. +- Use the latest WolfSSL again and compile with workarounds +- Upgrade to curl 8.10.1 + ## v0.6.16 (10/2/24): - Fix a bug with `Headers` objects and `Request` objects not being properly handled when passed into `libcurl.fetch` - Errors thrown are now `Error` or `TypeError` objects instead of plain strings diff --git a/client/package.json b/client/package.json index 064001a..9144589 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "libcurl.js", - "version": "0.6.16", + "version": "0.6.17", "description": "A port of libcurl to WebAssembly, for proxying HTTPS requests from the browser with full TLS encryption", "main": "libcurl.mjs", "exports": { diff --git a/client/tools/wolfssl.sh b/client/tools/wolfssl.sh index 20b78a9..64082ae 100755 --- a/client/tools/wolfssl.sh +++ b/client/tools/wolfssl.sh @@ -17,7 +17,7 @@ cd wolfssl autoreconf -fi export CFLAGS="-Oz -DSP_WORD_SIZE=32 -DWOLFSSL_NO_ATOMICS -DWOLFSSL_MAX_ALT_NAMES=1024" -emconfigure ./configure --prefix=$PREFIX --enable-curl --enable-static --disable-shared --host=i686-linux --disable-examples --disable-asm --enable-sni --enable-alpn --enable-truncatedhmac --enable-oldtls --enable-tlsv12 --enable-all-crypto --disable-asyncthreads --disable-threadlocal --enable-tlsx +emconfigure ./configure --prefix=$PREFIX --enable-curl --enable-static --disable-shared --host=i686-linux --disable-examples --disable-asm --enable-sni --enable-alpn --enable-truncatedhmac --enable-tlsv12 --enable-all-crypto --disable-arc4 --disable-asyncthreads --disable-threadlocal --enable-tlsx --disable-nullcipher emmake make -j$CORE_COUNT make install From e598ed3be65118d54ceaa672f8aef5a41e1cbd0a Mon Sep 17 00:00:00 2001 From: ading2210 Date: Thu, 24 Oct 2024 07:00:02 -0400 Subject: [PATCH 3/8] update readme --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d2db609..424bc16 100644 --- a/README.md +++ b/README.md @@ -86,8 +86,8 @@ If you are using the single file version (`libcurl_full.js`), the `libcurl.load_ Alternatively, prebuilt versions can be found on NPM and jsDelivr. You can use the [following URLs](https://cdn.jsdelivr.net/npm/libcurl.js@latest/) to load libcurl.js from a third party CDN. ``` -https://cdn.jsdelivr.net/npm/libcurl.js@latest/libcurl.js -https://cdn.jsdelivr.net/npm/libcurl.js@latest/libcurl.wasm +https://cdn.jsdelivr.net/npm/libcurl.js@0.6.7/libcurl.js +https://cdn.jsdelivr.net/npm/libcurl.js@0.6.7/libcurl.wasm ``` To know when libcurl.js has finished loading, you can use the `libcurl_load` DOM event. The `libcurl_abort` event will trigger if the Emscripten runtime gets aborted due to a critical error. The `libcurl.events` object contains an `EventTarget` where these events will also be emitted. @@ -131,9 +131,9 @@ Most of the standard Fetch API's features are supported, with the exception of: Sending cookies is supported, but they will not be automatically sent unless you create a new HTTP session, which is covered in the next section. -The response may contain multiple HTTP headers with the same name, which the `Headers` object isn't able to properly represent. If this matters to you, use `response.raw_headers`, which is an array of key value pairs, instead of `response.headers`. There is support for streaming the response body using a `ReadableStream`, as well as canceling requests using an `AbortSignal`. All requests made using this method share the same connection pool, which has a limit of 50 active TCP connections. +The response may contain multiple HTTP headers with the same name, which the `Headers` object isn't able to properly represent. If this matters to you, use `response.raw_headers`, which is an array of key value pairs, instead of `response.headers`. There is support for streaming the response body using a `ReadableStream`, as well as canceling requests using an `AbortSignal`. All requests made using this method share the same connection pool, which has a limit of 50 active TCP connections (configurable if you use a separate HTTP session). -The `proxy` option may be used to specify the URL of a `socks5h`, `socks4a`, or `http` proxy server. For example `proxy: "socks5h://127.0.0.0:1080"` will set the proxy server for just the current request. +The `proxy` option may be used to specify the URL of a `socks5h`, `socks4a`, or `http` proxy server. For example `proxy: "socks5h://127.0.0.0:1080"` will set the proxy server for just the current request. This proxy option is separate from the global websocket proxy. ### Creating New HTTP Sessions: To create new sessions for HTTP requests, use the `libcurl.HTTPSession` class. The constructor for this class takes the following arguments: @@ -146,7 +146,7 @@ The valid HTTP session settings are: Each HTTP session has the following methods available: - `fetch` - Identical to the `libcurl.fetch` function but only creates connections in this session. -- `set_connections` - Set the connection limits. This takes three arguments: the first [is the hard limit of active connections](https://curl.se/libcurl/c/CURLMOPT_MAX_TOTAL_CONNECTIONS.html) (default 60), the second is limit for the connection cache (default 50), and the third is the [max connections per host](https://curl.se/libcurl/c/CURLMOPT_MAXCONNECTS.html) (default 6). +- `set_connections` - Set the connection limits. This takes three arguments: the first [is the hard limit of active connections](https://curl.se/libcurl/c/CURLMOPT_MAX_TOTAL_CONNECTIONS.html) (default 60), the second is [limit for the connection cache](https://curl.se/libcurl/c/CURLMOPT_MAXCONNECTS.html) (default 50), and the third is the [max connections per host](https://curl.se/libcurl/c/CURLMOPT_MAX_HOST_CONNECTIONS.html) (default 6). - `export_cookies` - Export any cookies which were recorded in the session. This will return an empty string if cookies are disabled or no cookies have been set yet. - `close` - Close all connections and clean up the session. You must call this after you are done using the session, otherwise it will leak memory. @@ -246,6 +246,8 @@ libcurl.set_websocket("ws://localhost:6001/"); ``` If the websocket proxy URL is not set and one of the other API functions is called, an error will be thrown. Note that this URL must end with a trailing slash. +Changing the websocket proxy URL will not close any existing connections. + ### Getting Libcurl's Output: If you want more information about a connection, you can pass the `_libcurl_verbose` argument to the `libcurl.fetch` function. These are the same messages that you would see if you ran `curl -v` on the command line. ```js @@ -278,7 +280,7 @@ You can get version information from the `libcurl.version` object. This object w You can get the CA cert bundle that libcurl uses by calling `libcurl.get_cacert`. The function will return a string with the certificates in PEM format. The cert bundle comes from the [official curl website](https://curl.se/docs/caextract.html), which is extracted from the Mozilla Firefox source code. ### Using the Wisp Client -The `libcurl.wisp` object exposes all of the APIs from [wisp-client-js](https://github.com/MercuryWorkshop/wisp-client-js). This API is not guarenteed to be reliable. +The `libcurl.wisp` object exposes all of the APIs from [wisp-client-js](https://github.com/MercuryWorkshop/wisp-client-js). This API is not guaranteed to be stable. ## Proxy Server: The proxy server consists of a standard [Wisp](https://github.com/MercuryWorkshop/wisp-protocol) server, allowing multiple TCP connections to share the same websocket. From 40044096500ea7a79591c05d9bd80dc9fe18946a Mon Sep 17 00:00:00 2001 From: ading2210 Date: Tue, 29 Oct 2024 23:30:05 -0400 Subject: [PATCH 4/8] improve download speeds by listening directly for ws messages --- client/fragments/notify_ws_events.js | 5 +++++ client/javascript/main.js | 2 ++ client/javascript/session.js | 8 ++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 client/fragments/notify_ws_events.js diff --git a/client/fragments/notify_ws_events.js b/client/fragments/notify_ws_events.js new file mode 100644 index 0000000..dffb26c --- /dev/null +++ b/client/fragments/notify_ws_events.js @@ -0,0 +1,5 @@ +/* INSERT +Module\[['"]websocket['"]\]\.emit\(['"]message['"], ?sock\.stream\.fd\) +*/ +; ws_events.dispatchEvent(new Event("message")); + diff --git a/client/javascript/main.js b/client/javascript/main.js index 9af1bb4..9ca619f 100644 --- a/client/javascript/main.js +++ b/client/javascript/main.js @@ -30,6 +30,8 @@ var wasm_ready = false; var version_dict = null; var api = null; var main_session = null; +const ws_events = new EventTarget(); + const libcurl_version = "__library_version__"; const wisp_version = "__wisp_version__"; diff --git a/client/javascript/session.js b/client/javascript/session.js index c6c8d9a..91981b6 100644 --- a/client/javascript/session.js +++ b/client/javascript/session.js @@ -20,6 +20,9 @@ class CurlSession { }, "viii"); this.request_callbacks = {}; this.last_request_id = 0; + + this.ws_event_listener = () => {this.event_loop_func()}; + ws_events.addEventListener("message", this.ws_event_listener); } assert_ready() { @@ -97,7 +100,7 @@ class CurlSession { if (this.event_loop) { return; } - + this.event_loop = setInterval(() => { this.event_loop_func(); }, 0); @@ -108,7 +111,7 @@ class CurlSession { if (libcurl_active || this.active_requests) { _session_perform(this.session_ptr); } - else { + else if (this.event_loop) { clearInterval(this.event_loop); this.event_loop = null; } @@ -120,6 +123,7 @@ class CurlSession { } _session_cleanup(this.session_ptr); this.session_ptr = null; + ws_events.removeEventListener(this.ws_event_listener); Module.removeFunction(this.end_callback_ptr); Module.removeFunction(this.headers_callback_ptr); Module.removeFunction(this.data_callback_ptr); From 59de256621b57a3f40984ffea41b8390392e01c7 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Tue, 29 Oct 2024 20:43:44 -0700 Subject: [PATCH 5/8] increase libcurl's internal buffer size to 512kb --- CHANGELOG.md | 5 ++++- client/libcurl/request.c | 3 ++- client/package.json | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ef3ab6..b7cdfe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Libcurl.js Changelog: -## v0.6.17 (10/2/24): +## v0.6.18 (10/29/24): +- Improve download speeds by increasing libcurl's internal buffer size and listening directly for websocket messages + +## v0.6.17 (10/24/24): - Enable a per host connection limit. This defaults to 6, which is the same as most web browsers. - Use the latest WolfSSL again and compile with workarounds - Upgrade to curl 8.10.1 diff --git a/client/libcurl/request.c b/client/libcurl/request.c index a6f7c20..b9e6f51 100644 --- a/client/libcurl/request.c +++ b/client/libcurl/request.c @@ -43,7 +43,8 @@ CURL* create_request(const char* url, int request_id, DataCallback data_callback curl_easy_setopt(http_handle, CURLOPT_PRIVATE, request_info); curl_easy_setopt(http_handle, CURLOPT_URL, url); - curl_easy_setopt(http_handle, CURLOPT_CAINFO_BLOB , cacert_blob); + curl_easy_setopt(http_handle, CURLOPT_CAINFO_BLOB, cacert_blob); + curl_easy_setopt(http_handle, CURLOPT_BUFFERSIZE, 512*1024); //callbacks to pass the response data back to js curl_easy_setopt(http_handle, CURLOPT_WRITEFUNCTION, &write_function); diff --git a/client/package.json b/client/package.json index 9144589..7e50bb8 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "libcurl.js", - "version": "0.6.17", + "version": "0.6.18", "description": "A port of libcurl to WebAssembly, for proxying HTTPS requests from the browser with full TLS encryption", "main": "libcurl.mjs", "exports": { From 04aa226b2df19871b44f08e721dde1939b8ab200 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Tue, 29 Oct 2024 23:51:59 -0400 Subject: [PATCH 6/8] fix removeeventlistener and copyright dates --- README.md | 2 +- client/javascript/main.js | 2 +- client/javascript/session.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 424bc16..15a9f1e 100644 --- a/README.md +++ b/README.md @@ -311,7 +311,7 @@ This project is licensed under the GNU AGPL v3. ### Copyright Notice: ``` ading2210/libcurl.js - A port of libcurl to WASM for use in the browser. -Copyright (C) 2023 ading2210 +Copyright (C) 2024 ading2210 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by diff --git a/client/javascript/main.js b/client/javascript/main.js index 9ca619f..a6f93c9 100644 --- a/client/javascript/main.js +++ b/client/javascript/main.js @@ -1,6 +1,6 @@ /* ading2210/libcurl.js - A port of libcurl to WASM for the browser. -Copyright (C) 2023 ading2210 +Copyright (C) 2024 ading2210 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by diff --git a/client/javascript/session.js b/client/javascript/session.js index 91981b6..fdb2a69 100644 --- a/client/javascript/session.js +++ b/client/javascript/session.js @@ -123,7 +123,7 @@ class CurlSession { } _session_cleanup(this.session_ptr); this.session_ptr = null; - ws_events.removeEventListener(this.ws_event_listener); + ws_events.removeEventListener("message", this.ws_event_listener); Module.removeFunction(this.end_callback_ptr); Module.removeFunction(this.headers_callback_ptr); Module.removeFunction(this.data_callback_ptr); From 0897769f70af20923b7f4ccce3e7ebb8d4ff0249 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Sun, 3 Nov 2024 22:15:36 -0800 Subject: [PATCH 7/8] Revert "improve download speeds by listening directly for ws messages" This reverts commit 40044096500ea7a79591c05d9bd80dc9fe18946a. --- client/fragments/notify_ws_events.js | 5 ----- client/javascript/main.js | 2 -- client/javascript/session.js | 8 ++------ 3 files changed, 2 insertions(+), 13 deletions(-) delete mode 100644 client/fragments/notify_ws_events.js diff --git a/client/fragments/notify_ws_events.js b/client/fragments/notify_ws_events.js deleted file mode 100644 index dffb26c..0000000 --- a/client/fragments/notify_ws_events.js +++ /dev/null @@ -1,5 +0,0 @@ -/* INSERT -Module\[['"]websocket['"]\]\.emit\(['"]message['"], ?sock\.stream\.fd\) -*/ -; ws_events.dispatchEvent(new Event("message")); - diff --git a/client/javascript/main.js b/client/javascript/main.js index a6f93c9..47ee3e9 100644 --- a/client/javascript/main.js +++ b/client/javascript/main.js @@ -30,8 +30,6 @@ var wasm_ready = false; var version_dict = null; var api = null; var main_session = null; -const ws_events = new EventTarget(); - const libcurl_version = "__library_version__"; const wisp_version = "__wisp_version__"; diff --git a/client/javascript/session.js b/client/javascript/session.js index fdb2a69..c6c8d9a 100644 --- a/client/javascript/session.js +++ b/client/javascript/session.js @@ -20,9 +20,6 @@ class CurlSession { }, "viii"); this.request_callbacks = {}; this.last_request_id = 0; - - this.ws_event_listener = () => {this.event_loop_func()}; - ws_events.addEventListener("message", this.ws_event_listener); } assert_ready() { @@ -100,7 +97,7 @@ class CurlSession { if (this.event_loop) { return; } - + this.event_loop = setInterval(() => { this.event_loop_func(); }, 0); @@ -111,7 +108,7 @@ class CurlSession { if (libcurl_active || this.active_requests) { _session_perform(this.session_ptr); } - else if (this.event_loop) { + else { clearInterval(this.event_loop); this.event_loop = null; } @@ -123,7 +120,6 @@ class CurlSession { } _session_cleanup(this.session_ptr); this.session_ptr = null; - ws_events.removeEventListener("message", this.ws_event_listener); Module.removeFunction(this.end_callback_ptr); Module.removeFunction(this.headers_callback_ptr); Module.removeFunction(this.data_callback_ptr); From 8e5a23adf2ad6f063fa05aa667bfe3581c6f702a Mon Sep 17 00:00:00 2001 From: ading2210 Date: Sun, 3 Nov 2024 22:54:22 -0800 Subject: [PATCH 8/8] improve speeds and fix invalid mime type in blobs --- CHANGELOG.md | 4 ++++ client/javascript/http.js | 11 +++++++++++ client/javascript/session.js | 3 +-- client/package.json | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7cdfe3..bfb84cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Libcurl.js Changelog: +## v0.6.19 (11/1/24): +- Improve download speeds even more by reducing memory copies +- Fix wrong mime type being reported in response blob + ## v0.6.18 (10/29/24): - Improve download speeds by increasing libcurl's internal buffer size and listening directly for websocket messages diff --git a/client/javascript/http.js b/client/javascript/http.js index 64273fb..62843c4 100644 --- a/client/javascript/http.js +++ b/client/javascript/http.js @@ -157,6 +157,17 @@ class HTTPSession extends CurlSession { for (let [header_name, header_value] of response_info.headers) { response_obj.headers.append(header_name, header_value); } + + //hack to fix invalid blob type + let response_proto = Object.getPrototypeOf(response_obj); + response_obj.blob = async () => { + let blob = await response_proto.blob.call(response_obj); + let mime_type = blob.type.split(";")[0].trim(); + Object.defineProperty(blob, "type", { + value: mime_type + }); + return blob; + } return response_obj; } diff --git a/client/javascript/session.js b/client/javascript/session.js index c6c8d9a..1c7795b 100644 --- a/client/javascript/session.js +++ b/client/javascript/session.js @@ -41,8 +41,7 @@ class CurlSession { data_callback(request_id, chunk_ptr, chunk_size) { let data = Module.HEAPU8.subarray(chunk_ptr, chunk_ptr + chunk_size); - let chunk = new Uint8Array(data); - this.request_callbacks[request_id].data(chunk); + this.request_callbacks[request_id].data(data); } headers_callback(request_id, chunk_ptr, chunk_size) { diff --git a/client/package.json b/client/package.json index 7e50bb8..de4efa9 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "libcurl.js", - "version": "0.6.18", + "version": "0.6.19", "description": "A port of libcurl to WebAssembly, for proxying HTTPS requests from the browser with full TLS encryption", "main": "libcurl.mjs", "exports": {