@mherod/get-cookie 2.0.0-rc.15 → 2.0.0-rc.16
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 +26 -9
- package/package.json +1 -1
- package/src/fetchWithCookies.ts +36 -11
package/dist/index.js
CHANGED
|
@@ -789,7 +789,8 @@ function $2d84054eb5f070a6$export$f266452a5050185d(url) {
|
|
|
789
789
|
|
|
790
790
|
|
|
791
791
|
const $cfc07ae4aa2c7e44$var$userAgent = new (0, ($parcel$interopDefault($7oI3p$useragents)))().toString();
|
|
792
|
-
async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetch = (0, $7oI3p$crossfetch.fetch)) {
|
|
792
|
+
async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetch = (0, $7oI3p$crossfetch.fetch), originalRequest) {
|
|
793
|
+
const originalRequest1 = originalRequest || new Request(url, options);
|
|
793
794
|
const headers = {
|
|
794
795
|
"User-Agent": $cfc07ae4aa2c7e44$var$userAgent
|
|
795
796
|
};
|
|
@@ -816,20 +817,36 @@ async function $cfc07ae4aa2c7e44$export$b24a545a0b39f491(url, options = {}, fetc
|
|
|
816
817
|
});
|
|
817
818
|
for (const [key, value] of headers1)if (key === "set-cookie") {
|
|
818
819
|
await (0, $53a3bcc99a05dfcf$export$928a906645f9d018).setCookie(value, url2);
|
|
819
|
-
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Set-Cookie
|
|
820
|
-
// const cookie = tough.parse(value);
|
|
821
|
-
// if (cookie instanceof Cookie) {
|
|
822
|
-
// await memoryCookieStore.putCookie(cookie);
|
|
823
|
-
// }
|
|
820
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Set-Cookie:`), (0, $7oI3p$colorette.yellow)(value), (0, $7oI3p$colorette.yellow)(url2));
|
|
824
821
|
}
|
|
825
|
-
const newUrl = res.headers.get("location");
|
|
826
|
-
|
|
822
|
+
const newUrl = res.headers.get("location") ?? res.url;
|
|
823
|
+
const sameHost = new URL(newUrl).host === url1.host;
|
|
824
|
+
if (res.status == 301 || res.status == 302) // follow the redirect
|
|
827
825
|
{
|
|
828
826
|
if (newUrl && newUrl !== url2) {
|
|
829
827
|
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Redirected to `), (0, $7oI3p$colorette.yellow)(newUrl));
|
|
830
828
|
return $cfc07ae4aa2c7e44$export$b24a545a0b39f491(//
|
|
831
|
-
newUrl, newOptions1, fetch);
|
|
829
|
+
newUrl, newOptions1, fetch, originalRequest1);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
if (res.status == 303 && newUrl && newUrl !== url2) {
|
|
833
|
+
// follow the redirect with GET
|
|
834
|
+
let newOptions2 = {};
|
|
835
|
+
switch(newOptions1.method){
|
|
836
|
+
case "POST":
|
|
837
|
+
case "PUT":
|
|
838
|
+
case "DELETE":
|
|
839
|
+
(0, $7oI3p$lodash.merge)(newOptions2, newOptions1, {
|
|
840
|
+
method: "GET"
|
|
841
|
+
});
|
|
842
|
+
break;
|
|
843
|
+
default:
|
|
844
|
+
(0, $7oI3p$lodash.merge)(newOptions2, newOptions1);
|
|
845
|
+
break;
|
|
832
846
|
}
|
|
847
|
+
if ((0, $ef3d5dc2fd8022f5$export$c348dfaf65040d9b).verbose) console.log((0, $7oI3p$colorette.blue)(`Redirected to `), (0, $7oI3p$colorette.yellow)(newUrl));
|
|
848
|
+
return $cfc07ae4aa2c7e44$export$b24a545a0b39f491(//
|
|
849
|
+
newUrl, newOptions2, fetch, originalRequest1);
|
|
833
850
|
}
|
|
834
851
|
const arrayBuffer1 = res.arrayBuffer();
|
|
835
852
|
async function arrayBuffer() {
|
package/package.json
CHANGED
package/src/fetchWithCookies.ts
CHANGED
|
@@ -17,8 +17,10 @@ const userAgent = new UserAgent().toString();
|
|
|
17
17
|
export async function fetchWithCookies(
|
|
18
18
|
url: RequestInfo | URL,
|
|
19
19
|
options: RequestInit | undefined = {},
|
|
20
|
-
fetch: Function = fetchImpl
|
|
20
|
+
fetch: Function = fetchImpl,
|
|
21
|
+
originalRequest: Request | undefined = undefined
|
|
21
22
|
): Promise<Response> {
|
|
23
|
+
const originalRequest1 = originalRequest || new Request(url, options);
|
|
22
24
|
const headers: HeadersInit = {
|
|
23
25
|
"User-Agent": userAgent,
|
|
24
26
|
};
|
|
@@ -46,18 +48,15 @@ export async function fetchWithCookies(
|
|
|
46
48
|
if (key === "set-cookie") {
|
|
47
49
|
await cookieJar.setCookie(value, url2);
|
|
48
50
|
if (parsedArgs.verbose) {
|
|
49
|
-
console.log(blue(`Set-Cookie
|
|
51
|
+
console.log(blue(`Set-Cookie:`), yellow(value), yellow(url2));
|
|
50
52
|
}
|
|
51
|
-
// const cookie = tough.parse(value);
|
|
52
|
-
// if (cookie instanceof Cookie) {
|
|
53
|
-
// await memoryCookieStore.putCookie(cookie);
|
|
54
|
-
// }
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
const newUrl: string = res.headers.get("location")
|
|
56
|
+
const newUrl: string = res.headers.get("location") ?? res.url;
|
|
57
|
+
const sameHost = new URL(newUrl).host === url1.host;
|
|
59
58
|
if (res.status == 301 || res.status == 302) {
|
|
60
|
-
//
|
|
59
|
+
// follow the redirect
|
|
61
60
|
if (newUrl && newUrl !== url2) {
|
|
62
61
|
if (parsedArgs.verbose) {
|
|
63
62
|
console.log(blue(`Redirected to `), yellow(newUrl));
|
|
@@ -66,11 +65,37 @@ export async function fetchWithCookies(
|
|
|
66
65
|
//
|
|
67
66
|
newUrl,
|
|
68
67
|
newOptions1,
|
|
69
|
-
fetch
|
|
68
|
+
fetch,
|
|
69
|
+
originalRequest1
|
|
70
70
|
//
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
if (res.status == 303 && newUrl && newUrl !== url2) {
|
|
75
|
+
// follow the redirect with GET
|
|
76
|
+
let newOptions2: RequestInit = {};
|
|
77
|
+
switch (newOptions1.method) {
|
|
78
|
+
case "POST":
|
|
79
|
+
case "PUT":
|
|
80
|
+
case "DELETE":
|
|
81
|
+
merge(newOptions2, newOptions1, { method: "GET" });
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
merge(newOptions2, newOptions1);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
if (parsedArgs.verbose) {
|
|
88
|
+
console.log(blue(`Redirected to `), yellow(newUrl));
|
|
89
|
+
}
|
|
90
|
+
return fetchWithCookies(
|
|
91
|
+
//
|
|
92
|
+
newUrl,
|
|
93
|
+
newOptions2,
|
|
94
|
+
fetch,
|
|
95
|
+
originalRequest1
|
|
96
|
+
//
|
|
97
|
+
);
|
|
98
|
+
}
|
|
74
99
|
|
|
75
100
|
const arrayBuffer1: Promise<ArrayBuffer> = res.arrayBuffer();
|
|
76
101
|
|
|
@@ -83,11 +108,11 @@ export async function fetchWithCookies(
|
|
|
83
108
|
}
|
|
84
109
|
|
|
85
110
|
async function text(): Promise<string> {
|
|
86
|
-
return buffer().then((buffer) => buffer.toString("utf8"));
|
|
111
|
+
return buffer().then((buffer: Buffer) => buffer.toString("utf8"));
|
|
87
112
|
}
|
|
88
113
|
|
|
89
114
|
async function json(): Promise<any> {
|
|
90
|
-
return text().then((text) => destr(text));
|
|
115
|
+
return text().then((text: string) => destr(text));
|
|
91
116
|
}
|
|
92
117
|
|
|
93
118
|
async function formData(): Promise<FormData> {
|