diff rlgwebd.js @ 34:57f4b36ef06b

rlgwebd.js: handle HTTP HEAD properly. Prevent a message body from being sent in response to HTTP HEAD.
author John "Elwin" Edwards <elwin@sdf.org>
date Tue, 05 Jun 2012 20:13:47 -0700
parents c75fc4b1d13d
children a0387f112bcf
line wrap: on
line diff
--- a/rlgwebd.js	Tue Jun 05 14:55:33 2012 -0700
+++ b/rlgwebd.js	Tue Jun 05 20:13:47 2012 -0700
@@ -518,14 +518,18 @@
         }
         else {
           res.writeHead(200, resheaders);
-          res.write(data);
+          if (req.method != 'HEAD')
+            res.write(data);
           res.end();
         }
       });
     }
     else {
       res.writeHead(404, resheaders);
-      res.write("<html><head><title>" + nname + "</title></head>\n<body><h1>" + nname + " Not Found</h1></body></html>\n");
+      if (req.method != 'HEAD') {
+        res.write("<html><head><title>" + nname + "</title></head>\n<body><h1>"
+                  + nname + " Not Found</h1></body></html>\n");
+      }
       res.end();
     }
   });
@@ -573,7 +577,8 @@
     }
   }
   res.writeHead(200, { "Content-Type": "application/json" });
-  res.write(JSON.stringify(reply));
+  if (req.method != 'HEAD')
+    res.write(JSON.stringify(reply));
   res.end();
 }
 
@@ -609,7 +614,6 @@
 
   /* This will send the response once the whole request is here. */
   function respond() {
-    //formdata = getFormValues(reqbody);
     formdata = getMsg(reqbody);
     var target = url.parse(req.url).pathname;
     var cterm = findTermSession(formdata);
@@ -650,6 +654,11 @@
     }
     else if (req.method == 'GET' || req.method == 'HEAD') {
       if (target == '/feed') {
+        if (req.method == 'HEAD') {
+          res.writeHead(200, {"Content-Type": "application/json"});
+          res.end();
+          return;
+        }
         if (!cterm) {
           sendError(res, 1, null);
           return;