Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ossiana/node-libcurl

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ossiana/node-libcurl - npm Package Compare versions

Comparing version 1.1.0-alpha-1 to 1.1.0-alpha-4

79

dist/fetch.js
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -15,42 +6,40 @@ exports.fetch = void 0;

const utils_1 = require("./utils");
function fetch(url, request = {}) {
return __awaiter(this, void 0, void 0, function* () {
request.instance || (request.instance = new libcurl_1.LibCurl());
const curl = request.instance;
const { method = "GET", headers, redirect = false, httpVersion = 0, openInnerLog = false, proxy, body, cookies } = request;
curl.open(method, url + '', true);
if (headers) {
curl.setRequestHeaders(headers);
}
if (redirect) {
curl.setRedirect(true);
}
if (httpVersion) {
curl.setHttpVersion(httpVersion);
}
if (openInnerLog) {
curl.printInnerLogger();
}
async function fetch(url, request = {}) {
request.instance ||= new libcurl_1.LibCurl();
const curl = request.instance;
const { method = "GET", headers, redirect = false, httpVersion = 0, openInnerLog = false, proxy, body, cookies } = request;
curl.open(method, url + '', true);
if (headers) {
curl.setRequestHeaders(headers);
}
if (redirect) {
curl.setRedirect(true);
}
if (httpVersion) {
curl.setHttpVersion(httpVersion);
}
if (openInnerLog) {
curl.printInnerLogger();
}
if (cookies) {
const { hostname } = new URL(url);
if (cookies) {
const { hostname } = new URL(url);
if (cookies) {
(0, utils_1.libcurlSetCookies)(curl, cookies, hostname);
}
(0, utils_1.libcurlSetCookies)(curl, cookies, hostname);
}
if (proxy) {
curl.setProxy(proxy);
}
yield curl.send(body);
return {
status: () => curl.getResponseStatus(),
arraybuffer: () => __awaiter(this, void 0, void 0, function* () { return curl.getResponseBody().buffer; }),
text: () => __awaiter(this, void 0, void 0, function* () { return curl.getResponseString(); }),
json: () => __awaiter(this, void 0, void 0, function* () { return curl.getResponseJson(); }),
headers: () => __awaiter(this, void 0, void 0, function* () { return curl.getResponseHeaders(); }),
cookies: () => __awaiter(this, void 0, void 0, function* () { return curl.getCookies(); }),
cookiesMap: () => __awaiter(this, void 0, void 0, function* () { return curl.getCookiesMap(); }),
};
});
}
if (proxy) {
curl.setProxy(proxy);
}
await curl.send(body);
return {
status: () => curl.getResponseStatus(),
arraybuffer: async () => curl.getResponseBody().buffer,
text: async () => curl.getResponseString(),
json: async () => curl.getResponseJson(),
headers: async () => curl.getResponseHeaders(),
cookies: async () => curl.getCookies(),
cookiesMap: async () => curl.getCookiesMap(),
};
}
exports.fetch = fetch;
//# sourceMappingURL=fetch.js.map

@@ -22,2 +22,5 @@ "use strict";

class LibCurl {
m_libCurl_impl_;
m_isAsync_;
m_isSending_;
constructor() {

@@ -24,0 +27,0 @@ this.m_libCurl_impl_ = new BaoLibCurl();

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -16,2 +7,3 @@ exports.requests = void 0;

class requestsResponse {
curl;
constructor(curl) {

@@ -45,7 +37,7 @@ this.curl = curl;

class requests {
option;
constructor(option = {}) {
var _a;
this.option = Object.assign({}, option);
this.option = { ...option };
const { cookies, timeout, verbose } = option;
const curl = (_a = this.option).instance || (_a.instance = new libcurl_1.LibCurl());
const curl = this.option.instance ||= new libcurl_1.LibCurl();
if (cookies) {

@@ -64,61 +56,37 @@ (0, utils_1.libcurlSetCookies)(curl, cookies, '.');

}
static get(url, requestOpt) {
return __awaiter(this, void 0, void 0, function* () {
return requests.sendRequestStaic('GET', url, requestOpt);
});
static async get(url, requestOpt) {
return requests.sendRequestStaic('GET', url, requestOpt);
}
static post(url, requestOpt) {
return __awaiter(this, void 0, void 0, function* () {
return requests.sendRequestStaic('POST', url, requestOpt);
});
static async post(url, requestOpt) {
return requests.sendRequestStaic('POST', url, requestOpt);
}
static put(url, requestOpt) {
return __awaiter(this, void 0, void 0, function* () {
return requests.sendRequestStaic('PUT', url, requestOpt);
});
static async put(url, requestOpt) {
return requests.sendRequestStaic('PUT', url, requestOpt);
}
static patch(url, requestOpt) {
return __awaiter(this, void 0, void 0, function* () {
return requests.sendRequestStaic('PATCH', url, requestOpt);
});
static async patch(url, requestOpt) {
return requests.sendRequestStaic('PATCH', url, requestOpt);
}
static trace(url, requestOpt) {
return __awaiter(this, void 0, void 0, function* () {
return requests.sendRequestStaic('TRACE', url, requestOpt);
});
static async trace(url, requestOpt) {
return requests.sendRequestStaic('TRACE', url, requestOpt);
}
static head(url, requestOpt) {
return __awaiter(this, void 0, void 0, function* () {
return requests.sendRequestStaic('HEAD', url, requestOpt);
});
static async head(url, requestOpt) {
return requests.sendRequestStaic('HEAD', url, requestOpt);
}
get(url, requestOpt) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendRequest('GET', url, requestOpt);
});
async get(url, requestOpt) {
return this.sendRequest('GET', url, requestOpt);
}
post(url, requestOpt) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendRequest('POST', url, requestOpt);
});
async post(url, requestOpt) {
return this.sendRequest('POST', url, requestOpt);
}
put(url, requestOpt) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendRequest('PUT', url, requestOpt);
});
async put(url, requestOpt) {
return this.sendRequest('PUT', url, requestOpt);
}
patch(url, requestOpt) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendRequest('PATCH', url, requestOpt);
});
async patch(url, requestOpt) {
return this.sendRequest('PATCH', url, requestOpt);
}
trace(url, requestOpt) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendRequest('TRACE', url, requestOpt);
});
async trace(url, requestOpt) {
return this.sendRequest('TRACE', url, requestOpt);
}
head(url, requestOpt) {
return __awaiter(this, void 0, void 0, function* () {
return this.sendRequest('HEAD', url, requestOpt);
});
async head(url, requestOpt) {
return this.sendRequest('HEAD', url, requestOpt);
}

@@ -165,87 +133,87 @@ setCookie(key, value, domain = '', path = '') {

}
sendRequest(method, url, requestOpt) {
return __awaiter(this, void 0, void 0, function* () {
const { instance: curl, redirect = false, proxy, httpVersion } = this.option;
const { headers, data, json, params } = requestOpt || {};
if (data && json) {
throw new libcurl_1.LibCurlError('both data and json exist');
async sendRequest(method, url, requestOpt) {
const { instance: curl, redirect = false, proxy, httpVersion } = this.option;
const { headers, data, json, params } = requestOpt || {};
if (data && json) {
throw new libcurl_1.LibCurlError('both data and json exist');
}
const url_ = new URL(url);
if (params) {
assignURLSearchParam(url_.searchParams, new URLSearchParams(params));
}
curl.open(method, url_, true);
if (headers) {
curl.setRequestHeaders(headers);
}
if (redirect) {
curl.setRedirect(true);
}
if (httpVersion) {
curl.setHttpVersion(httpVersion);
}
if (proxy) {
curl.setProxy(proxy);
}
let hasContentType = false;
if (headers && (data || json)) {
const contentTypeFilter = (e) => e.some(e => e.toLocaleLowerCase() == 'content-type');
if (typeof headers == 'string') {
hasContentType = /content-type/i.test(headers);
}
const url_ = new URL(url);
if (params) {
assignURLSearchParam(url_.searchParams, new URLSearchParams(params));
else if (headers instanceof Map) {
hasContentType = contentTypeFilter([...headers.keys()]);
}
curl.open(method, url_, true);
if (headers) {
curl.setRequestHeaders(headers);
else {
hasContentType = contentTypeFilter(Object.keys(headers));
}
if (redirect) {
curl.setRedirect(true);
}
if (json) {
if (!hasContentType) {
curl.setRequestHeader('Content-Type', 'application/json');
}
if (httpVersion) {
curl.setHttpVersion(httpVersion);
}
if (proxy) {
curl.setProxy(proxy);
}
let hasContentType = false;
if (data || json) {
const contentTypeFilter = (e) => e.some(e => e.toLocaleLowerCase() == 'content-type');
if (typeof headers == 'string') {
hasContentType = /content-type/i.test(headers);
await curl.send(json);
}
else if (data) {
let sendData = data;
if (!hasContentType) {
if (typeof data == 'string') {
curl.setRequestHeader('Content-Type', 'text/plain');
}
else if (headers instanceof Map) {
hasContentType = contentTypeFilter([...headers.keys()]);
else if (data instanceof URLSearchParams) {
curl.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
else {
hasContentType = contentTypeFilter(Object.keys(headers));
else if (data instanceof Uint8Array) {
curl.setRequestHeader('Content-Type', 'application/octet-stream');
}
}
if (json) {
if (!hasContentType) {
curl.setRequestHeader('Content-Type', 'application/json');
}
yield curl.send(json);
}
else if (data) {
let sendData = data;
if (!hasContentType) {
if (typeof data == 'string') {
curl.setRequestHeader('Content-Type', 'text/plain');
if (typeof data == 'object' && data != null) {
curl.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
sendData = Object.keys(data).map((e) => {
const value = data[e];
const type = typeof value;
if (['object', 'boolean'].includes(type)) {
return [e, JSON.stringify(value)];
}
else if (data instanceof URLSearchParams) {
curl.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
else if (type == 'undefined') {
return [e, ''];
}
else if (data instanceof Uint8Array) {
curl.setRequestHeader('Content-Type', 'application/octet-stream');
else if (['string', 'number'].includes(type)) {
return [e, value + ''];
}
else {
sendData = Object.keys(data).map((e) => {
const value = data[e];
const type = typeof value;
if (['object', 'boolean', 'number']) {
return [e, JSON.stringify(value)];
}
else if (type == 'undefined') {
return [e, ''];
}
else if (type == 'string') {
return [e, value];
}
else {
throw new libcurl_1.LibCurlError(`data unkown type ${type}`);
}
})
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
.join('&');
throw new libcurl_1.LibCurlError(`data unkown type ${type}`);
}
}
yield curl.send(sendData);
})
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
.join('&');
}
return new requestsResponse(curl);
});
await curl.send(sendData);
}
else {
await curl.send();
}
return new requestsResponse(curl);
}
static sendRequestStaic(method, url, requestStaticOpt) {
return __awaiter(this, void 0, void 0, function* () {
return requests.session(requestStaticOpt).sendRequest(method, url, requestStaticOpt);
});
static async sendRequestStaic(method, url, requestStaticOpt) {
return requests.session(requestStaticOpt).sendRequest(method, url, requestStaticOpt);
}

@@ -252,0 +220,0 @@ }

@@ -39,7 +39,7 @@ "use strict";

const cookieOptFilter = (cookieOpt) => {
const domainArr = (cookieOpt === null || cookieOpt === void 0 ? void 0 : cookieOpt.domain) && getSubdomains(cookieOpt.domain);
const domainArr = cookieOpt?.domain && getSubdomains(cookieOpt.domain);
return (e) => {
if (domainArr && !domainArr.find(t => e[0] === t))
return false;
if (cookieOpt === null || cookieOpt === void 0 ? void 0 : cookieOpt.path) {
if (cookieOpt?.path) {
if (cookieOpt.path != e[2])

@@ -46,0 +46,0 @@ return false;

{
"name": "@ossiana/node-libcurl",
"version": "1.1.0-alpha-1",
"version": "1.1.0-alpha-4",
"dependencies": {

@@ -11,4 +11,3 @@ "@mapbox/node-pre-gyp": "^1.0.10",

"test": "node ./test/libcurl_test.js",
"install": "node-pre-gyp install && npm run build:dev",
"build:dev": "node-pre-gyp configure --node_use_openssl=false --openssl_quic=false --node_shared_openssl=false && node-pre-gyp -j 16 build --release",
"install": "node-pre-gyp install --fallback-to-build --update-binary && node-gyp rebuild --update-binary",
"unittest": "mocha",

@@ -22,3 +21,3 @@ "tsc": "tsc -p tsconfig.json"

"host": "https://ossianaa.github.io/static/github/release/node-libcurl/",
"remote_path": "v1.0.0"
"remote_path": "v1.0.1"
},

@@ -42,2 +41,2 @@ "devDependencies": {

}
}
}
{
"compilerOptions": {
"target": "es6",
"target": "es2022",
"module": "commonjs",

@@ -5,0 +5,0 @@ "declaration": true,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc