mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-13 14:30:02 -04:00
fix bug with response body, add test for download hash
This commit is contained in:
parent
8e5a23adf2
commit
82249fe707
6 changed files with 31 additions and 4 deletions
|
@ -1,5 +1,8 @@
|
||||||
# Libcurl.js Changelog:
|
# Libcurl.js Changelog:
|
||||||
|
|
||||||
|
## v0.6.20 (11/10/24):
|
||||||
|
- Fix bug with response body getting corrupted
|
||||||
|
|
||||||
## v0.6.19 (11/1/24):
|
## v0.6.19 (11/1/24):
|
||||||
- Improve download speeds even more by reducing memory copies
|
- Improve download speeds even more by reducing memory copies
|
||||||
- Fix wrong mime type being reported in response blob
|
- Fix wrong mime type being reported in response blob
|
||||||
|
|
|
@ -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.
|
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.20/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.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.
|
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.
|
||||||
|
|
|
@ -41,7 +41,8 @@ class CurlSession {
|
||||||
|
|
||||||
data_callback(request_id, chunk_ptr, chunk_size) {
|
data_callback(request_id, chunk_ptr, chunk_size) {
|
||||||
let data = Module.HEAPU8.subarray(chunk_ptr, 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) {
|
headers_callback(request_id, chunk_ptr, chunk_size) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "libcurl.js",
|
"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",
|
"description": "A port of libcurl to WebAssembly, for proxying HTTPS requests from the browser with full TLS encryption",
|
||||||
"main": "libcurl.mjs",
|
"main": "libcurl.mjs",
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|
|
@ -65,5 +65,8 @@ class JSTest(unittest.TestCase):
|
||||||
def test_post(self):
|
def test_post(self):
|
||||||
self.run_test("test_post.js")
|
self.run_test("test_post.js")
|
||||||
|
|
||||||
|
def test_download_hash(self):
|
||||||
|
self.run_test("test_download_hash.js")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
20
client/tests/scripts/test_download_hash.js
Normal file
20
client/tests/scripts/test_download_hash.js
Normal file
|
@ -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");
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue