node-curl-impersonate
Advanced tools
Comparing version 1.1.7 to 1.1.8
@@ -17,9 +17,9 @@ interface CurlImpersonateOptions { | ||
constructor(url: string, options: CurlImpersonateOptions); | ||
makeRequest(): Promise<unknown> | undefined; | ||
makeRequest(): Promise<unknown>; | ||
validateOptions(options: CurlImpersonateOptions): boolean; | ||
setProperBinary(): void; | ||
getRequest(flags: Array<string>, headers: string): Promise<unknown>; | ||
postRequest(flags: Array<string>, headers: string): Promise<unknown>; | ||
getRequest(flags: Array<string>, headers: string): Promise<string>; | ||
postRequest(flags: Array<string>, headers: string): Promise<string>; | ||
convertHeaderObjectToCURL(): string; | ||
} | ||
export default CurlImpersonate; |
@@ -11,21 +11,25 @@ import * as proc from "child_process"; | ||
makeRequest() { | ||
if (this.validateOptions(this.options)) { | ||
this.setProperBinary(); | ||
const headers = this.convertHeaderObjectToCURL(); | ||
const flags = this.options.flags || []; | ||
if (this.options.followRedirects) { | ||
flags.push("-L"); | ||
return new Promise(async (resolve, reject) => { | ||
if (this.validateOptions(this.options)) { | ||
this.setProperBinary(); | ||
let headers = this.convertHeaderObjectToCURL(); | ||
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": | ||
resolve(await this.getRequest(flags, headers)); | ||
break; | ||
case "POST": | ||
resolve(await this.postRequest(flags, headers)); | ||
break; | ||
default: | ||
throw new Error("Invalid Method! Valid HTTP methods are " + this.validMethods); | ||
} | ||
} | ||
if (this.options.timeout) { | ||
flags.push(`--connect-timeout ${this.options.timeout / 1000}`); | ||
} | ||
switch (this.options.method.toUpperCase()) { | ||
case "GET": | ||
return this.getRequest(flags, headers); | ||
case "POST": | ||
return this.postRequest(flags, headers); | ||
default: | ||
throw new Error("Invalid Method! Valid HTTP methods are " + this.validMethods); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -72,29 +76,13 @@ validateOptions(options) { | ||
} | ||
getRequest(flags, headers) { | ||
const binpath = path.join(__dirname, '..', 'bin', this.binary); | ||
const args = `${flags.join(' ')} ${headers} ${this.url}`; | ||
return new Promise((resolve, reject) => { | ||
const childProcess = proc.spawn(`${binpath} ${args}`, { shell: true }); | ||
let result = ""; | ||
childProcess.stdout.on('data', (data) => { | ||
result += data.toString(); | ||
}); | ||
childProcess.on('error', (err) => { | ||
reject(err); | ||
}); | ||
}); | ||
async getRequest(flags, headers) { | ||
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) { | ||
const binpath = path.join(__dirname, '..', 'bin', this.binary); | ||
const args = `${flags.join(' ')} ${headers} -d '${JSON.stringify(this.options.body)}' ${this.url}`; | ||
return new Promise((resolve, reject) => { | ||
const childProcess = proc.spawn(`${binpath} ${args}`, { shell: true }); | ||
let result = ""; | ||
childProcess.stdout.on('data', (data) => { | ||
result += data.toString(); | ||
}); | ||
childProcess.on('error', (err) => { | ||
reject(err); | ||
}); | ||
}); | ||
async postRequest(flags, headers) { | ||
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(); | ||
} | ||
@@ -101,0 +89,0 @@ convertHeaderObjectToCURL() { |
{ | ||
"name": "node-curl-impersonate", | ||
"version": "1.1.7", | ||
"version": "1.1.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", |
@@ -52,25 +52,28 @@ /* | ||
makeRequest() { | ||
if (this.validateOptions(this.options)) { | ||
this.setProperBinary(); | ||
const headers = this.convertHeaderObjectToCURL(); | ||
const 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": | ||
return this.getRequest(flags, headers); | ||
case "POST": | ||
return this.postRequest(flags, headers); | ||
default: | ||
throw new Error("Invalid Method! Valid HTTP methods are " + this.validMethods); | ||
} | ||
} | ||
// Convert code to be promise based | ||
return new Promise(async (resolve, reject) => { | ||
if (this.validateOptions(this.options)) { | ||
this.setProperBinary() | ||
let headers = this.convertHeaderObjectToCURL(); | ||
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": | ||
resolve(await this.getRequest(flags, headers)); | ||
break; | ||
case "POST": | ||
resolve(await this.postRequest(flags, headers)); | ||
break; | ||
default: | ||
throw new Error("Invalid Method! Valid HTTP methods are " + this.validMethods) | ||
} | ||
} | ||
}) | ||
} | ||
validateOptions(options: CurlImpersonateOptions) { | ||
@@ -111,38 +114,16 @@ if (this.validMethods.includes(options.method.toUpperCase())) { | ||
} | ||
getRequest(flags: Array<string>, headers: string) { | ||
async getRequest(flags: Array<string>, headers: string) { | ||
// GET REQUEST | ||
const binpath = path.join(__dirname, '..', 'bin', this.binary); | ||
const args = `${flags.join(' ')} ${headers} ${this.url}`; | ||
return new Promise((resolve, reject) => { | ||
const childProcess = proc.spawn(`${binpath} ${args}`, { shell: true }); | ||
let result = ""; | ||
childProcess.stdout.on('data', (data) => { | ||
result += data.toString(); | ||
}); | ||
childProcess.on('error', (err) => { | ||
reject(err); | ||
}); | ||
}); | ||
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) { | ||
async postRequest(flags: Array<string>, headers: string) { | ||
// POST REQUEST | ||
const binpath = path.join(__dirname, '..', 'bin', this.binary); | ||
const args = `${flags.join(' ')} ${headers} -d '${JSON.stringify(this.options.body)}' ${this.url}`; | ||
return new Promise((resolve, reject) => { | ||
const childProcess = proc.spawn(`${binpath} ${args}`, { shell: true }); | ||
let result = ""; | ||
childProcess.stdout.on('data', (data) => { | ||
result += data.toString(); | ||
}); | ||
childProcess.on('error', (err) => { | ||
reject(err); | ||
}); | ||
}); | ||
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 | ||
} | ||
@@ -149,0 +130,0 @@ |
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
8834552
243