List:Commits« Previous MessageNext Message »
From:Dyre Tjeldvoll Date:January 7 2013 11:54am
Subject:bzr push into mysql-5.5-cluster-7.2 branch (Dyre.Tjeldvoll:4148 to 4149)
View as plain text  
 4149 Dyre Tjeldvoll	2013-01-07
      Add support for HEAD requests which appear to be issued by modern versions of Firefox

    modified:
      storage/ndb/mcc/request_handler.py
 4148 Dyre Tjeldvoll	2013-01-04 [merge]
      Merge

    renamed:
      storage/ndb/mcc/ndb_setup.template => storage/ndb/mcc/ndb_setup.py.in
    modified:
      storage/ndb/mcc/CMakeLists.txt
      storage/ndb/mcc/ndb_setup.py.in
=== modified file 'storage/ndb/mcc/request_handler.py'
--- a/storage/ndb/mcc/request_handler.py	2012-12-06 14:03:02 +0000
+++ b/storage/ndb/mcc/request_handler.py	2013-01-07 11:53:42 +0000
@@ -44,6 +44,7 @@ import tempfile
 import threading
 import random
 import stat
+import errno
 
 import util
 import config_parser
@@ -396,12 +397,11 @@ class ConfiguratorHandler(BaseHTTPServer
         self.end_headers()
         self.server.logger.debug('Will send: %s', json.dumps(obj, indent=2, cls=ReplyJsonEncoder))
         json.dump(obj, self.wfile, cls=ReplyJsonEncoder)       
-    
-    def do_GET(self):
-        """Handles GET requests by returning the specified file. Attempts to guess 
+        
+    def _do_file_req(self, rt):
+        """Handles file requests. Attempts to guess 
         the MIME type and set the Content-Type accordingly."""
         log_thread_name()
-        f = None
         try:
             self.send_response(200)
             (ct, enc) = mimetypes.guess_type(self.path)
@@ -410,19 +410,37 @@ class ConfiguratorHandler(BaseHTTPServer
             if (enc):
                 self.send_header('Content-Encoding',  enc)
             self.end_headers()
-            self.server.logger.debug("fdir="+self.server.opts['fdir']+ " path="+os.path.normpath(self.path))
+            self.server.logger.debug(rt+' fdir='+self.server.opts['fdir']+ " path="+os.path.normpath(self.path))
             fn = os.path.join(self.server.opts['fdir'], os.path.normpath(self.path[1:]))
-            self.server.logger.debug('Serving file `'+fn+'\'')
-            f = open(fn, "rb")
-            self.wfile.write(f.read()+'\r\n\r\n')
             
+            if rt == 'HEAD':
+                os.stat(fn)                
+            elif rt == 'GET':
+                with open(fn, "rb") as f:
+                    self.wfile.write(f.read()+'\r\n\r\n')
+            else:
+                raise Exception('Unknown file request type: '+rt)
+            
+        except OSError as ose:
+            self.server.logger.exception(rt + ' '+self.path+ ' failed')
+            if ose.errno == errno.ENOENT:
+                self.send_error(404,'File '+self.path+'('+ose.filename+') does not exist.')
+            else:
+                self.send_error(500,'Unexpected exception occured: '+rt+' '+self.path+'\n'+traceback.format_exc()) # Some other number
+
         except:
-            self.server.logger.exception('GET request failed:')       
-            self.send_error(404,'File Not Found: '+self.path+'\n'+traceback.format_exc())
-        finally:
-            if f:
-                f.close()
-                
+            self.server.logger.exception(rt + ' '+self.path+ ' failed')
+            self.send_error(500,'Unexpected exception occured while processing: '+rt+' '+self.path+'\n'+traceback.format_exc()) # Some other number
+        
+    def do_HEAD(self):
+        """Handles HEAD requests by returning the headers without the body if file can be stated."""
+
+        self._do_file_req('HEAD')
+
+    def do_GET(self):
+        """Handles GET requests by returning the specified file."""
+        self._do_file_req('GET')
+
     def do_POST(self):
         """Handles POST requests, in the form of json-serialized command (request) 
         objects, from the frontend."""

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.5-cluster-7.2 branch (Dyre.Tjeldvoll:4148 to 4149) Dyre Tjeldvoll5 Feb