node-curl-impersonate
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -17,9 +17,9 @@ interface CurlImpersonateOptions { | ||
constructor(url: string, options: CurlImpersonateOptions); | ||
makeRequest(): void; | ||
makeRequest(): string | undefined; | ||
validateOptions(options: CurlImpersonateOptions): boolean; | ||
setProperBinary(): void; | ||
getRequest(flags: Array<string>, headers: string): void; | ||
postRequest(flags: Array<string>, headers: string): void; | ||
getRequest(flags: Array<string>, headers: string): string; | ||
postRequest(flags: Array<string>, headers: string): string; | ||
convertHeaderObjectToCURL(): string; | ||
} | ||
export default CurlImpersonate; |
@@ -15,8 +15,15 @@ import * as proc from "child_process"; | ||
let flags = this.options.flags || []; | ||
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; | ||
return this.getRequest(flags, headers); | ||
case "POST": | ||
this.postRequest(flags, headers); | ||
return this.postRequest(flags, headers); | ||
default: | ||
throw new Error("Invalid Method! Valid HTTP methods are " + this.validMethods); | ||
} | ||
@@ -66,22 +73,12 @@ } | ||
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" }); | ||
let binpath = path.join(__dirname, '..', 'bin', this.binary); | ||
let args = `${flags.join(' ')} ${headers} ${this.url}`; | ||
const result = proc.spawnSync(`${binpath} ${args}`, { shell: true }); | ||
return result.stdout.toString(); | ||
} | ||
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" }); | ||
let binpath = path.join(__dirname, '..', 'bin', this.binary); | ||
let args = `${flags.join(' ')} ${headers} -d '${JSON.stringify(this.options.body)}' ${this.url}`; | ||
const result = proc.spawnSync(`${binpath} ${args}`, { shell: true }); | ||
return result.stdout.toString(); | ||
} | ||
@@ -88,0 +85,0 @@ convertHeaderObjectToCURL() { |
{ | ||
"name": "node-curl-impersonate", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "A wrapper around cURL-impersonate, a binary which can be used to bypass TLS fingerprinting.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -64,7 +64,5 @@ /* | ||
case "GET": | ||
this.getRequest(flags, headers); | ||
break; | ||
return this.getRequest(flags, headers); | ||
case "POST": | ||
this.postRequest(flags, headers); | ||
break; | ||
return this.postRequest(flags, headers); | ||
default: | ||
@@ -112,12 +110,16 @@ throw new Error("Invalid Method! Valid HTTP methods are " + this.validMethods) | ||
// 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" }) | ||
let binpath = path.join(__dirname, '..', 'bin', this.binary); | ||
let args = `${flags.join(' ')} ${headers} ${this.url}`; | ||
const result = proc.spawnSync(`${binpath} ${args}`, { shell: true }); | ||
return result.stdout.toString(); // Convert the stdout buffer to a string and return it | ||
} | ||
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" }) | ||
let binpath = path.join(__dirname, '..', 'bin', this.binary); | ||
let args = `${flags.join(' ')} ${headers} -d '${JSON.stringify(this.options.body)}' ${this.url}`; | ||
const result = proc.spawnSync(`${binpath} ${args}`, { shell: true }); | ||
return result.stdout.toString(); // Convert the stdout buffer to a string and return it | ||
} | ||
convertHeaderObjectToCURL() { | ||
@@ -124,0 +126,0 @@ return Object.entries(this.options.headers).map(([key, value]) => `-H '${key}: ${value}'`).join(' '); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8834016
234