reformat code with prettier
This commit is contained in:
parent
31bec14cc2
commit
0ef1ff3194
|
@ -14,4 +14,4 @@ deploy:
|
||||||
on:
|
on:
|
||||||
branch: master
|
branch: master
|
||||||
tags: true
|
tags: true
|
||||||
repo: jkhsjdhjs/node-fetch-cookies
|
repo: kein-Bot/flumm-fetch-cookies
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# flumm-fetch-cookies [![Build Status](https://travis-ci.org/kein-Bot/flumm-fetch-cookies.svg?branch=master)](https://travis-ci.org/kein-Bot/flumm-fetch-cookies)
|
# flumm-fetch-cookies [![Build Status](https://travis-ci.org/kein-Bot/flumm-fetch-cookies.svg?branch=master)](https://travis-ci.org/kein-Bot/flumm-fetch-cookies)
|
||||||
|
|
||||||
A [flumm-fetch](https://github.com/kein-Bot/flumm-fetch) wrapper with support for cookies.
|
A [flumm-fetch](https://github.com/kein-Bot/flumm-fetch) wrapper with support for cookies.
|
||||||
It supports reading/writing from/to a JSON cookie jar and keeps cookies in memory until you call `CookieJar.save()` to reduce disk I/O.
|
It supports reading/writing from/to a JSON cookie jar and keeps cookies in memory until you call `CookieJar.save()` to reduce disk I/O.
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import _fetch from "flumm-fetch";
|
import _fetch from "flumm-fetch";
|
||||||
import CookieJar from "./cookie-jar.mjs";
|
import CookieJar from "./cookie-jar.mjs";
|
||||||
import Cookie from "./cookie.mjs";
|
import Cookie from "./cookie.mjs";
|
||||||
import {paramError, CookieParseError} from "./errors.mjs";
|
import {CookieParseError} from "./errors.mjs";
|
||||||
|
|
||||||
const redirectStatus = new Set([301, 302, 303, 307, 308]);
|
const redirectStatus = new Set([301, 302, 303, 307, 308]);
|
||||||
|
|
||||||
|
@ -9,14 +9,13 @@ const cookieJar = new CookieJar();
|
||||||
|
|
||||||
export default async function fetch(url, options) {
|
export default async function fetch(url, options) {
|
||||||
let cookies = "";
|
let cookies = "";
|
||||||
[...cookieJar.cookiesValidForRequest(url)]
|
[...cookieJar.cookiesValidForRequest(url)].forEach(
|
||||||
.forEach(c => cookies += c.serialize() + "; ");
|
c => (cookies += c.serialize() + "; ")
|
||||||
|
);
|
||||||
|
|
||||||
if(cookies) {
|
if (cookies) {
|
||||||
if(!options)
|
if (!options) options = {};
|
||||||
options = {};
|
if (!options.headers) options.headers = {};
|
||||||
if(!options.headers)
|
|
||||||
options.headers = {};
|
|
||||||
options.headers.cookie = cookies.slice(0, -2);
|
options.headers.cookie = cookies.slice(0, -2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,11 +37,10 @@ export default async function fetch(url, options) {
|
||||||
if (wantFollow && redirectStatus.has(result.status)) {
|
if (wantFollow && redirectStatus.has(result.status)) {
|
||||||
const location = result.headers.get("Location");
|
const location = result.headers.get("Location");
|
||||||
options.redirect = "follow";
|
options.redirect = "follow";
|
||||||
return fetch(cookieJars, location, options);
|
return fetch(location, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
export {cookieJar, CookieJar, Cookie};
|
export {cookieJar, CookieJar, Cookie, CookieParseError};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user