diff --git a/CHANGELOG.md b/CHANGELOG.md index bfb84cb..a97d187 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Libcurl.js Changelog: +## v0.6.20 (11/10/24): +- Fix bug with response body getting corrupted + ## v0.6.19 (11/1/24): - Improve download speeds even more by reducing memory copies - Fix wrong mime type being reported in response blob diff --git a/README.md b/README.md index 15a9f1e..badb3d3 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@0.6.7/libcurl.js -https://cdn.jsdelivr.net/npm/libcurl.js@0.6.7/libcurl.wasm +https://cdn.jsdelivr.net/npm/libcurl.js@0.6.20/libcurl.js +https://cdn.jsdelivr.net/npm/libcurl.js@0.6.20/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. diff --git a/client/javascript/session.js b/client/javascript/session.js index 1c7795b..c6c8d9a 100644 --- a/client/javascript/session.js +++ b/client/javascript/session.js @@ -41,7 +41,8 @@ class CurlSession { data_callback(request_id, chunk_ptr, chunk_size) { let data = Module.HEAPU8.subarray(chunk_ptr, chunk_ptr + chunk_size); - this.request_callbacks[request_id].data(data); + let chunk = new Uint8Array(data); + this.request_callbacks[request_id].data(chunk); } headers_callback(request_id, chunk_ptr, chunk_size) { diff --git a/client/package.json b/client/package.json index de4efa9..1abde9e 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "libcurl.js", - "version": "0.6.19", + "version": "0.6.20", "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/tests/run_tests.py b/client/tests/run_tests.py index 6b12122..850b02b 100644 --- a/client/tests/run_tests.py +++ b/client/tests/run_tests.py @@ -64,6 +64,9 @@ class JSTest(unittest.TestCase): def test_post(self): self.run_test("test_post.js") + + def test_download_hash(self): + self.run_test("test_download_hash.js") if __name__ == "__main__": unittest.main() \ No newline at end of file diff --git a/client/tests/scripts/test_download_hash.js b/client/tests/scripts/test_download_hash.js new file mode 100644 index 0000000..4b0e46d --- /dev/null +++ b/client/tests/scripts/test_download_hash.js @@ -0,0 +1,20 @@ +//https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#examples +async function digestMessage(msgUint8) { + const hashBuffer = await window.crypto.subtle.digest("SHA-256", msgUint8); // hash the message + const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array + const hashHex = hashArray + .map((b) => b.toString(16).padStart(2, "0")) + .join(""); // convert bytes to hex string + return hashHex; +} + +async function test() { + let url = "https://curl.se/download/curl-8.11.0.tar.gz"; + let expected_hash = "264537d90e58d2b09dddc50944baf3c38e7089151c8986715e2aaeaaf2b8118f"; + + let r = await libcurl.fetch(url); + let msg = new Uint8Array(await r.arrayBuffer()); + let hash = await digestMessage(msg); + + assert(hash === expected_hash, "unexpected hash of downloaded data"); +} \ No newline at end of file