mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-13 22:40:01 -04:00
various bugfixes
This commit is contained in:
parent
a5a537423e
commit
5f71e27422
3 changed files with 21 additions and 8 deletions
|
@ -153,6 +153,9 @@ function merge_arrays(arrays) {
|
|||
function create_response(response_data, response_info) {
|
||||
response_info.ok = response_info.status >= 200 && response_info.status < 300;
|
||||
response_info.statusText = status_messages[response_info.status] || "";
|
||||
if (response_info.status === 204 || response_info.status === 205) {
|
||||
response_data = null;
|
||||
}
|
||||
|
||||
//construct base response object
|
||||
let response_obj = new Response(response_data, response_info);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//class for custom websocket
|
||||
|
||||
class CurlWebSocket extends EventTarget {
|
||||
constructor(url, protocols=[]) {
|
||||
constructor(url, protocols=[], websocket_debug=false) {
|
||||
super();
|
||||
check_loaded(true);
|
||||
if (!url.startsWith("wss://") && !url.startsWith("ws://")) {
|
||||
|
@ -12,6 +12,7 @@ class CurlWebSocket extends EventTarget {
|
|||
this.protocols = protocols;
|
||||
this.binaryType = "blob";
|
||||
this.recv_buffer = [];
|
||||
this.websocket_debug = websocket_debug;
|
||||
|
||||
//legacy event handlers
|
||||
this.onopen = () => {};
|
||||
|
@ -33,7 +34,16 @@ class CurlWebSocket extends EventTarget {
|
|||
let finish_callback = (error, response_info) => {
|
||||
this.finish_callback(error, response_info);
|
||||
}
|
||||
this.http_handle = perform_request(this.url, {}, data_callback, finish_callback, null);
|
||||
let options = {};
|
||||
if (this.protocols) {
|
||||
options.headers = {
|
||||
"Sec-Websocket-Protocol": this.protocols.join(", "),
|
||||
};
|
||||
}
|
||||
if (this.websocket_debug) {
|
||||
options._libcurl_verbose = 1;
|
||||
}
|
||||
this.http_handle = perform_request(this.url, options, data_callback, finish_callback, null);
|
||||
this.recv_loop();
|
||||
}
|
||||
|
||||
|
@ -153,15 +163,15 @@ class CurlWebSocket extends EventTarget {
|
|||
if (ArrayBuffer.isView(data) && data instanceof DataView) {
|
||||
data_array = new Uint8Array(data.buffer);
|
||||
}
|
||||
//regular typed arrays
|
||||
else if (ArrayBuffer.isView(data)) {
|
||||
data_array = Uint8Array.from(data);
|
||||
}
|
||||
//regular arraybuffers
|
||||
else {
|
||||
data_array = new Uint8Array(data);
|
||||
}
|
||||
}
|
||||
//regular typed arrays
|
||||
else if (ArrayBuffer.isView(data)) {
|
||||
data_array = Uint8Array.from(data);
|
||||
}
|
||||
else {
|
||||
throw "invalid data type to be sent";
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "libcurl.js",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.2",
|
||||
"description": "An experimental port of libcurl to WebAssembly for use in the browser.",
|
||||
"main": "libcurl.mjs",
|
||||
"scripts": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue