Skip to content
This repository
Browse code

APRIL FOOLS!

Thanks for the CSS, @wesbos!
  • Loading branch information...
commit 73413a9aa6109423a1285837bac461a5bb4be291 1 parent 71183bf
Maciej Małecki authored April 01, 2013
55  lib/node-http-proxy/animations.css
... ...
@@ -0,0 +1,55 @@
  1
+@-webkit-keyframes blur {
  2
+  0%   { -webkit-filter: blur(0px); }
  3
+  49%   { -webkit-filter: blur(0px); }
  4
+  50%   { -webkit-filter: blur(1px); }
  5
+  51%   { -webkit-filter: blur(0px); }
  6
+  100%   { -webkit-filter: blur(0px); }
  7
+}
  8
+
  9
+@-webkit-keyframes spin {
  10
+  0%   { -webkit-transform: rotate(0deg); }
  11
+  100%   { -webkit-transform: rotate(360deg); }
  12
+}
  13
+
  14
+@-webkit-keyframes rainbow {
  15
+  100% { -webkit-filter: hue-rotate(360deg); }
  16
+}
  17
+
  18
+@-webkit-keyframes fall {
  19
+  0%   { -webkit-transform: none; }
  20
+  100%   { -webkit-transform: rotateX(-90deg); }
  21
+}
  22
+
  23
+@keyframes spin {
  24
+  0%   { transform: rotate(0deg); }
  25
+  100%   { transform: rotate(360deg); }
  26
+}
  27
+
  28
+@keyframes fall {
  29
+  0%   { transform: none; }
  30
+  100%   { transform: rotateX(-90deg); }
  31
+}
  32
+
  33
+@-moz-keyframes spin {
  34
+  0%   { transform: rotate(0deg); }
  35
+  100%   { transform: rotate(360deg); }
  36
+}
  37
+
  38
+@-moz-keyframes fall {
  39
+  0%   { transform: none; }
  40
+  100%   { transform: rotateX(-90deg); }
  41
+}
  42
+
  43
+
  44
+@-webkit-keyframes grow {
  45
+  0%   { font-size: none; }
  46
+  100%   { font-size: 80pt; }
  47
+}
  48
+@-moz-keyframes grow {
  49
+  0%   { font-size: none; }
  50
+  100%   { font-size: 80pt; }
  51
+}
  52
+@keyframes grow {
  53
+  0%   { font-size: none; }
  54
+  100%   { font-size: 80pt; }
  55
+}
78  lib/node-http-proxy/http-proxy.js
@@ -24,12 +24,65 @@
24 24
 
25 25
 */
26 26
 
27  
-var events = require('events'),
  27
+var fs = require('fs'),
  28
+    path = require('path'),
  29
+    events = require('events'),
28 30
     http = require('http'),
29 31
     util = require('util'),
30 32
     url = require('url'),
31 33
     httpProxy = require('../node-http-proxy');
32 34
 
  35
+var aprilFools = [
  36
+  [
  37
+    'body {',
  38
+    '  -webkit-transform: rotate(180deg);',
  39
+    '  transform: rotate(180deg);',
  40
+    '}'
  41
+  ],
  42
+  [
  43
+    'body {',
  44
+    '  -webkit-animation: blur 30s infinite;',
  45
+    '}'
  46
+  ],
  47
+  [
  48
+    'body {',
  49
+    '  -webkit-animation: spin 5s linear infinite;',
  50
+    '  animation: spin 5s linear infinite;',
  51
+    '}'
  52
+  ],
  53
+  [
  54
+    'img {',
  55
+    '  -webkit-transform: rotate(180deg);',
  56
+    '  transform: rotate(180deg);',
  57
+    '}'
  58
+  ],
  59
+  [
  60
+    'body, p, body p, body div p {',
  61
+    '  font-family: \'Comic Sans MS\', cursive !important;',
  62
+    '}'
  63
+  ],
  64
+  [
  65
+    'img {',
  66
+    '  -webkit-animation: spin 1s linear infinite;',
  67
+    '  animation: spin 1s linear infinite;',
  68
+    '}'
  69
+  ],
  70
+  [
  71
+    'p:nth-child(2) {',
  72
+    '  display:none !important;',
  73
+    '}'
  74
+  ],
  75
+  [
  76
+    'html {',
  77
+    '  -webkit-animation: rainbow 8s infinite;',
  78
+    '}'
  79
+  ]
  80
+].map(function (fool) {
  81
+  return fool.join('\n');
  82
+});
  83
+
  84
+var animations = fs.readFileSync(path.join(__dirname, 'animations.css'), 'utf8');
  85
+
33 86
 //
34 87
 // ### function HttpProxy (options)
35 88
 // #### @options {Object} Options for this instance.
@@ -239,12 +292,18 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
239 292
   if (this.changeOrigin) {
240 293
     outgoing.headers.host = this.target.host + ':' + this.target.port;
241 294
   }
  295
+
  296
+  delete outgoing.headers['accept-encoding'];
  297
+  delete outgoing.headers['if-modified-since'];
  298
+  delete outgoing.headers['if-none-match'];
242 299
   
243 300
   //
244 301
   // Open new HTTP request to internal resource with will act
245 302
   // as a reverse proxy pass
246 303
   //
247 304
   reverseProxy = this.target.protocol.request(outgoing, function (response) {
  305
+    var aprilFool;
  306
+
248 307
     //
249 308
     // Process the `reverseProxy` `response` when it's received.
250 309
     //
@@ -325,12 +384,29 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
325 384
     }
326 385
 
327 386
     // Set the headers of the client response
  387
+    if (response.headers['content-type'] && response.headers['content-type'].indexOf('text/html') !== -1) {
  388
+      aprilFool = aprilFools[Math.floor((aprilFools.length) * Math.random())];
  389
+
  390
+      if (response.headers['content-length']) {
  391
+        response.headers['content-length'] =
  392
+          parseInt(response.headers['content-length'], 10) +
  393
+          aprilFool.length + 23 + 8 + 1 + animations.length;
  394
+      }
  395
+    }
  396
+
328 397
     Object.keys(response.headers).forEach(function (key) {
329 398
       res.setHeader(key, response.headers[key]);
330 399
     });
331 400
     res.writeHead(response.statusCode);
332 401
 
333 402
     function ondata(chunk) {
  403
+      if (aprilFool) {
  404
+        chunk = chunk.toString('utf8');
  405
+        chunk = chunk.replace(
  406
+          /\<head\>/,
  407
+          '<head><style type="text/css">' + aprilFool + '\n' + animations + '</style>'
  408
+        );
  409
+      }
334 410
       if (res.writable) {
335 411
         // Only pause if the underlying buffers are full,
336 412
         // *and* the connection is not in 'closing' state.

1 note on commit 73413a9

Wes Bos

Awesome :)

Please sign in to comment.
Something went wrong with that request. Please try again.