@mherod/get-cookie 2.0.0-rc.12 → 2.0.0-rc.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +13 -11
- package/package.json +1 -1
- package/src/fetchWithCookies.ts +15 -13
package/dist/index.js
CHANGED
|
@@ -788,9 +788,10 @@ function $2d84054eb5f070a6$export$f266452a5050185d(url) {
|
|
|
788
788
|
}
|
|
789
789
|
|
|
790
790
|
|
|
791
|
+
const $cfc07ae4aa2c7e44$var$userAgent = new (0, ($parcel$interopDefault($7oI3p$useragents)))().toString();
|
|
791
792
|
async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetch = (0, $7oI3p$crossfetch.fetch)) {
|
|
792
793
|
const headers = {
|
|
793
|
-
"User-Agent":
|
|
794
|
+
"User-Agent": $cfc07ae4aa2c7e44$var$userAgent
|
|
794
795
|
};
|
|
795
796
|
const defaultOptions = {
|
|
796
797
|
headers: headers,
|
|
@@ -799,16 +800,13 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetc
|
|
|
799
800
|
const url2 = `${url}`;
|
|
800
801
|
const url1 = new URL(url2);
|
|
801
802
|
const cookieSpecs = (0, $2d84054eb5f070a6$export$f266452a5050185d)(url1);
|
|
802
|
-
|
|
803
|
-
if (cookie.length > 0) (0, $7oI3p$lodash.merge)(headers, {
|
|
804
|
-
Cookie: cookie
|
|
805
|
-
});
|
|
803
|
+
headers["Cookie"] = await (0, $4ffeaeb7bb3c0319$export$cfc0723de5712e57)(cookieSpecs).catch(()=>"");
|
|
806
804
|
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b)["dump-request-headers"]) console.log((0, $7oI3p$colorette.blue)("Request headers:"), headers);
|
|
807
|
-
const newOptions1 = (0, $7oI3p$lodash.merge)(defaultOptions,
|
|
805
|
+
const newOptions1 = (0, $7oI3p$lodash.merge)(defaultOptions, {
|
|
808
806
|
headers: headers
|
|
809
|
-
});
|
|
807
|
+
}, options);
|
|
810
808
|
try {
|
|
811
|
-
const res = await fetch(
|
|
809
|
+
const res = await fetch(url1, newOptions1);
|
|
812
810
|
const headers1 = [];
|
|
813
811
|
res.headers.forEach((value, key)=>{
|
|
814
812
|
headers1.push([
|
|
@@ -825,9 +823,13 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetc
|
|
|
825
823
|
// }
|
|
826
824
|
}
|
|
827
825
|
const newUrl = res.headers.get("location");
|
|
828
|
-
if (res.
|
|
829
|
-
|
|
830
|
-
|
|
826
|
+
if (res.status == 301 || res.status == 302) // const sameHost = new URL(newUrl).host === url1.host;
|
|
827
|
+
{
|
|
828
|
+
if (newUrl && newUrl !== url2) {
|
|
829
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Redirected to `), (0, $7oI3p$colorette.yellow)(newUrl));
|
|
830
|
+
return $cfc07ae4aa2c7e44$export$b24a545a0b39f491(//
|
|
831
|
+
newUrl, newOptions1, fetch);
|
|
832
|
+
}
|
|
831
833
|
}
|
|
832
834
|
const arrayBuffer1 = res.arrayBuffer();
|
|
833
835
|
async function arrayBuffer() {
|
package/package.json
CHANGED
package/src/fetchWithCookies.ts
CHANGED
|
@@ -19,7 +19,7 @@ export async function fetchWithCookies(
|
|
|
19
19
|
options: RequestInit | undefined = {},
|
|
20
20
|
fetch: Function = fetchImpl
|
|
21
21
|
): Promise<Response> {
|
|
22
|
-
const headers = {
|
|
22
|
+
const headers: HeadersInit = {
|
|
23
23
|
"User-Agent": userAgent,
|
|
24
24
|
};
|
|
25
25
|
const defaultOptions: RequestInit = {
|
|
@@ -29,18 +29,15 @@ export async function fetchWithCookies(
|
|
|
29
29
|
const url2: string = `${url}`;
|
|
30
30
|
const url1: URL = new URL(url2);
|
|
31
31
|
const cookieSpecs: CookieSpec[] = cookieSpecsFromUrl(url1);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
Cookie: cookie,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
32
|
+
headers["Cookie"] = await getMergedRenderedCookies(cookieSpecs).catch(
|
|
33
|
+
() => ""
|
|
34
|
+
);
|
|
38
35
|
if (parsedArgs["dump-request-headers"]) {
|
|
39
36
|
console.log(blue("Request headers:"), headers);
|
|
40
37
|
}
|
|
41
|
-
const newOptions1: RequestInit = merge(defaultOptions,
|
|
38
|
+
const newOptions1: RequestInit = merge(defaultOptions, { headers }, options);
|
|
42
39
|
try {
|
|
43
|
-
const res: Response = await fetch(
|
|
40
|
+
const res: Response = await fetch(url1, newOptions1);
|
|
44
41
|
const headers: [string, string][] = [];
|
|
45
42
|
res.headers.forEach((value, key) => {
|
|
46
43
|
headers.push([key, value]);
|
|
@@ -59,14 +56,19 @@ export async function fetchWithCookies(
|
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
const newUrl: string = res.headers.get("location") as string;
|
|
62
|
-
if (res.status
|
|
59
|
+
if (res.status == 301 || res.status == 302) {
|
|
60
|
+
// const sameHost = new URL(newUrl).host === url1.host;
|
|
63
61
|
if (newUrl && newUrl !== url2) {
|
|
64
62
|
if (parsedArgs.verbose) {
|
|
65
63
|
console.log(blue(`Redirected to `), yellow(newUrl));
|
|
66
64
|
}
|
|
67
|
-
return fetchWithCookies(
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
return fetchWithCookies(
|
|
66
|
+
//
|
|
67
|
+
newUrl,
|
|
68
|
+
newOptions1,
|
|
69
|
+
fetch
|
|
70
|
+
//
|
|
71
|
+
);
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
|