setInterval(maintainCache, cacheTimer);
}
-function upstreamRequest(unify, callback) {
+function upstreamRequest(unify) {
// first do a head request
console.log("upsteram as ", unify.requestFor);
function getAndService(unify, xpath) {
- if(global.repoproxy.downloads[unify.fullFilePath] == 1) {
+ if(typeof global.repoproxy.downloads[unify.fullFilePath] != "undefined" && global.repoproxy.downloads[unify.fullFilePath] == 1) {
+ console.log("service inline");
unify.b.write("trying to service inline");
unify.b.end();
} else {
file.end();
global.repoproxy.downloads[unify.fullFilePath] = 0;
});
+
+ res.on("error", function(err) {
+ console.log("res threw error... ", err);
+ });
});
}
}
// file should already exist, so we just poop it out
var inp = fs.createReadStream(unify.fullFilePath);
- inp.setEncoding("utf8");
+ //inp.setEncoding("utf8");
inp.on("data", function(data) {
unify.b.write(data);
});
var res = unify.b;
res.write("<html><h1>Directory listing for " + unify.originalReq + "</h1><hr><pre>");
- if(unify.fullFilePath != "/") res.write("<a href=\"..\">Parent</a>\n\n");
+ if(unify.originalReq != "/") res.write("<a href=\"..\">Parent</a>\n\n");
fs.readdir(unify.fullFilePath, function(err, files) {
console.log("doing directory listing on: ", unify.fullFilePath);
if(err == null) {
unified.b.writeHead(404, {"Content-Type": "text/plain"});
unified.b.write("404 Not Found\n");
} else if(unified.exists) {
- if(unified.isFile) {
+ if(typeof global.repoproxy.downloads[unified.fullFilePath] != "undefined" && global.repoproxy.downloads[unified.fullFilePath] == 1) {
+ cache.upstreamRequest(unified);
+ } else if(unified.isFile) {
cache.serviceFile(unified);
} else if(unified.isDirectory) {
cache.serviceDirectory(unified);
} else {
// it doesnt exist yet, so we send it to the cache service
console.log("file doesnt exist, upstream we go: ", unified);
- cache.upstreamRequest(unified, function(err) {
- if(err == null) {
- cache.watchAndService(unfied);
- } // if upstream sends anything other then a 200, cache.upstreamRequest will handle it (i.e. 302, 404, etc)
- });
+ cache.upstreamRequest(unified);
}
});
}