From ee27970e62f5fb053422c679b51cd56a3630af4d Mon Sep 17 00:00:00 2001 From: Technoboy10 Date: Thu, 1 Dec 2016 14:23:15 -0700 Subject: [PATCH 1/4] start put/post --- modules/proxy.js | 60 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/modules/proxy.js b/modules/proxy.js index fc3a02d..ed807ac 100644 --- a/modules/proxy.js +++ b/modules/proxy.js @@ -13,6 +13,7 @@ let serverHeadersBlacklist = new Set([ 'connection', ]); +var sizeLimit = 2e6; //TODO: change this to something different depending on tier. It's fine for now. /* get handler handles standard GET reqs as well as streams */ @@ -22,7 +23,7 @@ function get (req, res, next) { var url = req.params[0]; - // require CORS header + // require Origin header if (!requireHeader.some(header => req.headers[header])) { res.statusCode = 403; return res.end('Origin: header is required'); @@ -46,7 +47,6 @@ function get (req, res, next) { headers['X-Fowarded-For'] = (forwardedFor ? forwardedFor + ',' : '') + req.connection.remoteAddress; var data = 0; // This variable contains the size of the data (for limiting file size) - var limit = 2e6; //TODO: change this to something different depending on tier. It's fine for now. request .get(url, {headers}) // GET the document that the user specified .on('response', function (page) { @@ -68,7 +68,7 @@ function get (req, res, next) { }) .on('data', function (chunk) { data += chunk.length; - if (data > limit){ + if (data > sizeLimit){ res.abort(); // kills response and request cleanly } }) @@ -89,6 +89,60 @@ function post (req, res, next) { function put (req, res, next) { res.header('Access-Control-Allow-Origin', '*'); // Actually do the CORS thing! :) + + var url = req.params[0]; + var data = 0; + + // require Origin header + if (!requireHeader.some(header => req.headers[header])) { + res.statusCode = 403; + return res.end('Origin: header is required'); + } + + // TODO redirect same origin + /* from cors-anywhere: boolean redirectSameOrigin - If true, requests to + * URLs from the same origin will not be proxied but redirected. The + * primary purpose for this option is to save server resources by + * delegating the request to the client (since same-origin requests should + * always succeed, even without proxying). */ + + // forward client headers to server + + var headers = {}; + for (var header in req.headers) { + if (!clientHeadersBlacklist.has(header.toLowerCase())) { + headers[header] = req.headers[header]; + } + } + + var forwardedFor = req.headers['X-Fowarded-For']; + headers['X-Fowarded-For'] = (forwardedFor ? forwardedFor + ',' : '') + req.connection.remoteAddress; + req.pipe( + request + .put(url, {headers}) + .on('data', function (chunk) { + data += chunk.length; + if (data > sizeLimit){ + res.abort(); // kills response and request cleanly + } + }) + .on('response', function (page) { + res.statusCode = page.statusCode; + + // if the page already supports cors, redirect to the URL directly + if (page.headers['access-control-allow-origin'] === '*') { // TODO is this best? + res.redirect(url, next); + } + + // include only desired headers + for (var header in page.headers) { + if (!serverHeadersBlacklist.has(header)) { + res.header(header, page.headers[header]); + } + } + // must flush here -- otherwise pipe() will include the headers anyway! + res.flushHeaders(); + })); next(); } From 258608b00b9c03333c9e1175a44aee97b607656a Mon Sep 17 00:00:00 2001 From: Technoboy10 Date: Wed, 8 Mar 2017 10:05:32 -0700 Subject: [PATCH 2/4] Add toobusy-js to prevent overloading. --- modules/server.js | 9 +++ package.json | 3 +- yarn.lock | 151 ++++++++++++++++++++-------------------------- 3 files changed, 78 insertions(+), 85 deletions(-) diff --git a/modules/server.js b/modules/server.js index e9acb8a..a6412c2 100644 --- a/modules/server.js +++ b/modules/server.js @@ -1,4 +1,5 @@ const restify = require('restify'); +const toobusy = require('toobusy-js'); var proxy = require('./proxy'); const server = restify.createServer({ @@ -7,6 +8,14 @@ const server = restify.createServer({ server.use(restify.queryParser({ mapParams: false })); +server.use(function (req, res, next) { + if (toobusy()) { + res.send(503, 'Server is overloaded! Please try again later.'); + } else { + next(); + } +}); + const freeTier = restify.throttle({ rate: 3, burst: 10, diff --git a/package.json b/package.json index 439f803..e1006a1 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "dependencies": { "request": "2.79.0", "restify": "4.3.0", - "restify-router": "0.2.1" + "restify-router": "0.2.1", + "toobusy-js": "^0.5.1" } } diff --git a/yarn.lock b/yarn.lock index f8d8c9f..980ce9f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1,5 +1,7 @@ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # yarn lockfile v1 + + acorn-jsx@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-3.0.1.tgz#afdf9488fb1ecefc8348f6fb22f464e32a58b36b" @@ -57,14 +59,14 @@ arrify@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d" -asn1@~0.2.3: - version "0.2.3" - resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.3.tgz#dac8787713c9966849fc8180777ebe9c1ddf3b86" - asn1@0.1.11: version "0.1.11" resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.1.11.tgz#559be18376d08a4ec4dbe80877d27818639b2df7" +asn1@~0.2.3: + version "0.2.3" + resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.3.tgz#dac8787713c9966849fc8180777ebe9c1ddf3b86" + assert-plus@^0.1.5: version "0.1.5" resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-0.1.5.tgz#ee74009413002d84cec7219c6ac811812e723160" @@ -134,10 +136,6 @@ browser-stdout@1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.0.tgz#f351d32969d32fa5d7a5567154263d928ae3bd1f" -buffer-shims@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/buffer-shims/-/buffer-shims-1.0.0.tgz#9978ce317388c649ad8793028c3477ef044a8b51" - bunyan@^1.4.0: version "1.8.5" resolved "https://registry.yarnpkg.com/bunyan/-/bunyan-1.8.5.tgz#0d619e83005fb89070f5f47982fc1bf00600878a" @@ -199,7 +197,7 @@ combined-stream@^1.0.5, combined-stream@~1.0.5: dependencies: delayed-stream "~1.0.0" -commander@^2.9.0, commander@2.9.0: +commander@2.9.0, commander@^2.9.0: version "2.9.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4" dependencies: @@ -225,7 +223,7 @@ cookiejar@^2.0.6: version "2.1.0" resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.0.tgz#86549689539b6d0e269b6637a304be508194d898" -core-util-is@~1.0.0, core-util-is@1.0.2: +core-util-is@1.0.2, core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" @@ -272,18 +270,18 @@ dashdash@^1.12.0: dependencies: assert-plus "^1.0.0" -debug@^2.1.1, debug@^2.2.0: - version "2.3.3" - resolved "https://registry.yarnpkg.com/debug/-/debug-2.3.3.tgz#40c453e67e6e13c901ddec317af8986cda9eff8c" - dependencies: - ms "0.7.2" - debug@2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da" dependencies: ms "0.7.1" +debug@^2.1.1, debug@^2.2.0: + version "2.3.3" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.3.3.tgz#40c453e67e6e13c901ddec317af8986cda9eff8c" + dependencies: + ms "0.7.2" + deep-is@~0.1.3: version "0.1.3" resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" @@ -369,7 +367,7 @@ es6-set@~0.1.3: es6-symbol "3" event-emitter "~0.3.4" -es6-symbol@~3.1, es6-symbol@~3.1.0, es6-symbol@3: +es6-symbol@3, es6-symbol@~3.1, es6-symbol@~3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.0.tgz#94481c655e7a7cad82eba832d97d5433496d7ffa" dependencies: @@ -389,7 +387,7 @@ escape-regexp-component@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/escape-regexp-component/-/escape-regexp-component-1.0.2.tgz#9c63b6d0b25ff2a88c3adbd18c5b61acc3b9faa2" -escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5, escape-string-regexp@1.0.5: +escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" @@ -492,10 +490,6 @@ extend@^3.0.0, extend@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.0.tgz#5a474353b9f3353ddd8176dfd37b91c83a46f1d4" -extsprintf@^1.2.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05" - extsprintf@1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.0.2.tgz#e1080e0658e300b06294990cc70e1502235fd550" @@ -504,6 +498,10 @@ extsprintf@1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.2.0.tgz#5ad946c22f5b32ba7f8cd7426711c6e8a3fc2529" +extsprintf@^1.2.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05" + fast-levenshtein@~2.0.4: version "2.0.5" resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.5.tgz#bd33145744519ab1c36c3ee9f31f08e9079b67f2" @@ -535,14 +533,6 @@ forever-agent@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" -form-data@~2.1.1: - version "2.1.2" - resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.1.2.tgz#89c3534008b97eada4cbb157d58f6f5df025eae4" - dependencies: - asynckit "^0.4.0" - combined-stream "^1.0.5" - mime-types "^2.1.12" - form-data@1.0.0-rc4: version "1.0.0-rc4" resolved "https://registry.yarnpkg.com/form-data/-/form-data-1.0.0-rc4.tgz#05ac6bc22227b43e4461f488161554699d4f8b5e" @@ -551,6 +541,14 @@ form-data@1.0.0-rc4: combined-stream "^1.0.5" mime-types "^2.1.10" +form-data@~2.1.1: + version "2.1.2" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.1.2.tgz#89c3534008b97eada4cbb157d58f6f5df025eae4" + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.5" + mime-types "^2.1.12" + formidable@^1.0.14, formidable@^1.0.17: version "1.0.17" resolved "https://registry.yarnpkg.com/formidable/-/formidable-1.0.17.tgz#ef5491490f9433b705faa77249c99029ae348559" @@ -575,30 +573,30 @@ getpass@^0.1.1: dependencies: assert-plus "^1.0.0" -glob@^6.0.1: - version "6.0.4" - resolved "https://registry.yarnpkg.com/glob/-/glob-6.0.4.tgz#0f08860f6a155127b2fadd4f9ce24b1aab6e4d22" +glob@7.0.5: + version "7.0.5" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.5.tgz#b4202a69099bbb4d292a7c1b95b6682b67ebdc95" dependencies: + fs.realpath "^1.0.0" inflight "^1.0.4" inherits "2" - minimatch "2 || 3" + minimatch "^3.0.2" once "^1.3.0" path-is-absolute "^1.0.0" -glob@^7.0.0, glob@^7.0.3, glob@^7.0.5: - version "7.1.1" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" +glob@^6.0.1: + version "6.0.4" + resolved "https://registry.yarnpkg.com/glob/-/glob-6.0.4.tgz#0f08860f6a155127b2fadd4f9ce24b1aab6e4d22" dependencies: - fs.realpath "^1.0.0" inflight "^1.0.4" inherits "2" - minimatch "^3.0.2" + minimatch "2 || 3" once "^1.3.0" path-is-absolute "^1.0.0" -glob@7.0.5: - version "7.0.5" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.5.tgz#b4202a69099bbb4d292a7c1b95b6682b67ebdc95" +glob@^7.0.0, glob@^7.0.3: + version "7.1.1" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" dependencies: fs.realpath "^1.0.0" inflight "^1.0.4" @@ -714,7 +712,7 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@^2.0.1, inherits@~2.0.1, inherits@2: +inherits@2, inherits@^2.0.1, inherits@~2.0.1: version "2.0.3" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" @@ -925,7 +923,7 @@ lru-cache@^4.0.1: pseudomap "^1.0.1" yallist "^2.0.0" -methods@^1.1.1, methods@1.x: +methods@1.x, methods@^1.1.1: version "1.1.2" resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" @@ -947,7 +945,7 @@ minimalistic-assert@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.0.tgz#702be2dda6b37f4836bcb3f5db56641b64a1d3d3" -minimatch@^3.0.2, "minimatch@2 || 3": +"minimatch@2 || 3", minimatch@^3.0.2: version "3.0.3" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774" dependencies: @@ -957,7 +955,7 @@ minimist@0.0.8: version "0.0.8" resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" -mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.1, mkdirp@0.5.1: +mkdirp@0.5.1, mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" dependencies: @@ -1122,19 +1120,7 @@ ramda@^0.22.1: version "0.22.1" resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.22.1.tgz#031da0c3df417c5b33c96234757eb37033f36a0e" -readable-stream@^2.0.1, readable-stream@^2.0.5: - version "2.2.2" - resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.2.tgz#a9e6fec3c7dda85f8bb1b3ba7028604556fc825e" - dependencies: - buffer-shims "^1.0.0" - core-util-is "~1.0.0" - inherits "~2.0.1" - isarray "~1.0.0" - process-nextick-args "~1.0.6" - string_decoder "~0.10.x" - util-deprecate "~1.0.1" - -readable-stream@~2.0.0: +readable-stream@^2.0.1, readable-stream@^2.0.5, readable-stream@~2.0.0: version "2.0.6" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.0.6.tgz#8f90341e68a53ccc928788dacfcd11b36eb9b78e" dependencies: @@ -1207,7 +1193,7 @@ restify-router@0.2.1: lodash "^3.10.1" restify "^4.0.3" -restify@^4.0.3, restify@4.3.0: +restify@4.3.0, restify@^4.0.3: version "4.3.0" resolved "https://registry.yarnpkg.com/restify/-/restify-4.3.0.tgz#03b67960d1d42a6dafcde3bd82fb882173a27678" dependencies: @@ -1240,13 +1226,7 @@ restore-cursor@^1.0.1: exit-hook "^1.0.0" onetime "^1.0.0" -rimraf@^2.2.8: - version "2.5.4" - resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.5.4.tgz#96800093cbf1a0c86bd95b4625467535c29dfa04" - dependencies: - glob "^7.0.5" - -rimraf@~2.4.0: +rimraf@^2.2.8, rimraf@~2.4.0: version "2.4.5" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.4.5.tgz#ee710ce5d93a8fdb856fb5ea8ff0e2d75934b2da" dependencies: @@ -1335,10 +1315,6 @@ stream-transform@^0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/stream-transform/-/stream-transform-0.1.1.tgz#0a54a2b81eea88da55a50df2441cb63edc101c71" -string_decoder@~0.10.x: - version "0.10.31" - resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" - string-width@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3" @@ -1354,6 +1330,10 @@ string-width@^2.0.0: is-fullwidth-code-point "^2.0.0" strip-ansi "^3.0.0" +string_decoder@~0.10.x: + version "0.10.31" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" + stringstream@~0.0.4: version "0.0.5" resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878" @@ -1394,16 +1374,16 @@ supertest@2.0.1: methods "1.x" superagent "^2.0.0" -supports-color@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" - supports-color@3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.1.2.tgz#72a262894d9d408b956ca05ff37b2ed8a6e2a2d5" dependencies: has-flag "^1.0.0" +supports-color@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" + table@^3.7.8: version "3.8.3" resolved "https://registry.yarnpkg.com/table/-/table-3.8.3.tgz#2bbc542f0fda9861a755d3947fefd8b3f513855f" @@ -1423,6 +1403,10 @@ through@^2.3.6: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" +toobusy-js@^0.5.1: + version "0.5.1" + resolved "https://registry.yarnpkg.com/toobusy-js/-/toobusy-js-0.5.1.tgz#5511f78f6a87a6a512d44fdb0efa13672217f659" + tough-cookie@~2.3.0: version "2.3.2" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.2.tgz#f081f76e4c85720e6c37a5faced737150d84072a" @@ -1471,14 +1455,6 @@ vasync@1.6.3: dependencies: verror "1.6.0" -verror@^1.4.0: - version "1.9.0" - resolved "https://registry.yarnpkg.com/verror/-/verror-1.9.0.tgz#107a8a2d14c33586fc4bb830057cd2d19ae2a6ee" - dependencies: - assert-plus "^1.0.0" - core-util-is "1.0.2" - extsprintf "^1.2.0" - verror@1.3.6: version "1.3.6" resolved "https://registry.yarnpkg.com/verror/-/verror-1.3.6.tgz#cff5df12946d297d2baaefaa2689e25be01c005c" @@ -1491,6 +1467,14 @@ verror@1.6.0: dependencies: extsprintf "1.2.0" +verror@^1.4.0: + version "1.9.0" + resolved "https://registry.yarnpkg.com/verror/-/verror-1.9.0.tgz#107a8a2d14c33586fc4bb830057cd2d19ae2a6ee" + dependencies: + assert-plus "^1.0.0" + core-util-is "1.0.2" + extsprintf "^1.2.0" + wbuf@^1.1.0, wbuf@^1.4.0: version "1.7.2" resolved "https://registry.yarnpkg.com/wbuf/-/wbuf-1.7.2.tgz#d697b99f1f59512df2751be42769c1580b5801fe" @@ -1518,4 +1502,3 @@ xtend@^4.0.0: yallist@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.0.0.tgz#306c543835f09ee1a4cb23b7bce9ab341c91cdd4" - From 51aae404b229796393eb3d39eb049102017fd006 Mon Sep 17 00:00:00 2001 From: Technoboy10 Date: Thu, 9 Mar 2017 09:33:15 -0700 Subject: [PATCH 3/4] Add content-length checking for sizeLimit and modified test --- modules/proxy.js | 5 +++++ tests/integration/limits.js | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/proxy.js b/modules/proxy.js index d93f56c..d4da672 100644 --- a/modules/proxy.js +++ b/modules/proxy.js @@ -59,6 +59,11 @@ function get (req, res, next) { request .get(url, {headers}) // GET the document that the user specified .on('response', function (page) { + // Check content length - if it's larger than the size limit, end the request with a 413 error. + if (Number(page.headers['content-length']) > sizeLimit) { + res.statusCode = 413; + res.end('ERROR 413: Maximum allowed size is ' + sizeLimit + ' bytes.'); + } res.statusCode = page.statusCode; // if the page already supports cors, redirect to the URL directly diff --git a/tests/integration/limits.js b/tests/integration/limits.js index 937e56b..789aeb7 100644 --- a/tests/integration/limits.js +++ b/tests/integration/limits.js @@ -10,6 +10,9 @@ describe('Large file request', function () { .expect(function (res) { res.body.length < 2e6; }) - .expect(200, done); + .expect(function (res) { + res.statusCode == 200 || res.statusCode == 413; + }) + .end(done); }); }); From ea26043ddeddfcfe6d0f3a34794e446b3f2078d3 Mon Sep 17 00:00:00 2001 From: Technoboy10 Date: Tue, 21 Mar 2017 23:05:06 -0600 Subject: [PATCH 4/4] The old README was outdated. --- README.md | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/README.md b/README.md index 0e7878d..73f9d3d 100644 --- a/README.md +++ b/README.md @@ -9,14 +9,4 @@ Status](https://travis-ci.org/technoboy10/crossorigin.me.svg?branch=v2)](https:/ [![Support me on patreon!](https://img.shields.io/badge/support-patreon-green.svg)](https://patreon.com/corsproxy) [![Donate bitcoin to support crossorigin.me](https://img.shields.io/badge/donate-bitcoin-yellow.svg)](https://coinbase.com/technoboy10) -A CORS proxy replacement. Based partly on https://github.com/bmpvieira/simple-corsproxy. - -## What? -crossorigin.me is a CORS proxy. It lets developers (like you!) access resources from other sites that don't have CORS enabled on their server. - -## Why? -One of the more well known CORS proxies, corsproxy.com, recently disappeared. Quite a few things relied on that site, so I decided to set a new proxy up. - -## Where? - -[Here](http://crossorigin.me). +crossorigin.me is a CORS proxy. It lets developers (like you!) access resources from other sites that don't have CORS enabled on their server. See [the website](https://crossorigin.me) for more information.