Skip to content

Commit

Permalink
dep bump & associated fixes
Browse files Browse the repository at this point in the history
ended up needing to bump the minimum version of node.js from 6 to 8 and update a few of the tests
also, lots of formatting changes + one eslint-disable because it kept breaking the code
  • Loading branch information
nfriedly committed Nov 8, 2023
1 parent 4f05030 commit cd8fde2
Show file tree
Hide file tree
Showing 40 changed files with 9,012 additions and 8,908 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules/
.nyc_output/
.vscode/
examples/*/package-lock.json
.tap
2 changes: 1 addition & 1 deletion examples/blacklist/blacklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function ({ blockedDomains, message }) {
const { hostname } = URL.parse(data.url);

Check warning on line 7 in examples/blacklist/blacklist.js

View workflow job for this annotation

GitHub Actions / build (lts/*)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 7 in examples/blacklist/blacklist.js

View workflow job for this annotation

GitHub Actions / build (latest)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead
return blockedDomains.some(
(blockedDomain) =>
hostname === blockedDomain || hostname.endsWith(`.${blockedDomain}`)
hostname === blockedDomain || hostname.endsWith(`.${blockedDomain}`),
);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/blacklist/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const unblocker = Unblocker({
app.use(unblocker);

app.get("/", (req, res) =>
res.redirect("/proxy/https://en.wikipedia.org/wiki/Main_Page")
res.redirect("/proxy/https://en.wikipedia.org/wiki/Main_Page"),
);

app.listen(8080).on("upgrade", unblocker.onUpgrade);
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-user-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"unblocker": "file:..\\.."
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"start": "node server.js"
Expand Down
6 changes: 3 additions & 3 deletions examples/custom-user-agent/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ app.use(unblocker);

app.get("/", (req, res) =>
res.end(
"Use the format http://thissite.com/proxy/http://site-i-want.com/ to access the proxy."
)
"Use the format http://thissite.com/proxy/http://site-i-want.com/ to access the proxy.",
),
);

app.listen(8080).on("upgrade", unblocker.onUpgrade);

console.log(
"app listening on port 8080. Test at http://localhost:8080/proxy/https://duckduckgo.com/?q=what%27s+my+user+agent&atb=v130-1ei&ia=answer"
"app listening on port 8080. Test at http://localhost:8080/proxy/https://duckduckgo.com/?q=what%27s+my+user+agent&atb=v130-1ei&ia=answer",
);
2 changes: 1 addition & 1 deletion examples/express/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const unblocker = Unblocker({
app.use(unblocker);

app.get("/", (req, res) =>
res.redirect("/proxy/https://en.wikipedia.org/wiki/Main_Page")
res.redirect("/proxy/https://en.wikipedia.org/wiki/Main_Page"),
);

// start the server and allow unblocker to proxy websockets:
Expand Down
2 changes: 1 addition & 1 deletion examples/replace_snippet/replace_snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function (config) {
this.push(updated, "utf8");
next();
},
})
}),
);
}
}
Expand Down
7 changes: 4 additions & 3 deletions examples/replace_snippet/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ app.use(
responseMiddleware: [
replaceSnippet({
processContentTypes: ["text/html"],
searchFor: /<script type="text\/javascript">\s*BrowserCheck.testForCookies\(\);\s*<\/script>/i,
searchFor:
/<script type="text\/javascript">\s*BrowserCheck.testForCookies\(\);\s*<\/script>/i,
replaceWith: "",
}),
],
})
}),
);

app.get("/", (req, res) =>
res.redirect("/proxy/https://en.wikipedia.org/wiki/Main_Page")
res.redirect("/proxy/https://en.wikipedia.org/wiki/Main_Page"),
);

app.listen(8080);
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var server = http
if (req.url == "/") {
res.writeHead(200, headers);
return res.end(
"Use the format http://thissite.com/proxy/http://site-i-want.com/ to access the proxy."
"Use the format http://thissite.com/proxy/http://site-i-want.com/ to access the proxy.",
);
} else {
res.writeHead(404, headers);
Expand Down
2 changes: 1 addition & 1 deletion examples/whitelist/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const unblocker = Unblocker({
app.use(unblocker);

app.get("/", (req, res) =>
res.redirect("/proxy/https://en.wikipedia.org/wiki/Main_Page")
res.redirect("/proxy/https://en.wikipedia.org/wiki/Main_Page"),
);

app.listen(8080).on("upgrade", unblocker.onUpgrade);
Expand Down
2 changes: 1 addition & 1 deletion examples/whitelist/whitelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function ({ allowedDomains, message }) {
const { hostname } = URL.parse(data.url);

Check warning on line 7 in examples/whitelist/whitelist.js

View workflow job for this annotation

GitHub Actions / build (lts/*)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead

Check warning on line 7 in examples/whitelist/whitelist.js

View workflow job for this annotation

GitHub Actions / build (latest)

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead
return allowedDomains.some(
(allowedDomain) =>
hostname === allowedDomain || hostname.endsWith(`.${allowedDomain}`)
hostname === allowedDomain || hostname.endsWith(`.${allowedDomain}`),
);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/youtube/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var server = http
if (req.url == "/") {
res.writeHead(200, headers);
return res.end(
'Visit a link such as <a href="/proxy/https://www.youtube.com/watch?v=dQw4w9WgXcQ"><script>document.write(window.location)</script>proxy/https://www.youtube.com/watch?v=dQw4w9WgXcQ</a> to see the magic.'
'Visit a link such as <a href="/proxy/https://www.youtube.com/watch?v=dQw4w9WgXcQ"><script>document.write(window.location)</script>proxy/https://www.youtube.com/watch?v=dQw4w9WgXcQ</a> to see the magic.',
);
} else {
res.writeHead(404, headers);
Expand Down
4 changes: 2 additions & 2 deletions examples/youtube/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ ${formats
(format) =>
` <source type="${format.mimeType
.split(";")
.shift()}" src="/proxy/${format.url.replace(/&/g, "&amp;")}">`
.shift()}" src="/proxy/${format.url.replace(/&/g, "&amp;")}">`,
)
.join("\n")}
</video>
<p>${info.videoDetails.description.replace(/[\n]/g, "\n<br>")}</p>
</body>
</html>
`
`,
);
})
.catch((err) => {
Expand Down
20 changes: 11 additions & 9 deletions lib/charsets.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function charsets(config) {
data.stream = data.stream.pipe(
new PassThrough({
encoding: "utf8",
})
}),
);
}

Expand All @@ -53,7 +53,8 @@ module.exports = charsets;

// based on https://github.com/ashtuchkin/iconv-lite/blob/master/lib/streams.js

var re_charset_finder = /<\?xml[^>]+encoding="([^">]+)"|<meta [^>]*charset=['"]?([^ '">]+)['"]/i; // warning: making this global causes it to not include the matched value in the results :/
var re_charset_finder =
/<\?xml[^>]+encoding="([^">]+)"|<meta [^>]*charset=['"]?([^ '">]+)['"]/i; // warning: making this global causes it to not include the matched value in the results :/

// == Decoder stream =======================================================
function IconvHtmlStream(options) {
Expand All @@ -77,7 +78,7 @@ IconvHtmlStream.prototype = Object.create(Transform.prototype, {
IconvHtmlStream.prototype._transform = function (chunk, encoding, done) {
if (!Buffer.isBuffer(chunk))
return done(
new Error("delayed decoding stream needs buffers as its input.")
new Error("delayed decoding stream needs buffers as its input."),
);

if (this.isBuffering) {
Expand Down Expand Up @@ -123,7 +124,7 @@ IconvHtmlStream.prototype.startStreaming = function (charset, encoding, done) {
} else {
console.error(
"unrecognized charset %s, decoding as utf8",
this.inputEncoding
this.inputEncoding,
);
}
this.emit("charset", this.inputEncoding);
Expand All @@ -150,7 +151,8 @@ IconvHtmlStream.prototype._flush = function (done) {
}
};

var re_charset_replacer = /<\?xml[^>]+encoding="([^">]+)"|<meta [^>]*charset=['"]?([^ '">]+)['"]/gi; // similar to the charset_finder, except global
var re_charset_replacer =
/<\?xml[^>]+encoding="([^">]+)"|<meta [^>]*charset=['"]?([^ '">]+)['"]/gi; // similar to the charset_finder, except global

function MetaCharsetReplacerStream(options) {
options = options || {};
Expand All @@ -168,7 +170,7 @@ MetaCharsetReplacerStream.prototype = Object.create(Transform.prototype, {
MetaCharsetReplacerStream.prototype._transform = function (
chunk,
encoding,
done
done,
) {
done(
null,
Expand All @@ -182,10 +184,10 @@ MetaCharsetReplacerStream.prototype._transform = function (
debug(
"rewriting charset meta tag from %s to %s",
subChunk,
newSubChunk
newSubChunk,
);
return newSubChunk;
}
)
},
),
);
};
6 changes: 3 additions & 3 deletions lib/client-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = function ({ prefix }) {
const clientScriptPathFs = path.join(
__dirname,
clientDir,
"unblocker-client.js"
"unblocker-client.js",
);
const isProduction = process.env.NODE_ENV === "production";
const sendOpts = {
Expand Down Expand Up @@ -44,12 +44,12 @@ module.exports = function ({ prefix }) {
prefix,
url: data.url,
})}, window);</script>
`
`,
);
this.push(updated, "utf8");
next();
},
})
}),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/client/unblocker-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
wsSecure +
"://" +
wsHost +
wsPath
wsPath // eslint-disable-line
);
}
// fallback in case the regex failed
Expand Down
2 changes: 1 addition & 1 deletion lib/content-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function (/*config*/) {
// if any of the middleware is possibly changing the body, remove the content-length header
if (data.stream != data.remoteResponse) {
debug(
"deleting content-length header due to possible content changes by other middleware"
"deleting content-length header due to possible content changes by other middleware",
);
delete data.headers["content-length"];
}
Expand Down
14 changes: 7 additions & 7 deletions lib/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function cookies(config) {
debug(
"copying cookies from %s to %s",
data.url,
uri.query[REDIRECT_QUERY_PARAM]
uri.query[REDIRECT_QUERY_PARAM],
);
var cookies = libCookie.parse(data.headers.cookie || "");
var setCookieHeaders = Object.keys(cookies).map(function (name) {
Expand Down Expand Up @@ -97,7 +97,7 @@ function cookies(config) {

// get all of the old cookies (from the request) indexed by name, and create set-cookie headers for each one
var oldCookies = libCookie.parse(
data.clientRequest.headers.cookie || ""
data.clientRequest.headers.cookie || "",
);
var oldSetCookieHeaders = _.mapValues(
oldCookies,
Expand All @@ -106,7 +106,7 @@ function cookies(config) {
path:
config.prefix + nextUri.protocol + "//" + nextUri.host + "/",
});
}
},
);

// but, if we have a new cookie with the same name as an old one, delete the old one
Expand All @@ -116,7 +116,7 @@ function cookies(config) {

// finally, append the remaining old cookie headers to any existing set-cookie headers in the response
data.headers["set-cookie"] = (data.headers["set-cookie"] || []).concat(
_.values(oldSetCookieHeaders)
_.values(oldSetCookieHeaders),
);
}
}
Expand All @@ -139,7 +139,7 @@ function cookies(config) {
debug(
"rewriting link from %s to %s in order to allow cookies to be copied over to new path",
proxiedUrl,
cookieProxiedUrl
cookieProxiedUrl,
);
return cookieProxiedUrl;
} else {
Expand All @@ -153,7 +153,7 @@ function cookies(config) {
var tld = TLD.registered(uri.hostname);
var RE_PROTO_SUBDOMAIN_URL = new RegExp(
config.prefix + "(https?://([a-z0-9.-]+.)?" + tld + "[^'\") \\\\]*)",
"ig"
"ig",
);

data.stream = data.stream.pipe(
Expand All @@ -166,7 +166,7 @@ function cookies(config) {
this.push(updated, "utf8");
next();
},
})
}),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/decompress.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = function (config) {
if (contentTypes.shouldProcess(config, data) && shouldProcess(data)) {
debug(
"decompressing %s encoding and deleting content-encoding header",
data.headers["content-encoding"]
data.headers["content-encoding"],
);

// https://github.com/nfriedly/node-unblocker/pull/105
Expand Down
2 changes: 1 addition & 1 deletion lib/get-real-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function (config) {
// note: the prefix only appears in the regex once because the other will have already been trimmed out.
var RE_DUOBLE_PREFIX = new RegExp(
"^https?:/?/?" + config.prefix + "(https?://)",
"i"
"i",
);
/**
* Takes a /proxy/http://site.com url from a request or a referer and returns the http://site.com/ part
Expand Down
2 changes: 1 addition & 1 deletion lib/meta-robots.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function (/* config */) {
.toString()
.replace(
"</head>",
'<meta name="ROBOTS" content="NOINDEX, NOFOLLOW"/>\n</head>'
'<meta name="ROBOTS" content="NOINDEX, NOFOLLOW"/>\n</head>',
);
this.push(updated, "utf8");
next();
Expand Down
6 changes: 3 additions & 3 deletions lib/middleware-debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getDebugMiddlewareFor(middleware, dir) {
"starting %s middleware stack for %s %s",
dir,
data.contentType || "",
data.url
data.url,
);
data.prevStream = null;
}
Expand All @@ -43,7 +43,7 @@ function getDebugMiddlewareFor(middleware, dir) {
dir,
prevMiddleware || "source",
chunk.length,
hash
hash,
);
if (data.prevHash && hash != data.prevHash) {
debug("chunk modified by " + prevMiddleware);
Expand All @@ -52,7 +52,7 @@ function getDebugMiddlewareFor(middleware, dir) {
this.push(chunk);
next();
},
})
}),
);
}
if (nextName) {
Expand Down
Loading

0 comments on commit cd8fde2

Please sign in to comment.