Add client for background testing of HTTP pipelining.

Note this isn't hooked up, so it won't affect users yet. Once the servers are up, it'll be
hooked up to a field test, much like the UDP echo test. Also missing is a force-pipelining option for requests. I'll add that in a separate CL.

BUG=110794
TEST=unit_tests


Review URL: http://codereview.chromium.org/9302024

git-svn-id: http://src.chromium.org/svn/trunk/src/net/tools/testserver@121572 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
diff --git a/testserver.py b/testserver.py
index f917789..12882b5 100755
--- a/testserver.py
+++ b/testserver.py
@@ -378,6 +378,7 @@
       self.MultipartHandler,
       self.MultipartSlowHandler,
       self.GetSSLSessionCacheHandler,
+      self.CloseSocketHandler,
       self.DefaultResponseHandler]
     post_handlers = [
       self.EchoTitleHandler,
@@ -922,6 +923,7 @@
     return self._FileHandlerHelper(prefix)
 
   def _FileHandlerHelper(self, prefix):
+    old_protocol_version = self.protocol_version
     _, _, url_path, _, query, _ = urlparse.urlparse(self.path)
     sub_path = url_path[len(prefix):]
     entries = sub_path.split('/')
@@ -948,7 +950,9 @@
 
       # "HTTP/1.1 200 OK"
       response = f.readline()
-      status_code = re.findall('HTTP/\d+.\d+ (\d+)', response)[0]
+      http_major, http_minor, status_code = re.findall(
+          'HTTP/(\d+).(\d+) (\d+)', response)[0]
+      self.protocol_version = "HTTP/%s.%s" % (http_major, http_minor)
       self.send_response(int(status_code))
 
       for line in f:
@@ -990,6 +994,7 @@
     if (self.command != 'HEAD'):
       self.wfile.write(data)
 
+    self.protocol_version = old_protocol_version
     return True
 
   def SetCookieHandler(self):
@@ -1427,6 +1432,15 @@
                        ' this request')
     return True
 
+  def CloseSocketHandler(self):
+    """Closes the socket without sending anything."""
+
+    if not self._ShouldHandleRequest('/close-socket'):
+      return False
+
+    self.wfile.close()
+    return True
+
   def DefaultResponseHandler(self):
     """This is the catch-all response handler for requests that aren't handled
     by one of the special handlers above.