commit
511958db96
@ -155,7 +155,7 @@ export class Stream {
|
||||
this.timer = new Timer(() => {
|
||||
this.timer.reuse();
|
||||
this.loop();
|
||||
}, 280);
|
||||
}, 265);
|
||||
this.stream.on('close', () => {
|
||||
this.cleanup();
|
||||
});
|
||||
|
||||
@ -110,7 +110,6 @@ async function proxy_getter(req_url: string, req_proxy: Proxy[]): Promise<ProxyO
|
||||
}
|
||||
|
||||
req.on('connect', function (res, socket, head) {
|
||||
console.log('Connected');
|
||||
const tlsConnection = tls.connect(
|
||||
{
|
||||
host: parsed_url.hostname,
|
||||
@ -156,16 +155,20 @@ export async function request(url: string, options: RequestOpts = {}): Promise<s
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (!options?.proxies || options.proxies.length === 0) {
|
||||
let data = '';
|
||||
let cook = getCookies()
|
||||
if (typeof cook === 'string' && options.headers) {
|
||||
Object.assign(options.headers, { cookie : cook });
|
||||
let cookies_added = false
|
||||
if(options.cookies){
|
||||
let cook = getCookies()
|
||||
if (typeof cook === 'string' && options.headers) {
|
||||
Object.assign(options.headers, { cookie : cook });
|
||||
cookies_added = true
|
||||
}
|
||||
}
|
||||
let res = await https_getter(url, options).catch((err: Error) => err);
|
||||
if (res instanceof Error) {
|
||||
reject(res);
|
||||
return;
|
||||
}
|
||||
if(res.headers && res.headers['set-cookie'] && cook){
|
||||
if(res.headers && res.headers['set-cookie'] && cookies_added){
|
||||
res.headers['set-cookie'].forEach((x) => {
|
||||
x.split(';').forEach((x) => {
|
||||
const [key, value] = x.split('=');
|
||||
@ -184,16 +187,20 @@ export async function request(url: string, options: RequestOpts = {}): Promise<s
|
||||
res.on('data', (c) => (data += c));
|
||||
res.on('end', () => resolve(data));
|
||||
} else {
|
||||
let cook = getCookies()
|
||||
if (typeof cook === 'string' && options.headers) {
|
||||
Object.assign(options.headers, { cookie : cook });
|
||||
let cookies_added = false
|
||||
if(options.cookies){
|
||||
let cook = getCookies()
|
||||
if (typeof cook === 'string' && options.headers) {
|
||||
Object.assign(options.headers, { cookie : cook });
|
||||
cookies_added = true
|
||||
}
|
||||
}
|
||||
let res = await proxy_getter(url, options.proxies).catch((e: Error) => e);
|
||||
if (res instanceof Error) {
|
||||
reject(res);
|
||||
return;
|
||||
}
|
||||
if(res.head && cook){
|
||||
if(res.head && cookies_added){
|
||||
let cookies = res.head.filter((x) => x.toLocaleLowerCase().startsWith('set-cookie: '));
|
||||
cookies.forEach((x) => {
|
||||
x.toLocaleLowerCase().split('set-cookie: ')[1].split(';').forEach((y) => {
|
||||
|
||||
@ -184,6 +184,7 @@ export function authorization(): void {
|
||||
let cookie: Object = {};
|
||||
cook.split(';').forEach((x) => {
|
||||
let [ key, value ] = x.split('=')
|
||||
if(!value) return;
|
||||
key = key.trim()
|
||||
value = value.trim()
|
||||
Object.assign(cookie, { [key] : value })
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user