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.0.9-alpha-3 to 1.0.9-alpha-5

2

dist/libcurl.d.ts

@@ -45,3 +45,3 @@ export declare enum LibCurlHttpVersionInfo {

} | LibCurlHeadersAttr;
export type LibCurlBodyInfo = string | Uint8Array | URLSearchParams | any;
export type LibCurlBodyInfo = string | Uint8Array | URLSearchParams | object;
export type LibCurlMethodInfo = 'GET' | 'POST' | 'HEAD' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';

@@ -48,0 +48,0 @@ export type LibCurlProxyWithAccountInfo = {

@@ -32,2 +32,3 @@ import { LibCurl, LibCurlBodyInfo, LibCurlCookiesAttr, LibCurlCookiesInfo, LibCurlHeadersAttr, LibCurlHeadersInfo, LibCurlProxyInfo, LibCurlHttpVersionInfo, LibCurlURLInfo } from "./libcurl";

httpVersion?: requestsHttpVersionInfo;
verbose?: boolean;
timeout?: number;

@@ -41,5 +42,8 @@ instance?: LibCurl;

headers?: requestsHeadersInfo;
body?: requestsBodyInfo;
params?: requestsParamsInfo;
json?: object;
data?: requestsBodyInfo;
}
interface requestsStaticOption extends Omit<requestsInitOption, 'body' | 'instance'>, requestsOption {
}
export declare class requests {

@@ -49,8 +53,8 @@ private option;

static session(option?: requestsInitOption): requests;
static get(url: requestsURLInfo, requestOpt?: requestsOption): Promise<requestsResponse>;
static post(url: requestsURLInfo, requestOpt?: requestsOption): Promise<requestsResponse>;
static put(url: requestsURLInfo, requestOpt?: requestsOption): Promise<requestsResponse>;
static patch(url: requestsURLInfo, requestOpt?: requestsOption): Promise<requestsResponse>;
static trace(url: requestsURLInfo, requestOpt?: requestsOption): Promise<requestsResponse>;
static head(url: requestsURLInfo, requestOpt?: requestsOption): Promise<requestsResponse>;
static get(url: requestsURLInfo, requestOpt?: requestsStaticOption): Promise<requestsResponse>;
static post(url: requestsURLInfo, requestOpt?: requestsStaticOption): Promise<requestsResponse>;
static put(url: requestsURLInfo, requestOpt?: requestsStaticOption): Promise<requestsResponse>;
static patch(url: requestsURLInfo, requestOpt?: requestsStaticOption): Promise<requestsResponse>;
static trace(url: requestsURLInfo, requestOpt?: requestsStaticOption): Promise<requestsResponse>;
static head(url: requestsURLInfo, requestOpt?: requestsStaticOption): Promise<requestsResponse>;
get(url: requestsURLInfo, requestOpt?: requestsOption): Promise<requestsResponse>;

@@ -68,3 +72,4 @@ post(url: requestsURLInfo, requestOpt?: requestsOption): Promise<requestsResponse>;

private sendRequest;
private static sendRequestStaic;
}
export {};

@@ -47,3 +47,3 @@ "use strict";

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

@@ -56,2 +56,5 @@ if (cookies) {

}
if (verbose) {
curl.printInnerLogger();
}
}

@@ -63,3 +66,3 @@ static session(option = {}) {

return __awaiter(this, void 0, void 0, function* () {
return requests.session().sendRequest('GET', url, requestOpt);
return requests.sendRequestStaic('GET', url, requestOpt);
});

@@ -69,3 +72,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return requests.session().sendRequest('POST', url, requestOpt);
return requests.sendRequestStaic('POST', url, requestOpt);
});

@@ -75,3 +78,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return requests.session().sendRequest('PUT', url, requestOpt);
return requests.sendRequestStaic('PUT', url, requestOpt);
});

@@ -81,3 +84,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return requests.session().sendRequest('PATCH', url, requestOpt);
return requests.sendRequestStaic('PATCH', url, requestOpt);
});

@@ -87,3 +90,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return requests.session().sendRequest('TRACE', url, requestOpt);
return requests.sendRequestStaic('TRACE', url, requestOpt);
});

@@ -93,3 +96,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
return requests.session().sendRequest('HEAD', url, requestOpt);
return requests.sendRequestStaic('HEAD', url, requestOpt);
});

@@ -170,3 +173,6 @@ }

const { instance: curl, redirect = false, proxy, httpVersion } = this.option;
const { headers, body, params } = requestOpt || {};
const { headers, data, json, params } = requestOpt || {};
if (data && json) {
throw new libcurl_1.LibCurlError('both data and json exist');
}
const url_ = new URL(url);

@@ -189,8 +195,66 @@ if (params) {

}
yield curl.send(body);
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);
}
else if (headers instanceof Map) {
hasContentType = contentTypeFilter([...headers.keys()]);
}
else {
hasContentType = contentTypeFilter(Object.keys(headers));
}
}
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');
}
else if (data instanceof URLSearchParams) {
curl.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
else if (data instanceof Uint8Array) {
curl.setRequestHeader('Content-Type', 'application/octet-stream');
}
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('&');
}
}
yield curl.send(sendData);
}
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);
});
}
}
exports.requests = requests;
//# sourceMappingURL=requests.js.map

@@ -39,13 +39,9 @@ "use strict";

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

@@ -52,0 +48,0 @@ return true;

{
"name": "@ossiana/node-libcurl",
"version": "1.0.9-alpha-3",
"version": "1.0.9-alpha-5",
"dependencies": {

@@ -5,0 +5,0 @@ "@mapbox/node-pre-gyp": "^1.0.10",

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