more bugfixes, update docs

This commit is contained in:
ading2210 2024-03-20 03:00:39 -04:00
parent 1730e6d964
commit 2c04f55a5e
3 changed files with 21 additions and 6 deletions

View file

@ -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

View file

@ -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.

View file

@ -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();
}