Index: gm/rebaseline_server/server.py |
diff --git a/gm/rebaseline_server/server.py b/gm/rebaseline_server/server.py |
index 5865f5910c80f53492d236bc46d1025dcf2f02dc..0906c4e7ee075a73ce098b5250b75f910c6452e0 100755 |
--- a/gm/rebaseline_server/server.py |
+++ b/gm/rebaseline_server/server.py |
@@ -260,27 +260,36 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
how to handle (static HTML and Javascript, expected/actual results, etc.) |
""" |
def do_GET(self): |
- """ Handles all GET requests, forwarding them to the appropriate |
- do_GET_* dispatcher. """ |
- if self.path == '' or self.path == '/' or self.path == '/index.html' : |
- self.redirect_to('/static/index.html') |
- return |
- if self.path == '/favicon.ico' : |
- self.redirect_to('/static/favicon.ico') |
- return |
+ """ |
+ Handles all GET requests, forwarding them to the appropriate |
+ do_GET_* dispatcher. |
- # All requests must be of this form: |
- # /dispatcher/remainder |
- # where 'dispatcher' indicates which do_GET_* dispatcher to run |
- # and 'remainder' is the remaining path sent to that dispatcher. |
- normpath = posixpath.normpath(self.path) |
- (dispatcher_name, remainder) = PATHSPLIT_RE.match(normpath).groups() |
- dispatchers = { |
- 'results': self.do_GET_results, |
- 'static': self.do_GET_static, |
- } |
- dispatcher = dispatchers[dispatcher_name] |
- dispatcher(remainder) |
+ If we see any Exceptions, return a 404. This fixes http://skbug.com/2147 |
+ """ |
+ try: |
+ logging.debug('do_GET: path="%s"' % self.path) |
+ if self.path == '' or self.path == '/' or self.path == '/index.html' : |
+ self.redirect_to('/static/index.html') |
+ return |
+ if self.path == '/favicon.ico' : |
+ self.redirect_to('/static/favicon.ico') |
+ return |
+ |
+ # All requests must be of this form: |
+ # /dispatcher/remainder |
+ # where 'dispatcher' indicates which do_GET_* dispatcher to run |
+ # and 'remainder' is the remaining path sent to that dispatcher. |
+ normpath = posixpath.normpath(self.path) |
+ (dispatcher_name, remainder) = PATHSPLIT_RE.match(normpath).groups() |
+ dispatchers = { |
+ 'results': self.do_GET_results, |
+ 'static': self.do_GET_static, |
+ } |
+ dispatcher = dispatchers[dispatcher_name] |
+ dispatcher(remainder) |
+ except: |
+ self.send_error(404) |
+ raise |
def do_GET_results(self, type): |
""" Handle a GET request for GM results. |
@@ -290,31 +299,27 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
must be one of the results.RESULTS_* constants |
""" |
logging.debug('do_GET_results: sending results of type "%s"' % type) |
- try: |
- # Since we must make multiple calls to the Results object, grab a |
- # reference to it in case it is updated to point at a new Results |
- # object within another thread. |
- # |
- # TODO(epoger): Rather than using a global variable for the handler |
- # to refer to the Server object, make Server a subclass of |
- # HTTPServer, and then it could be available to the handler via |
- # the handler's .server instance variable. |
- results_obj = _SERVER.results |
- if results_obj: |
- response_dict = self.package_results(results_obj, type) |
- else: |
- now = int(time.time()) |
- response_dict = { |
- 'header': { |
- 'resultsStillLoading': True, |
- 'timeUpdated': now, |
- 'timeNextUpdateAvailable': now + RELOAD_INTERVAL_UNTIL_READY, |
- }, |
- } |
- self.send_json_dict(response_dict) |
- except: |
- self.send_error(404) |
- raise |
+ # Since we must make multiple calls to the Results object, grab a |
+ # reference to it in case it is updated to point at a new Results |
+ # object within another thread. |
+ # |
+ # TODO(epoger): Rather than using a global variable for the handler |
+ # to refer to the Server object, make Server a subclass of |
+ # HTTPServer, and then it could be available to the handler via |
+ # the handler's .server instance variable. |
+ results_obj = _SERVER.results |
+ if results_obj: |
+ response_dict = self.package_results(results_obj, type) |
+ else: |
+ now = int(time.time()) |
+ response_dict = { |
+ 'header': { |
+ 'resultsStillLoading': True, |
+ 'timeUpdated': now, |
+ 'timeNextUpdateAvailable': now + RELOAD_INTERVAL_UNTIL_READY, |
+ }, |
+ } |
+ self.send_json_dict(response_dict) |
def package_results(self, results_obj, type): |
""" Given a nonempty "results" object, package it as a response_dict |
@@ -383,6 +388,7 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
# All requests must be of this form: |
# /dispatcher |
# where 'dispatcher' indicates which do_POST_* dispatcher to run. |
+ logging.debug('do_POST: path="%s"' % self.path) |
normpath = posixpath.normpath(self.path) |
dispatchers = { |
'/edits': self.do_POST_edits, |