-/* $Id: httpd.js,v 1.33 2005/07/09 05:44:53 mmondor Exp $ */
+/* $Id: httpd.js,v 1.34 2005/07/09 06:33:19 mmondor Exp $ */
/*
* Copyright (c) 2005, Matthew Mondor
* Server identification
*/
SERVER_VERSION = 'mmondor_js_httpd/0.0.1 (NetBSD)';
-SERVER_CVSID = '$Id: httpd.js,v 1.33 2005/07/09 05:44:53 mmondor Exp $';
+SERVER_CVSID = '$Id: httpd.js,v 1.34 2005/07/09 06:33:19 mmondor Exp $';
FD.prototype.httpRespond = function(time)
{
- var path, fd, st, res, ext, mimetype, i, index, sess;
+ var path, fd, st, res, ext, mimetype, i, sess;
var cookie = undefined;
- index = false;
- for (;;) {
- path = this.http_vhost.htdocs_root.valid_virtual(
- this.http_path);
- if (!path) {
- http_error(this, 403, 'Permission Denied',
- 'You do not have the permission to access this ' +
- 'resource.');
- return true;
- }
+ /*
+ * Attempt to find requested file.
+ * If it consists of a directory, attempt to first find index.html in
+ * it, then index.jso in it, fail with error 403 if none can be found.
+ * Otherwise, continue forward keeping the descriptor open, and the
+ * stat information already filled in.
+ */
+
+ path = this.http_vhost.htdocs_root.valid_virtual(this.http_path);
+ if (!path) {
+ http_error(this, 403, 'Permission Denied',
+ 'You do not have the permission to access this ' +
+ 'resource.');
+ return true;
+ }
+
+ fd = new FD();
+
+ try {
+ fd.open(path.real, FD.O_RDONLY);
+ st = fd.fstat();
+ } catch (x) {
+ http_error(this, 404, 'Not Found',
+ path.virtual + ' could not be found.');
+ return true;
+ }
+
+ if ((st.st_mode & FD.S_IFDIR) != 0) {
+ var error = false;
- fd = new FD();
+ fd.close();
try {
- fd.open(path.real, FD.O_RDONLY);
+ fd.open(path.real + '/index.html', FD.O_RDONLY);
st = fd.fstat();
+ path.real += '/index.html';
+ path.virtual += '/index.html';
} catch (x) {
- if (index) {
- http_error(this, 403, 'Permission Denied',
- 'You do not have the permission to ' +
- 'access this resource.');
- return true;
- } else {
- http_error(this, 404, 'Not Found',
- path.virtual + ' could not be found.');
- return true;
+ err.put(x + "\n");
+ try {
+ fd.open(path.real + '/index.jso',
+ FD.O_RDONLY);
+ st = fd.fstat();
+ path.real += '/index.jso';
+ path.virtual += '/index.jso';
+ } catch (x) {
+ error = true;
}
}
-
- /*
- * Is file a directory? If so, attempt to fallback to
- * index.html inside it.
- */
- if ((st.st_mode & FD.S_IFDIR) != 0) {
- fd.close();
- this.http_path += '/index.html';
- index = true;
- continue;
+ if (error) {
+ http_error(this, 403, 'Permission Denied',
+ 'You do not have the permission to access the ' +
+ 'resource ' + path.virtual);
+ return true;
}
-
- break;
}
/*
if ((st.st_mode & FD.S_IFREG) == 0) {
fd.close();
http_error(this, 403, 'Permission Denied',
- 'You do not have the permission to access this resource.');
+ 'You do not have the permission to access the resource ' +
+ path.virtual);
return true;
}
'Please try again later.');
}
+ delete obj;
return true;
}