From cf6425b4a9c8489abb67e6235ca666521824f0f6 Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Wed, 15 Dec 2021 13:54:56 +0530 Subject: [PATCH] Fixed internal Request issue. --- play-dl/Request/index.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/play-dl/Request/index.ts b/play-dl/Request/index.ts index 7a6e1a2..fd28cdf 100644 --- a/play-dl/Request/index.ts +++ b/play-dl/Request/index.ts @@ -39,7 +39,6 @@ export function request_stream(req_url: string, options: RequestOpts = { method: */ function internalRequest( req_url: string, - cookies_added: boolean, options: RequestOpts = { method: 'GET' } ): Promise { return new Promise(async (resolve, reject) => { @@ -49,14 +48,11 @@ function internalRequest( return; } if (Number(res.statusCode) >= 300 && Number(res.statusCode) < 400) { - res = await internalRequest(res.headers.location as string, cookies_added, options); + res = await internalRequest(res.headers.location as string, options); } else if (Number(res.statusCode) > 400) { reject(new Error(`Got ${res.statusCode} from the request`)); return; } - if (res.headers && res.headers['set-cookie'] && cookies_added) { - cookieHeaders(res.headers['set-cookie']); - } resolve(res); }); } @@ -83,11 +79,14 @@ export function request(req_url: string, options: RequestOpts = { method: 'GET' 'user-agent': getRandomUserAgent() }; } - const res = await internalRequest(req_url, cookies_added, options).catch((err: Error) => err); + const res = await internalRequest(req_url, options).catch((err: Error) => err); if (res instanceof Error) { reject(res); return; } + if (res.headers && res.headers['set-cookie'] && cookies_added) { + cookieHeaders(res.headers['set-cookie']); + } const data: string[] = []; let decoder: BrotliDecompress | Gunzip | Deflate | undefined = undefined; const encoding = res.headers['content-encoding'];