-/* $Id: httpd.js,v 1.64 2005/07/15 00:05:15 mmondor Exp $ */
+/* $Id: httpd.js,v 1.65 2005/07/15 14:17:56 mmondor Exp $ */
/*
* Copyright (c) 2005, Matthew Mondor
* - It might be nice to implement a minimal database-like facility, where
* for performance we could log changes, and only sync to disk once in a
* while, discarding obsolete logs... JSON would be used
- * - Support old-style HTTP requests if the default vhost does not allow
- * scripts. Thid would however require http_error() and HTTPResult()
- * modifications to support header-less operation.
* - Enhance the JS shell to report errors better
*/
* Server identification
*/
SERVER_VERSION = 'mmondor_js_httpd/0.0.1 (NetBSD)';
-SERVER_CVSID = '$Id: httpd.js,v 1.64 2005/07/15 00:05:15 mmondor Exp $';
+SERVER_CVSID = '$Id: httpd.js,v 1.65 2005/07/15 14:17:56 mmondor Exp $';
headers += 'Content-Type: ' + this.type + "\r\n";
headers += "\r\n";
- fd.bwrite(headers + contents);
+ if (!fd.http_old_get)
+ fd.bwrite(headers + contents);
+ else
+ fd.bwrite(contents);
}
}
* We take care not to transfer more than this.transfer_size bytes
* outbound.
* XXX We might also want to observe it for inbound, where it could
- * be set to the user-provided Content-Length...
+ * be set to the user-provided Content-Length... for PUT ?
*/
if (this.transfer_state == STATE_TRANSFER_READ) {
if (this == this.transfer_src) {
*/
FD.prototype.parseRequest = function(time)
{
- var close = valid = old = false;
+ var close = valid = false;
var evil_browser = evil_os = false;
var vhost = '';
var lines;
this.http_sessid = undefined;
this.http_vars_session = {};
this.http_range = undefined;
+ this.http_old_get = false;
/* Split request lines */
lines = this.request_data.split("\r\n");
this.http_method = words[0];
this.http_path = words[1];
this.http_protocol = 'HTTP/1.1';
- valid = old = true;
+ this.http_old_get = true;
+ valid = true;
} else if (words.length == 3) {
if ((words[0] == 'GET' || words[0] == 'POST' ||
words[0] == 'PUT') && (words[2] == 'HTTP/1.0' ||
}
}
- if (old) {
- /*
- * We can't send any headers in this case, just error
- * for now.
- *
- * XXX It would be nice to support general requests in the
- * future, although there are serious limitations to that
- * old protocol. Maybe static pages only for instance on
- * the default vhost. The HTTPResult object, as well as the
- * http_error() function would then need to support a special
- * flag not to include any headers.
- */
- this.bwrite('<html><head>' +
- '<title>Unsupported Old-Style Request</title></head>' +
- '<body><h1>Unsupported Old-Style Request</h1><p>' +
- 'Your browser sent an old-style HTTP request, which ' +
- 'this server does not support. Use an HTTP/1.0 or ' +
- 'HTTP/1.1 compliant client to continue.</p></body>' +
- '</html>' + "\r\n");
- return true;
- }
-
/*
* Parse header for interesting lines.
*/
- if (valid) {
+ if (valid && !this.http_old_get) {
for (i in lines) {
words = lines[i].split(' ');
if (words[0] == 'Host:' && words.length == 2) {
vhost = options.default_vhost;
this.http_vhost = vhosts_table[vhost.toLowerCase()];
+ if (this.http_old_get && this.http_vhost.scripts) {
+ /*
+ * We only allow old style GET request on static vhosts
+ */
+ this.bwrite('<html><head>' +
+ '<title>Unsupported Old-Style Request</title></head>' +
+ '<body><h1>Unsupported Old-Style Request</h1><p>' +
+ 'Your browser sent an old-style HTTP request, which ' +
+ 'this server does not support on dynamic content ' +
+ 'virtual hosts. Use an HTTP/1.0 or HTTP/1.1 compliant ' +
+ 'client to continue.</p></body></html>' + "\r\n");
+ return true;
+ }
+
/*
* Filter out definitely invalid requests
*/