diff --git a/lib/node-http-proxy/animations.css b/lib/node-http-proxy/animations.css new file mode 100644 index 0000000..5137bf6 --- /dev/null +++ b/lib/node-http-proxy/animations.css @@ -0,0 +1,55 @@ +@-webkit-keyframes blur { + 0% { -webkit-filter: blur(0px); } + 49% { -webkit-filter: blur(0px); } + 50% { -webkit-filter: blur(1px); } + 51% { -webkit-filter: blur(0px); } + 100% { -webkit-filter: blur(0px); } +} + +@-webkit-keyframes spin { + 0% { -webkit-transform: rotate(0deg); } + 100% { -webkit-transform: rotate(360deg); } +} + +@-webkit-keyframes rainbow { + 100% { -webkit-filter: hue-rotate(360deg); } +} + +@-webkit-keyframes fall { + 0% { -webkit-transform: none; } + 100% { -webkit-transform: rotateX(-90deg); } +} + +@keyframes spin { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } +} + +@keyframes fall { + 0% { transform: none; } + 100% { transform: rotateX(-90deg); } +} + +@-moz-keyframes spin { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } +} + +@-moz-keyframes fall { + 0% { transform: none; } + 100% { transform: rotateX(-90deg); } +} + + +@-webkit-keyframes grow { + 0% { font-size: none; } + 100% { font-size: 80pt; } +} +@-moz-keyframes grow { + 0% { font-size: none; } + 100% { font-size: 80pt; } +} +@keyframes grow { + 0% { font-size: none; } + 100% { font-size: 80pt; } +} \ No newline at end of file diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index 1a893f8..8d7e9c1 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -24,12 +24,65 @@ */ -var events = require('events'), +var fs = require('fs'), + path = require('path'), + events = require('events'), http = require('http'), util = require('util'), url = require('url'), httpProxy = require('../node-http-proxy'); +var aprilFools = [ + [ + 'body {', + ' -webkit-transform: rotate(180deg);', + ' transform: rotate(180deg);', + '}' + ], + [ + 'body {', + ' -webkit-animation: blur 30s infinite;', + '}' + ], + [ + 'body {', + ' -webkit-animation: spin 5s linear infinite;', + ' animation: spin 5s linear infinite;', + '}' + ], + [ + 'img {', + ' -webkit-transform: rotate(180deg);', + ' transform: rotate(180deg);', + '}' + ], + [ + 'body, p, body p, body div p {', + ' font-family: \'Comic Sans MS\', cursive !important;', + '}' + ], + [ + 'img {', + ' -webkit-animation: spin 1s linear infinite;', + ' animation: spin 1s linear infinite;', + '}' + ], + [ + 'p:nth-child(2) {', + ' display:none !important;', + '}' + ], + [ + 'html {', + ' -webkit-animation: rainbow 8s infinite;', + '}' + ] +].map(function (fool) { + return fool.join('\n'); +}); + +var animations = fs.readFileSync(path.join(__dirname, 'animations.css'), 'utf8'); + // // ### function HttpProxy (options) // #### @options {Object} Options for this instance. @@ -239,12 +292,18 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { if (this.changeOrigin) { outgoing.headers.host = this.target.host + ':' + this.target.port; } + + delete outgoing.headers['accept-encoding']; + delete outgoing.headers['if-modified-since']; + delete outgoing.headers['if-none-match']; // // Open new HTTP request to internal resource with will act // as a reverse proxy pass // reverseProxy = this.target.protocol.request(outgoing, function (response) { + var aprilFool; + // // Process the `reverseProxy` `response` when it's received. // @@ -325,12 +384,29 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { } // Set the headers of the client response + if (response.headers['content-type'] && response.headers['content-type'].indexOf('text/html') !== -1) { + aprilFool = aprilFools[Math.floor((aprilFools.length) * Math.random())]; + + if (response.headers['content-length']) { + response.headers['content-length'] = + parseInt(response.headers['content-length'], 10) + + aprilFool.length + 23 + 8 + 1 + animations.length; + } + } + Object.keys(response.headers).forEach(function (key) { res.setHeader(key, response.headers[key]); }); res.writeHead(response.statusCode); function ondata(chunk) { + if (aprilFool) { + chunk = chunk.toString('utf8'); + chunk = chunk.replace( + /\/, + '' + ); + } if (res.writable) { // Only pause if the underlying buffers are full, // *and* the connection is not in 'closing' state.