From 2c04f55a5e2dc5f152321619ad104c1bb1846ee2 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Wed, 20 Mar 2024 03:00:39 -0400 Subject: [PATCH] more bugfixes, update docs --- CHANGELOG.md | 2 +- README.md | 11 +++++++++-- client/javascript/main.js | 14 +++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 069d43d..506cc43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Libcurl.js Changelog: -## v0.6.0 (3/19/24): +## v0.6.0 (3/20/24): - Refactor JS and C code - Allow for multiple sessions with separate connection pools - Switch to wolfSSL instead of OpenSSL for significantly smaller binaries diff --git a/README.md b/README.md index f34e415..ba1c166 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,9 @@ This is an experimental port of [libcurl](https://curl.se/libcurl/) to WebAssemb - Custom network transport support - Works inside web workers without needing special permissions or headers - Works in all major browsers (Chromium >= 64, Firefox >= 65, Safari >= 14) +- Has the ability to create multiple independent sessions +- Small footprint size (800kb after compression) and low runtime memory usage +- Support for running inside a web worker ## Building: You can build this project by running the following commands: @@ -77,14 +80,18 @@ document.addEventListener("libcurl_load", ()=>{ }); ``` -You may also use the, the `libcurl.onload` callback, which can be useful for running libcurl.js inside a web worker. +You may also use the, the `libcurl.onload` callback, which can be useful for running libcurl.js inside a web worker. ```js libcurl.onload = () => { console.log("libcurl.js ready!"); } ``` -Once loaded, there will be a `window.libcurl` object which includes all the API functions. The `libcurl.ready` property can also be used to know if the WASM has loaded. +Once loaded, there will be a `window.libcurl` object which includes all the API functions. The `libcurl.ready` property can also be used to know if the WASM has loaded. + +There are also ES6 modules available if you are using a bundler. The `libcurl.mjs` and `libcurl_full.mjs` files provide this functionality, with the former being set as the entry point for the NPM package. + +Examples of running libcurl.js on the main thread and in a web worker are available at `client/index.html` and `client/worker.html` respectively. ### Making HTTP Requests: To perform HTTP requests, use `libcurl.fetch`, which takes the same arguments as the browser's regular `fetch` function. Like the standard Fetch API, `libcurl.fetch` will also return a `Response` object. diff --git a/client/javascript/main.js b/client/javascript/main.js index 93d8ec5..37f2efb 100644 --- a/client/javascript/main.js +++ b/client/javascript/main.js @@ -46,6 +46,9 @@ function set_websocket_url(url) { if (Module.websocket) { Module.websocket.url = url; } + if (!main_session && wasm_ready) { + setup_main_session(); + } } function get_version() { @@ -65,18 +68,23 @@ function get_cacert() { return UTF8ToString(_get_cacert()); } +function setup_main_session() { + main_session = new HTTPSession(); + api.fetch = main_session.fetch.bind(main_session); +} + function main() { wasm_ready = true; _init_curl(); - set_websocket_url(websocket_url); if (ENVIRONMENT_IS_WEB) { let load_event = new Event("libcurl_load"); document.dispatchEvent(load_event); } - main_session = new HTTPSession(); - api.fetch = main_session.fetch.bind(main_session); + if (!main_session && websocket_url) { + setup_main_session(); + } api.onload(); }