Пример #1
0
 def _prepare_connection(self, url, headers):
     if not isinstance(url, atom_url.Url):
         if isinstance(url, types.StringTypes):
             url = atom_url.parse_url(url)
         else:
             raise atom_http_interface.UnparsableUrlObject(
                 'Unable to parse url '
                 'parameter because it was not a string or atom_url.Url')
     if url.protocol == 'https':
         if not url.port:
             return httplib.HTTPSConnection(url.host)
         return httplib.HTTPSConnection(url.host, int(url.port))
     else:
         if not url.port:
             return httplib.HTTPConnection(url.host)
         return httplib.HTTPConnection(url.host, int(url.port))
Пример #2
0
def http_request(method, host, path, headers):
    conn = httplib.HTTPConnection(host)
    conn.request(method, path, headers=headers)
    response = conn.getresponse()
    body = response.read()
    print(method, host, path, response.status, response.reason, len(body))
    return format_response(response, body)
Пример #3
0
    def _get_connection(self, uri, headers=None):
        """Opens a socket connection to the server to set up an HTTP request.

    Args:
      uri: The full URL for the request as a Uri object.
      headers: A dict of string pairs containing the HTTP headers for the
          request.
    """
        connection = None
        if uri.scheme == 'https':
            if not uri.port:
                connection = httplib.HTTPSConnection(uri.host)
            else:
                connection = httplib.HTTPSConnection(uri.host, int(uri.port))
        else:
            if not uri.port:
                connection = httplib.HTTPConnection(uri.host)
            else:
                connection = httplib.HTTPConnection(uri.host, int(uri.port))
        return connection
Пример #4
0
def PrepareConnection(service, full_uri):
    """Opens a connection to the server based on the full URI.

  This method is deprecated, instead use atom_http.HttpClient.request.

  Examines the target URI and the proxy settings, which are set as
  environment variables, to open a connection with the server. This
  connection is used to make an HTTP request.

  Args:
    service: atom.AtomService or a subclass. It must have a server string which
      represents the server host to which the request should be made. It may also
      have a dictionary of additional_headers to send in the HTTP request.
    full_uri: str Which is the target relative (lacks protocol and host) or
    absolute URL to be opened. Example:
    'https://www.google.com/accounts/ClientLogin' or
    'base/feeds/snippets' where the server is set to www.google.com.

  Returns:
    A tuple containing the httplib.HTTPConnection and the full_uri for the
    request.
  """
    deprecation('calling deprecated function PrepareConnection')
    (server, port, ssl, partial_uri) = ProcessUrl(service, full_uri)
    if ssl:
        # destination is https
        # XXX: Non working proxy support removed. -Saul
        connection = httplib.HTTPSConnection(server, port)
        full_uri = partial_uri
    else:
        # destination is http
        # XXX: Non working proxy support removed. -Saul
        connection = httplib.HTTPConnection(server, port)
        full_uri = partial_uri

    return (connection, full_uri)