aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/rebaseline_server/server.py
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-02-07 18:21:59 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-02-07 18:21:59 +0000
commite6af4fb34bd780ff24e0e967a8dc73639ccc2a9d (patch)
tree5de15bfd3fe1933d2bf44dd48fa4ab21b3a2a5eb /gm/rebaseline_server/server.py
parent480ae28b6406b3d759034ad3d0583206d00822fe (diff)
rebaseline_server: properly handle unexpected GETs
BUG=skia:2147 NOTRY=True R=rmistry@google.com Author: epoger@google.com Review URL: https://codereview.chromium.org/157773002 git-svn-id: http://skia.googlecode.com/svn/trunk@13366 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/rebaseline_server/server.py')
-rwxr-xr-xgm/rebaseline_server/server.py96
1 files changed, 51 insertions, 45 deletions
diff --git a/gm/rebaseline_server/server.py b/gm/rebaseline_server/server.py
index 5865f5910c..0906c4e7ee 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,