add nodejs support

This commit is contained in:
ading2210 2025-02-13 16:12:03 -05:00
parent 3a2ab40e75
commit 87b887a4b7
13 changed files with 78 additions and 18 deletions

View file

@ -193,7 +193,7 @@ class HTTPSession extends CurlSession {
if (params.referrer) {
params.headers["Referer"] = params.referrer;
}
if (!params.headers["User-Agent"]) {
if (!params.headers["User-Agent"] && typeof navigator === "object") {
params.headers["User-Agent"] = navigator.userAgent;
}
if (body && !params.headers["Content-Type"]) {

View file

@ -5,7 +5,7 @@ Licensed under the GNU LGPL v3. See https://github.com/ading2210/libcurl.js
*/
//everything is wrapped in a function to prevent emscripten from polluting the global scope
const libcurl = (function() {
export const libcurl = (function() {
//emscripten compiled code is inserted here
/* __emscripten_output__ */
@ -21,6 +21,8 @@ var main_session = null;
const libcurl_version = "__library_version__";
const wisp_version = "__wisp_version__";
const WSImpl = (typeof process !== "undefined" && typeof WebSocket === "undefined") ? require("ws").WebSocket : WebSocket;
function check_loaded(check_websocket) {
if (!wasm_ready) {
throw new Error("wasm not loaded yet, please call libcurl.load_wasm first");
@ -149,4 +151,6 @@ api = {
return api;
})()
})()
export default libcurl;

View file

@ -186,7 +186,7 @@ class CurlSession {
try {
stream_controller.close();
}
catch {}
catch (e) {}
end_callback(error);
}