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

node-curl-impersonate

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-curl-impersonate - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

2

dist/index.d.ts

@@ -20,4 +20,6 @@ interface CurlImpersonateOptions {

setProperBinary(): void;
getRequest(flags: Array<string>, headers: string): void;
postRequest(flags: Array<string>, headers: string): void;
convertHeaderObjectToCURL(): string;
}
export default CurlImpersonate;

41

dist/index.js
import * as proc from "child_process";
import { fileURLToPath } from 'url';
import * as path from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export class CurlImpersonate {

@@ -18,12 +15,8 @@ constructor(url, options) {

let flags = this.options.flags || [];
if (this.options.method == "GET") {
if (this.options.followRedirects) {
flags.push("-L");
}
if (this.options.timeout) {
flags.push(`--connect-timeout ${this.options.timeout / 1000}`);
}
let binpath = path.join(__dirname, "..", "bin", this.binary);
let args = `${flags.join(" ")} ${headers} ${this.url}`;
proc.spawn(`${binpath} ${args}`, { shell: true, stdio: "inherit" });
switch (this.options.method.toUpperCase()) {
case "GET":
this.getRequest(flags, headers);
break;
case "POST":
this.postRequest(flags, headers);
}

@@ -72,2 +65,24 @@ }

}
getRequest(flags, headers) {
if (this.options.followRedirects) {
flags.push("-L");
}
if (this.options.timeout) {
flags.push(`--connect-timeout ${this.options.timeout / 1000}`);
}
let binpath = path.join(__dirname, "..", "bin", this.binary);
let args = `${flags.join(" ")} ${headers} ${this.url}`;
proc.spawn(`${binpath} ${args}`, { shell: true, stdio: "inherit" });
}
postRequest(flags, headers) {
if (this.options.followRedirects) {
flags.push("-L");
}
if (this.options.timeout) {
flags.push(`--connect-timeout ${this.options.timeout / 1000}`);
}
let binpath = path.join(__dirname, "..", "bin", this.binary);
let args = `${flags.join(" ")} ${headers} -d '${JSON.stringify(this.options.body)}' ${this.url}`;
proc.spawn(`${binpath} ${args}`, { shell: true, stdio: "inherit" });
}
convertHeaderObjectToCURL() {

@@ -74,0 +89,0 @@ return Object.entries(this.options.headers).map(([key, value]) => `-H '${key}: ${value}'`).join(' ');

{
"name": "node-curl-impersonate",
"version": "1.0.6",
"version": "1.0.7",
"description": "A wrapper around cURL-impersonate, a binary which can be used to bypass TLS fingerprinting.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -10,9 +10,6 @@ /*

import * as proc from "child_process";
import { fileURLToPath } from 'url';
import * as path from 'path';
import { inherits } from "util";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
/*

@@ -22,3 +19,3 @@

method: A string that should read any of the many HTTP methods, GET, POST, PATCH, PUT, OPTIONS, DELETE.
method: A string that should read HTTP methods, GET or POST.
headers: HTTP Headers in the form of a key:value pair object.

@@ -61,14 +58,18 @@ body: Only required if using a method such as POST or any other option that requires a payload.

let flags = this.options.flags || [];
if (this.options.method == "GET") {
// GET REQUEST
if (this.options.followRedirects) {
flags.push("-L")
}
if (this.options.timeout) {
flags.push(`--connect-timeout ${this.options.timeout / 1000}`)
}
let binpath = path.join(__dirname, "..", "bin", this.binary)
let args = `${flags.join(" ")} ${headers} ${this.url}`
proc.spawn(`${binpath} ${args}`, { shell: true, stdio: "inherit" })
if (this.options.followRedirects) {
flags.push("-L")
}
if (this.options.timeout) {
flags.push(`--connect-timeout ${this.options.timeout / 1000}`)
}
switch (this.options.method.toUpperCase()) {
case "GET":
this.getRequest(flags, headers);
break;
case "POST":
this.postRequest(flags, headers);
break;
default:
throw new Error("Invalid Method! Valid HTTP methods are " + this.validMethods)
}
}

@@ -111,2 +112,14 @@ }

}
getRequest(flags: Array<string>, headers: string) {
// GET REQUEST
let binpath = path.join(__dirname, "..", "bin", this.binary)
let args = `${flags.join(" ")} ${headers} ${this.url}`
proc.spawn(`${binpath} ${args}`, { shell: true, stdio: "inherit" })
}
postRequest(flags: Array<string>, headers: string) {
// POST REQUEST
let binpath = path.join(__dirname, "..", "bin", this.binary)
let args = `${flags.join(" ")} ${headers} -d '${JSON.stringify(this.options.body)}' ${this.url}`
proc.spawn(`${binpath} ${args}`, { shell: true, stdio: "inherit" })
}
convertHeaderObjectToCURL() {

@@ -113,0 +126,0 @@ return Object.entries(this.options.headers).map(([key, value]) => `-H '${key}: ${value}'`).join(' ');

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