| Index: net/tools/testserver/testserver.py
|
| ===================================================================
|
| --- net/tools/testserver/testserver.py (revision 7487)
|
| +++ net/tools/testserver/testserver.py (working copy)
|
| @@ -109,6 +109,16 @@
|
|
|
| BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, request, client_address, socket_server)
|
|
|
| + def _ShouldHandleRequest(self, handler_name):
|
| + """Determines if the path can be handled by the handler.
|
| +
|
| + We consider a handler valid if the path begins with the
|
| + handler name. It can optionally be followed by "?*", "/*".
|
| + """
|
| +
|
| + pattern = re.compile('%s($|\?|/).*' % handler_name)
|
| + return pattern.match(self.path)
|
| +
|
| def GetMIMETypeFromName(self, file_name):
|
| """Returns the mime type for the specified file_name. So far it only looks
|
| at the file extension."""
|
| @@ -140,7 +150,7 @@
|
| """This request handler yields a page with the title set to the current
|
| system time, and no caching requested."""
|
|
|
| - if (self.path.find("/nocachetime/maxage") != 0):
|
| + if not self._ShouldHandleRequest("/nocachetime/maxage"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -156,7 +166,7 @@
|
| """This request handler yields a page with the title set to the current
|
| system time, and no caching requested."""
|
|
|
| - if (self.path.find("/nocachetime") != 0):
|
| + if not self._ShouldHandleRequest("/nocachetime"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -172,7 +182,7 @@
|
| """This request handler yields a page with the title set to the current
|
| system time, and allows caching for one minute."""
|
|
|
| - if self.path.find("/cachetime") != 0:
|
| + if not self._ShouldHandleRequest("/cachetime"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -188,7 +198,7 @@
|
| """This request handler yields a page with the title set to the current
|
| system time, and set the page to expire on 1 Jan 2099."""
|
|
|
| - if (self.path.find("/cache/expires") != 0):
|
| + if not self._ShouldHandleRequest("/cache/expires"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -204,7 +214,7 @@
|
| """This request handler yields a page with the title set to the current
|
| system time, and allows caching for 60 seconds"""
|
|
|
| - if (self.path.find("/cache/proxy-revalidate") != 0):
|
| + if not self._ShouldHandleRequest("/cache/proxy-revalidate"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -220,7 +230,7 @@
|
| """This request handler yields a page with the title set to the current
|
| system time, and allows caching for 5 seconds."""
|
|
|
| - if (self.path.find("/cache/private") != 0):
|
| + if not self._ShouldHandleRequest("/cache/private"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -236,7 +246,7 @@
|
| """This request handler yields a page with the title set to the current
|
| system time, and allows caching for 5 seconds."""
|
|
|
| - if (self.path.find("/cache/public") != 0):
|
| + if not self._ShouldHandleRequest("/cache/public"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -252,7 +262,7 @@
|
| """This request handler yields a page with the title set to the current
|
| system time, and does not allow for caching."""
|
|
|
| - if (self.path.find("/cache/s-maxage") != 0):
|
| + if not self._ShouldHandleRequest("/cache/s-maxage"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -268,7 +278,7 @@
|
| """This request handler yields a page with the title set to the current
|
| system time, and does not allow caching."""
|
|
|
| - if (self.path.find("/cache/must-revalidate") != 0):
|
| + if not self._ShouldHandleRequest("/cache/must-revalidate"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -285,7 +295,7 @@
|
| system time, and does not allow caching event though max-age of 60
|
| seconds is specified."""
|
|
|
| - if (self.path.find("/cache/must-revalidate/max-age") != 0):
|
| + if not self._ShouldHandleRequest("/cache/must-revalidate/max-age"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -297,12 +307,11 @@
|
|
|
| return True
|
|
|
| -
|
| def CacheNoStoreHandler(self):
|
| """This request handler yields a page with the title set to the current
|
| system time, and does not allow the page to be stored."""
|
|
|
| - if (self.path.find("/cache/no-store") != 0):
|
| + if not self._ShouldHandleRequest("/cache/no-store"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -319,7 +328,7 @@
|
| system time, and does not allow the page to be stored even though max-age
|
| of 60 seconds is specified."""
|
|
|
| - if (self.path.find("/cache/no-store/max-age") != 0):
|
| + if not self._ShouldHandleRequest("/cache/no-store/max-age"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -337,7 +346,7 @@
|
| system time, and does not allow the content to transformed during
|
| user-agent caching"""
|
|
|
| - if (self.path.find("/cache/no-transform") != 0):
|
| + if not self._ShouldHandleRequest("/cache/no-transform"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -352,7 +361,7 @@
|
| def EchoHeader(self):
|
| """This handler echoes back the value of a specific request header."""
|
|
|
| - if self.path.find("/echoheader") != 0:
|
| + if not self._ShouldHandleRequest("/echoheader"):
|
| return False
|
|
|
| query_char = self.path.find('?')
|
| @@ -377,7 +386,7 @@
|
| """This handler just echoes back the payload of the request, for testing
|
| form submission."""
|
|
|
| - if self.path.find("/echo") != 0:
|
| + if not self._ShouldHandleRequest("/echo"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -391,7 +400,7 @@
|
| def EchoTitleHandler(self):
|
| """This handler is like Echo, but sets the page title to the request."""
|
|
|
| - if self.path.find("/echotitle") != 0:
|
| + if not self._ShouldHandleRequest("/echotitle"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -408,7 +417,7 @@
|
| """This handler yields a (more) human-readable page listing information
|
| about the request header & contents."""
|
|
|
| - if self.path.find("/echoall") != 0:
|
| + if not self._ShouldHandleRequest("/echoall"):
|
| return False
|
|
|
| self.send_response(200)
|
| @@ -481,7 +490,7 @@
|
| def DownloadFinishHandler(self):
|
| """This handler just tells the server to finish the current download."""
|
|
|
| - if not self.path.startswith("/download-finish"):
|
| + if not self._ShouldHandleRequest("/download-finish"):
|
| return False
|
|
|
| self.server.waitForDownload = False
|
| @@ -616,7 +625,7 @@
|
| """This handler tests 'Basic' authentication. It just sends a page with
|
| title 'user/pass' if you succeed."""
|
|
|
| - if not self.path.startswith("/auth-basic"):
|
| + if not self._ShouldHandleRequest("/auth-basic"):
|
| return False
|
|
|
| username = userpass = password = b64str = ""
|
| @@ -672,7 +681,7 @@
|
| """This handler tests 'Digest' authentication. It just sends a page with
|
| title 'user/pass' if you succeed."""
|
|
|
| - if not self.path.startswith("/auth-digest"):
|
| + if not self._ShouldHandleRequest("/auth-digest"):
|
| return False
|
|
|
| # Periodically generate a new nonce. Technically we should incorporate
|
| @@ -760,7 +769,7 @@
|
| def SlowServerHandler(self):
|
| """Wait for the user suggested time before responding. The syntax is
|
| /slow?0.5 to wait for half a second."""
|
| - if not self.path.startswith("/slow"):
|
| + if not self._ShouldHandleRequest("/slow"):
|
| return False
|
| query_char = self.path.find('?')
|
| wait_sec = 1.0
|
| @@ -780,7 +789,7 @@
|
| """Returns a string of html with the given content type. E.g.,
|
| /contenttype?text/css returns an html file with the Content-Type
|
| header set to text/css."""
|
| - if not self.path.startswith('/contenttype'):
|
| + if not self._ShouldHandleRequest("/contenttype"):
|
| return False
|
| query_char = self.path.find('?')
|
| content_type = self.path[query_char + 1:].strip()
|
| @@ -797,7 +806,7 @@
|
| '/server-redirect?http://foo.bar/asdf' to redirect to 'http://foo.bar/asdf'"""
|
|
|
| test_name = "/server-redirect"
|
| - if not self.path.startswith(test_name):
|
| + if not self._ShouldHandleRequest(test_name):
|
| return False
|
|
|
| query_char = self.path.find('?')
|
| @@ -820,7 +829,7 @@
|
| '/client-redirect?http://foo.bar/asdf' to redirect to 'http://foo.bar/asdf'"""
|
|
|
| test_name = "/client-redirect"
|
| - if not self.path.startswith(test_name):
|
| + if not self._ShouldHandleRequest(test_name):
|
| return False
|
|
|
| query_char = self.path.find('?');
|
|
|