Skip to content
Browse files

Update for v0.1.94

  • Loading branch information...
1 parent 7935af4 commit f2d65d9d781ce03f726525c950a5364b85550c56 @ry ry committed May 9, 2010
Showing with 21 additions and 28 deletions.
  1. +20 −27 fu.js
  2. +1 −1 server.js
View
47 fu.js
@@ -9,11 +9,10 @@ var fu = exports;
var NOT_FOUND = "Not Found\n";
function notFound(req, res) {
- res.sendHeader(404, [ ["Content-Type", "text/plain"]
- , ["Content-Length", NOT_FOUND.length]
- ]);
- res.write(NOT_FOUND);
- res.close();
+ res.writeHead(404, { "Content-Type": "text/plain"
+ , "Content-Length": NOT_FOUND.length
+ });
+ res.end(NOT_FOUND);
}
var getMap = {};
@@ -26,20 +25,18 @@ var server = createServer(function (req, res) {
var handler = getMap[url.parse(req.url).pathname] || notFound;
res.simpleText = function (code, body) {
- res.sendHeader(code, [ ["Content-Type", "text/plain"]
- , ["Content-Length", body.length]
- ]);
- res.write(body);
- res.close();
+ res.writeHead(code, { "Content-Type": "text/plain"
+ , "Content-Length": body.length
+ });
+ res.end(body);
};
res.simpleJSON = function (code, obj) {
var body = JSON.stringify(obj);
- res.sendHeader(code, [ ["Content-Type", "text/json"]
- , ["Content-Length", body.length]
- ]);
- res.write(body);
- res.close();
+ res.writeHead(code, { "Content-Type": "text/json"
+ , "Content-Length": body.length
+ });
+ res.end(body);
};
handler(req, res);
@@ -61,7 +58,6 @@ function extname (path) {
fu.staticHandler = function (filename) {
var body, headers;
var content_type = fu.mime.lookupExtension(extname(filename));
- var encoding = (content_type.slice(0,4) === "text" ? "utf8" : "binary");
function loadResponseData(callback) {
if (body && headers && !DEBUG) {
@@ -70,17 +66,15 @@ fu.staticHandler = function (filename) {
}
sys.puts("loading " + filename + "...");
- readFile(filename, encoding, function (err, data) {
+ readFile(filename, function (err, data) {
if (err) {
sys.puts("Error loading " + filename);
} else {
body = data;
- headers = [ [ "Content-Type" , content_type ]
- , [ "Content-Length" , body.length ]
- ];
- if (!DEBUG)
- headers.push(["Cache-Control", "public"]);
-
+ headers = { "Content-Type": content_type
+ , "Content-Length": body.length
+ };
+ if (!DEBUG) headers["Cache-Control"] = "public";
sys.puts("static file " + filename + " loaded");
callback();
}
@@ -89,9 +83,8 @@ fu.staticHandler = function (filename) {
return function (req, res) {
loadResponseData(function () {
- res.sendHeader(200, headers);
- res.write(body, encoding);
- res.close();
+ res.writeHead(200, headers);
+ res.end(body);
});
}
};
@@ -102,7 +95,7 @@ fu.mime = {
lookupExtension : function(ext, fallback) {
return fu.mime.TYPES[ext.toLowerCase()] || fallback || 'application/octet-stream';
},
-
+
// List of most common mime-types, stolen from Rack.
TYPES : { ".3gp" : "video/3gpp"
, ".a" : "application/octet-stream"
View
2 server.js
@@ -64,7 +64,7 @@ var channel = new function () {
while (callbacks.length > 0 && now - callbacks[0].timestamp > 30*1000) {
callbacks.shift().callback([]);
}
- }, 1000);
+ }, 3000);
};
var sessions = {};

0 comments on commit f2d65d9

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