parameters: (host, port, tries=3, command='GET', path='/',
                              expected_read='', timeout=2)
return_statement: return (False, client_error or 'Timeout')
docstring: Checks whether the specified http server is ready to serve request or not.
  
    Args:
      host: Host name of the HTTP server.
      port: Port number of the HTTP server.
      tries: How many times we want to test the connection. The default value is
             3.
      command: The http command we use to connect to HTTP server. The default
               command is 'GET'.
      path: The path we use when connecting to HTTP server. The default path is
            '/'.
      expected_read: The content we expect to read from the response. The default
                     value is ''.
      timeout: Timeout (in seconds) for each http connection. The default is 2s.
  
    Returns:
      Tuple of (connect status, client error). connect status is a boolean value
      to indicate whether the server is connectable. client_error is the error
      message the server returns when connect status is false.
docstring_summary: Checks whether the specified http server is ready to serve request or not.
docstring_tokens: Checks whether the specified http server is ready to serve request or not .
function: def IsHttpServerConnectable(host, port, tries=3, command='GET', path='/',
                              expected_read='', timeout=2):
    """Checks whether the specified http server is ready to serve request or not.
  
    Args:
      host: Host name of the HTTP server.
      port: Port number of the HTTP server.
      tries: How many times we want to test the connection. The default value is
             3.
      command: The http command we use to connect to HTTP server. The default
               command is 'GET'.
      path: The path we use when connecting to HTTP server. The default path is
            '/'.
      expected_read: The content we expect to read from the response. The default
                     value is ''.
      timeout: Timeout (in seconds) for each http connection. The default is 2s.
  
    Returns:
      Tuple of (connect status, client error). connect status is a boolean value
      to indicate whether the server is connectable. client_error is the error
      message the server returns when connect status is false.
    """
    assert tries >= 1
    for i in xrange(0, tries):
      client_error = None
      try:
        with contextlib.closing(httplib.HTTPConnection(
            host, port, timeout=timeout)) as http:
          # Output some debug information when we have tried more than 2 times.
          http.set_debuglevel(i >= 2)
          http.request(command, path)
          r = http.getresponse()
          content = r.read()
          if r.status == 200 and r.reason == 'OK' and content == expected_read:
            return (True, '')
          client_error = ('Bad response: %s %s version %s\n  ' %
                          (r.status, r.reason, r.version) +
                          '\n  '.join([': '.join(h) for h in r.getheaders()]))
      except (httplib.HTTPException, socket.error) as e:
        # Probably too quick connecting: try again.
        exception_error_msgs = traceback.format_exception_only(type(e), e)
        if exception_error_msgs:
          client_error = ''.join(exception_error_msgs)
    # Only returns last client_error.
    return (False, client_error or 'Timeout')
function_tokens: def IsHttpServerConnectable ( host , port , tries = 3 , command = 'GET' , path = '/' , expected_read = '' , timeout = 2 ) : assert tries >= 1 for i in xrange ( 0 , tries ) : client_error = None try : with contextlib . closing ( httplib . HTTPConnection ( host , port , timeout = timeout ) ) as http : # Output some debug information when we have tried more than 2 times. http . set_debuglevel ( i >= 2 ) http . request ( command , path ) r = http . getresponse ( ) content = r . read ( ) if r . status == 200 and r . reason == 'OK' and content == expected_read : return ( True , '' ) client_error = ( 'Bad response: %s %s version %s\n  ' % ( r . status , r . reason , r . version ) + '\n  ' . join ( [ ': ' . join ( h ) for h in r . getheaders ( ) ] ) ) except ( httplib . HTTPException , socket . error ) as e : # Probably too quick connecting: try again. exception_error_msgs = traceback . format_exception_only ( type ( e ) , e ) if exception_error_msgs : client_error = '' . join ( exception_error_msgs ) # Only returns last client_error. return ( False , client_error or 'Timeout' )