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.
|
||||||
|
|
||||||
|
|
2296
package-lock.json
generated
2296
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
76
package.json
76
package.json
|
@ -1,40 +1,40 @@
|
||||||
{
|
{
|
||||||
"name": "flumm-fetch-cookies",
|
"name": "flumm-fetch-cookies",
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"description": "flumm-fetch wrapper that adds support for cookie-jars",
|
"description": "flumm-fetch wrapper that adds support for cookie-jars",
|
||||||
"main": "src/index.mjs",
|
"main": "src/index.mjs",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=11.14.0"
|
"node": ">=11.14.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src/"
|
"src/"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npx eslint --ext mjs . && npx prettier --check package.json package-lock.json .travis.yml .prettierrc.json .eslintrc.json README.md && node --experimental-modules test/index.mjs"
|
"test": "npx eslint --ext mjs . && npx prettier --check package.json package-lock.json .travis.yml .prettierrc.json .eslintrc.json README.md && node --experimental-modules test/index.mjs"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/kein-Bot/flumm-fetch-cookies.git"
|
"url": "git+https://github.com/kein-Bot/flumm-fetch-cookies.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"cookie",
|
"cookie",
|
||||||
"cookie-jar",
|
"cookie-jar",
|
||||||
"flumm-fetch",
|
"flumm-fetch",
|
||||||
"fetch"
|
"fetch"
|
||||||
],
|
],
|
||||||
"author": "flummi & jkhsjdhjs",
|
"author": "flummi & jkhsjdhjs",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/kein-Bot/flumm-fetch-cookies/issues"
|
"url": "https://github.com/kein-Bot/flumm-fetch-cookies/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/kein-Bot/flumm-fetch-cookies#readme",
|
"homepage": "https://github.com/kein-Bot/flumm-fetch-cookies#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"flumm-fetch": "^1.0.1"
|
"flumm-fetch": "^1.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^7.2.0",
|
"eslint": "^7.2.0",
|
||||||
"eslint-config-prettier": "^6.11.0",
|
"eslint-config-prettier": "^6.11.0",
|
||||||
"eslint-plugin-prettier": "^3.1.4",
|
"eslint-plugin-prettier": "^3.1.4",
|
||||||
"prettier": "2.0.5"
|
"prettier": "2.0.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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