Permalink
Browse files

use writeHead to compensate for flakiness

  • Loading branch information...
substack committed Apr 7, 2012
1 parent 12ead0d commit ee622fe2ea3f0c2b9bf5157f41e06a29b5a59ea9
Showing with 8 additions and 7 deletions.
  1. +8 −7 lib/stream_socketio.js
View
@@ -9,30 +9,31 @@ var bundle = (function () {
return function (req, res) {
if (cache) {
- res.setHeader('content-type', 'text/javascript');
- res.setHeader('last-modified', cache.modified.toGMTString());
- res.setHeader('date', new Date().toGMTString());
+ var headers = {
+ 'content-type' : 'text/javascript',
+ 'last-modified' : cache.modified.toGMTString(),
+ 'date' : new Date().toGMTString(),
+ };
var ims = req.headers['if-modified-since'];
if (ims) {
var m = new Date(ims);
if (m >= cache.modified) {
- res.statusCode = 304;
+ res.writeHead(304, headers);
res.end();
return;
}
}
- res.statusCode = 200;
+ res.writeHead(200, headers);
res.end(cache.source);
}
else fs.stat(file, function (err0, stat) {
fs.readFile(file, function (err1, src) {
if (err0 || err1) {
var e = err0 || err1;
console.error(e.message || e);
- res.statusCode = 500;
- res.setHeader('content-type', 'text/plain');
+ res.writeHead(500, { 'content-type' : 'text/plain' });
res.end('an error occured loading the bundle');
}
else {

0 comments on commit ee622fe

Please sign in to comment.