@mherod/get-cookie 2.0.0-rc.13 → 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 +7 -9
- package/package.json +1 -1
- package/src/fetchWithCookies.ts +8 -12
package/dist/index.js
CHANGED
|
@@ -800,16 +800,13 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetc
|
|
|
800
800
|
const url2 = `${url}`;
|
|
801
801
|
const url1 = new URL(url2);
|
|
802
802
|
const cookieSpecs = (0, $2d84054eb5f070a6$export$f266452a5050185d)(url1);
|
|
803
|
-
|
|
804
|
-
if (cookie.length > 0) (0, $7oI3p$lodash.merge)(headers, {
|
|
805
|
-
Cookie: cookie
|
|
806
|
-
});
|
|
803
|
+
headers["Cookie"] = await (0, $4ffeaeb7bb3c0319$export$cfc0723de5712e57)(cookieSpecs).catch(()=>"");
|
|
807
804
|
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b)["dump-request-headers"]) console.log((0, $7oI3p$colorette.blue)("Request headers:"), headers);
|
|
808
|
-
const newOptions1 = (0, $7oI3p$lodash.merge)(defaultOptions,
|
|
805
|
+
const newOptions1 = (0, $7oI3p$lodash.merge)(defaultOptions, {
|
|
809
806
|
headers: headers
|
|
810
|
-
});
|
|
807
|
+
}, options);
|
|
811
808
|
try {
|
|
812
|
-
const res = await fetch(
|
|
809
|
+
const res = await fetch(url1, newOptions1);
|
|
813
810
|
const headers1 = [];
|
|
814
811
|
res.headers.forEach((value, key)=>{
|
|
815
812
|
headers1.push([
|
|
@@ -826,12 +823,13 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetc
|
|
|
826
823
|
// }
|
|
827
824
|
}
|
|
828
825
|
const newUrl = res.headers.get("location");
|
|
829
|
-
if (res.status
|
|
826
|
+
if (res.status == 301 || res.status == 302) // const sameHost = new URL(newUrl).host === url1.host;
|
|
827
|
+
{
|
|
830
828
|
if (newUrl && newUrl !== url2) {
|
|
831
829
|
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Redirected to `), (0, $7oI3p$colorette.yellow)(newUrl));
|
|
832
830
|
return $cfc07ae4aa2c7e44$export$b24a545a0b39f491(//
|
|
833
831
|
newUrl, newOptions1, fetch);
|
|
834
|
-
}
|
|
832
|
+
}
|
|
835
833
|
}
|
|
836
834
|
const arrayBuffer1 = res.arrayBuffer();
|
|
837
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,7 +56,8 @@ 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));
|
|
@@ -71,8 +69,6 @@ export async function fetchWithCookies(
|
|
|
71
69
|
fetch
|
|
72
70
|
//
|
|
73
71
|
);
|
|
74
|
-
} else {
|
|
75
|
-
throw new Error("Redirected but no new location");
|
|
76
72
|
}
|
|
77
73
|
}
|
|
78
74
|
|