From fdd99dfbd9e5f06d15ba8df91766559366bde923 Mon Sep 17 00:00:00 2001 From: Flummi Date: Mon, 25 Nov 2019 15:41:12 +0100 Subject: [PATCH] update flumm-fetch --- package.json | 7 +++++-- src/fetch.mjs | 35 ----------------------------------- src/index.mjs | 2 +- 3 files changed, 6 insertions(+), 38 deletions(-) delete mode 100644 src/fetch.mjs diff --git a/package.json b/package.json index 5f2da86..1dd7d63 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "flumm-fetch-cookies", - "version": "1.1.1", + "version": "1.1.2", "description": "flumm-fetch wrapper that adds support for cookie-jars", "main": "src/index.mjs", "engines": { @@ -24,5 +24,8 @@ "bugs": { "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": { + "flumm-fetch": "^1.0.0" + } } diff --git a/src/fetch.mjs b/src/fetch.mjs deleted file mode 100644 index e14f6f1..0000000 --- a/src/fetch.mjs +++ /dev/null @@ -1,35 +0,0 @@ -import http from "http"; -import https from "https"; -import url from "url"; -import querystring from "querystring"; - -const readdata = (res, mode, data = "") => new Promise((resolve, reject) => res - .setEncoding("utf8") - .on("data", chunk => data += chunk) - .on("end", () => { - switch(mode) { - case "text": resolve(data); break; - case "json": try { resolve(JSON.parse(data)); } catch(err) { reject(data); } break; - case "buffer": resolve(new Buffer.from(data)); break; - default: reject("lol no D:"); break; - } - })); - -export default (a, options = {}, link = url.parse(a), body = "") => new Promise((resolve, reject) => { - options = {...{ hostname: link.hostname, path: link.path, method: "GET" }, ...options}; - if(options.method === "POST") { - body = querystring.stringify(options.body); - delete options.body; - options.headers = {...options.headers, ...{ - "Content-Type": "application/x-www-form-urlencoded", - "Content-Length": Buffer.byteLength(body) - }}; - } - (link.protocol === "https:"?https:http).request(options, res => resolve({ - body: res, - headers: res.headers, - text: () => readdata(res, "text"), - json: () => readdata(res, "json"), - buffer: () => readdata(res, "buffer") - })).on("error", err => reject(err)).end(body); -}); diff --git a/src/index.mjs b/src/index.mjs index 334d6c8..adb4611 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -1,4 +1,4 @@ -import fetch from "./fetch.mjs"; +import fetch from "flumm-fetch"; import CookieJar from "./cookie-jar.mjs"; import Cookie from "./cookie.mjs";