reformat code with prettier
This commit is contained in:
parent
31bec14cc2
commit
0ef1ff3194
@ -14,4 +14,4 @@ deploy:
|
||||
on:
|
||||
branch: master
|
||||
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)
|
||||
|
||||
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.
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import _fetch from "flumm-fetch";
|
||||
import CookieJar from "./cookie-jar.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]);
|
||||
|
||||
@ -9,14 +9,13 @@ const cookieJar = new CookieJar();
|
||||
|
||||
export default async function fetch(url, options) {
|
||||
let cookies = "";
|
||||
[...cookieJar.cookiesValidForRequest(url)]
|
||||
.forEach(c => cookies += c.serialize() + "; ");
|
||||
[...cookieJar.cookiesValidForRequest(url)].forEach(
|
||||
c => (cookies += c.serialize() + "; ")
|
||||
);
|
||||
|
||||
if (cookies) {
|
||||
if(!options)
|
||||
options = {};
|
||||
if(!options.headers)
|
||||
options.headers = {};
|
||||
if (!options) options = {};
|
||||
if (!options.headers) options.headers = {};
|
||||
options.headers.cookie = cookies.slice(0, -2);
|
||||
}
|
||||
|
||||
@ -38,11 +37,10 @@ export default async function fetch(url, options) {
|
||||
if (wantFollow && redirectStatus.has(result.status)) {
|
||||
const location = result.headers.get("Location");
|
||||
options.redirect = "follow";
|
||||
return fetch(cookieJars, location, options);
|
||||
return fetch(location, options);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export {cookieJar, CookieJar, Cookie};
|
||||
|
||||
export {cookieJar, CookieJar, Cookie, CookieParseError};
|
||||
|
Loading…
x
Reference in New Issue
Block a user