title: Send socket.io response data to client from node.js server in gzip format
body: <p>The issue I'm having is that I don't know how to be able to tell whether or not the data that I'm sending back to the client is compressed in gzip format. Looking at the output of my server from the command line I'm seeing:</p>
  
  <pre><code>debug - websocket writing 3:::{"result":1368673052397}
  debug - websocket writing 3:::{"result":1368673053399}
  ...
  </code></pre>
  
  <p>To me this looks like the server is writing the response in ascii form rather than compressing it first before sending.</p>
  
  <p>Below is the example I've written to produce these results. From what I've read as long as I set 'browser client gzip' my responses should be getting sent gzipped. If they're not how do I do this and if I am how can I tell from the server's debug info that they are in fact compressed responses.</p>
  
  <p>When I launch the server I use the following command in BASH:</p>
  
  <p>$ NODE_ENV=production node app.js</p>
  
  <pre><code>var express = require('express'),
      http    = require('http');
  
  var app     = express(),
      server  = http.createServer(app),
      io      = require('socket.io').listen(server);
  
  io.configure('production', function() {
      io.enable('browser client minification');
      io.enable('browser client etag');
      io.enable('browser client gzip');
      io.set('log level', 3);
  });
  
  app.use(express.logger('dev'));
  
  app.get('/', function(req, res) {
      res.send(
      "&lt;script src='/socket.io/socket.io.js'&gt;&lt;/script&gt;\n"+
      "&lt;script src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'&gt;&lt;/script&gt;\n"+
      "&lt;script&gt;\n"+
      "var socket=io.connect('http://127.0.0.1:3000');\n"+
      "socket.on('message', function(data) {\n"+
      "   $(\"h2\").text(data);\n"+
      "});\n"+
      "&lt;/script&gt;\n"+
      "&lt;h1&gt;"+process.env.NODE_ENV+"&lt;/h1&gt;\n"+
      "&lt;h2&gt;&lt;/h2&gt;\n"
      );
  });
  
  server.listen('3000');
  
  io.sockets.on('connection', function(webSocket) {
      function whileLoop() {
          setTimeout(function() {
                  var epoch = (new Date).getTime();
                  var jsonData = "{\"result\":"+epoch+"}";
                  webSocket.send(jsonData);
              whileLoop();
          }, 1000);
      }
      whileLoop();
  });
  </code></pre>