*** empty log message ***
authorMatthew Mondor <mmondor@pulsar-zone.net>
Fri, 15 Jul 2005 14:17:56 +0000 (14:17 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Fri, 15 Jul 2005 14:17:56 +0000 (14:17 +0000)
tests/js-test/js/httpd/httpd.js

index 9069ff4..34dd7e7 100644 (file)
@@ -1,4 +1,4 @@
-/* $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
@@ -50,9 +50,6 @@
  * - 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
  */
 
@@ -62,7 +59,7 @@
  * 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 $';
 
 
 
@@ -344,7 +341,10 @@ HTTPReply.prototype = {
                        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);
        }
 }
 
@@ -497,7 +497,7 @@ function process_transfer(time)
         * 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) {
@@ -650,7 +650,7 @@ FD.prototype.init = function(time, idx)
  */
 FD.prototype.parseRequest = function(time)
 {
-       var close = valid = old = false;
+       var close = valid = false;
        var evil_browser = evil_os = false;
        var vhost = '';
        var lines;
@@ -671,6 +671,7 @@ FD.prototype.parseRequest = function(time)
        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");
@@ -682,7 +683,8 @@ FD.prototype.parseRequest = function(time)
                        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' ||
@@ -695,32 +697,10 @@ FD.prototype.parseRequest = function(time)
                }
        }
 
-       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) {
@@ -763,6 +743,20 @@ FD.prototype.parseRequest = function(time)
                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
         */