Various fixed
This commit is contained in:
parent
b36364da76
commit
5c64bdd0b2
@ -155,7 +155,7 @@ export class Stream {
|
|||||||
this.timer = new Timer(() => {
|
this.timer = new Timer(() => {
|
||||||
this.timer.reuse();
|
this.timer.reuse();
|
||||||
this.loop();
|
this.loop();
|
||||||
}, 280);
|
}, 265);
|
||||||
this.stream.on('close', () => {
|
this.stream.on('close', () => {
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -155,16 +155,20 @@ export async function request(url: string, options: RequestOpts = {}): Promise<s
|
|||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
if (!options?.proxies || options.proxies.length === 0) {
|
if (!options?.proxies || options.proxies.length === 0) {
|
||||||
let data = '';
|
let data = '';
|
||||||
let cook = getCookies()
|
let cookies_added = false
|
||||||
if (typeof cook === 'string' && options.headers) {
|
if(options.cookies){
|
||||||
Object.assign(options.headers, { cookie : cook });
|
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);
|
let res = await https_getter(url, options).catch((err: Error) => err);
|
||||||
if (res instanceof Error) {
|
if (res instanceof Error) {
|
||||||
reject(res);
|
reject(res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(res.headers && res.headers['set-cookie'] && cook){
|
if(res.headers && res.headers['set-cookie'] && cookies_added){
|
||||||
res.headers['set-cookie'].forEach((x) => {
|
res.headers['set-cookie'].forEach((x) => {
|
||||||
x.split(';').forEach((x) => {
|
x.split(';').forEach((x) => {
|
||||||
const [key, value] = x.split('=');
|
const [key, value] = x.split('=');
|
||||||
@ -183,16 +187,20 @@ export async function request(url: string, options: RequestOpts = {}): Promise<s
|
|||||||
res.on('data', (c) => (data += c));
|
res.on('data', (c) => (data += c));
|
||||||
res.on('end', () => resolve(data));
|
res.on('end', () => resolve(data));
|
||||||
} else {
|
} else {
|
||||||
let cook = getCookies()
|
let cookies_added = false
|
||||||
if (typeof cook === 'string' && options.headers) {
|
if(options.cookies){
|
||||||
Object.assign(options.headers, { cookie : cook });
|
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);
|
let res = await proxy_getter(url, options.proxies).catch((e: Error) => e);
|
||||||
if (res instanceof Error) {
|
if (res instanceof Error) {
|
||||||
reject(res);
|
reject(res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(res.head && cook){
|
if(res.head && cookies_added){
|
||||||
let cookies = res.head.filter((x) => x.toLocaleLowerCase().startsWith('set-cookie: '));
|
let cookies = res.head.filter((x) => x.toLocaleLowerCase().startsWith('set-cookie: '));
|
||||||
cookies.forEach((x) => {
|
cookies.forEach((x) => {
|
||||||
x.toLocaleLowerCase().split('set-cookie: ')[1].split(';').forEach((y) => {
|
x.toLocaleLowerCase().split('set-cookie: ')[1].split(';').forEach((y) => {
|
||||||
|
|||||||
@ -184,6 +184,7 @@ export function authorization(): void {
|
|||||||
let cookie: Object = {};
|
let cookie: Object = {};
|
||||||
cook.split(';').forEach((x) => {
|
cook.split(';').forEach((x) => {
|
||||||
let [ key, value ] = x.split('=')
|
let [ key, value ] = x.split('=')
|
||||||
|
if(!value) return;
|
||||||
key = key.trim()
|
key = key.trim()
|
||||||
value = value.trim()
|
value = value.trim()
|
||||||
Object.assign(cookie, { [key] : value })
|
Object.assign(cookie, { [key] : value })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user