当前位置: 首页>>代码示例>>Python>>正文


Python HTTPSConnection.putheader方法代码示例

本文整理汇总了Python中eventlet.green.httplib.HTTPSConnection.putheader方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPSConnection.putheader方法的具体用法?Python HTTPSConnection.putheader怎么用?Python HTTPSConnection.putheader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eventlet.green.httplib.HTTPSConnection的用法示例。


在下文中一共展示了HTTPSConnection.putheader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: http_connect_raw

# 需要导入模块: from eventlet.green.httplib import HTTPSConnection [as 别名]
# 或者: from eventlet.green.httplib.HTTPSConnection import putheader [as 别名]
def http_connect_raw(ipaddr, port, method, path, headers=None,
                     query_string=None, ssl=False):
    """
    Helper function to create an HTTPConnection object. If ssl is set True,
    HTTPSConnection will be used. However, if ssl=False, BufferedHTTPConnection
    will be used, which is buffered for backend Swift services.

    :param ipaddr: IPv4 address to connect to
    :param port: port to connect to
    :param method: HTTP method to request ('GET', 'PUT', 'POST', etc.)
    :param path: request path
    :param headers: dictionary of headers
    :param query_string: request query string
    :param ssl: set True if SSL should be used (default: False)
    :returns: HTTPConnection object
    """
    if ssl:
        conn = HTTPSConnection('%s:%s' % (ipaddr, port))
    else:
        conn = BufferedHTTPConnection('%s:%s' % (ipaddr, port))
    if query_string:
        path += '?' + query_string
    conn.path = path
    conn.putrequest(method, path)
    if headers:
        for header, value in headers.iteritems():
            conn.putheader(header, value)
    conn.endheaders()
    return conn
开发者ID:AsherBond,项目名称:colony,代码行数:31,代码来源:bufferedhttp.py

示例2: http_connect

# 需要导入模块: from eventlet.green.httplib import HTTPSConnection [as 别名]
# 或者: from eventlet.green.httplib.HTTPSConnection import putheader [as 别名]
def http_connect(ipaddr, port, device, partition, method, path,
                 headers=None, query_string=None, ssl=False):
    """
    Helper function to create an HTTPConnection object. If ssl is set True,
    HTTPSConnection will be used. However, if ssl=False, BufferedHTTPConnection
    will be used, which is buffered for backend Swift services.

    :param ipaddr: IPv4 address to connect to
    :param port: port to connect to
    :param device: device of the node to query
    :param partition: partition on the device
    :param method: HTTP method to request ('GET', 'PUT', 'POST', etc.)
    :param path: request path
    :param headers: dictionary of headers
    :param query_string: request query string
    :param ssl: set True if SSL should be used (default: False)
    :returns: HTTPConnection object
    """
    if not port:
        port = 443 if ssl else 80
    if ssl:
        conn = HTTPSConnection('%s:%s' % (ipaddr, port))
    else:
        conn = BufferedHTTPConnection('%s:%s' % (ipaddr, port))
    path = quote('/' + device + '/' + str(partition) + path)
    if query_string:
        path += '?' + query_string
    conn.path = path
    conn.putrequest(method, path, skip_host=(headers and 'Host' in headers))
    if headers:
        for header, value in headers.iteritems():
            conn.putheader(header, str(value))
    conn.endheaders()
    return conn
开发者ID:OpenStack-Kha,项目名称:swift,代码行数:36,代码来源:bufferedhttp.py

示例3: http_connect_raw

# 需要导入模块: from eventlet.green.httplib import HTTPSConnection [as 别名]
# 或者: from eventlet.green.httplib.HTTPSConnection import putheader [as 别名]
def http_connect_raw(ipaddr, port, method, path, headers=None,
                     query_string=None, ssl=False, key_file=None,
                     cert_file=None, timeout=None):
    """
    Helper function to create an HTTPConnection object. If ssl is set True,
    HTTPSConnection will be used. However, if ssl=False, BufferedHTTPConnection
    will be used, which is buffered for backend Swift services.

    :param ipaddr: IPv4 address to connect to
    :param port: port to connect to
    :param method: HTTP method to request ('GET', 'PUT', 'POST', etc.)
    :param path: request path
    :param headers: dictionary of headers
    :param query_string: request query string
    :param ssl: set True if SSL should be used (default: False)
    :param key_file: Private key file (not needed if cert_file has private key)
    :param cert_file: Certificate file (Keystore)
    :returns: HTTPConnection object
    """
    if timeout is None:
        timeout = DEFAULT_TIMEOUT
    if ssl:
        conn = HTTPSConnection('%s:%s' % (ipaddr, port), key_file=key_file,
                               cert_file=cert_file, timeout=timeout)
    else:
        conn = BufferedHTTPConnection('%s:%s' % (ipaddr, port),
                                      timeout=timeout)
    if query_string:
        path += '?' + query_string
    conn.path = path
    conn.putrequest(method, path)
    if headers:
        # pylint: disable=E1103
        for header, value in headers.iteritems():
            conn.putheader(header, value)
    # pylint: disable=E1103
    conn.endheaders()
    return conn
开发者ID:HugoKuo,项目名称:keystone-essex3,代码行数:40,代码来源:bufferedhttp.py

示例4: send_to_peer

# 需要导入模块: from eventlet.green.httplib import HTTPSConnection [as 别名]
# 或者: from eventlet.green.httplib.HTTPSConnection import putheader [as 别名]
    def send_to_peer(self, peer, sync_to_peer, key):
        peer = peer.lower()
        ssl = False
        if peer.startswith('https://'):
            ssl = True
            peer = peer[8:]
        if peer.startswith('http://'):
            peer = peer[7:]
        try:
            with Timeout(self.conn_timeout):
                if ssl:
                    #print 'HTTPS %s ' % peer
                    conn = HTTPSConnection(peer)
                else:
                    #print 'HTTP %s ' % peer
                    conn = HTTPConnection(peer)
            conn.putrequest(self.req.method, self.req.path_qs)
            conn.putheader('X-Orig-Cluster', self.my_cluster)
            conn.putheader('X-Account-Meta-Orig-Cluster', self.my_cluster)
            conn.putheader('X-Container-Meta-Orig-Cluster', self.my_cluster)
            if key:
                sync_to = sync_to_peer + self.env['PATH_INFO']
                conn.putheader('X-Container-Sync-To', sync_to)
            for header, value in self.req.headers.iteritems():
                if header != 'X-Container-Sync-To':
                    conn.putheader(header, value)
            conn.endheaders(message_body=None)
            with Timeout(self.req_timeout):
                resp = conn.getresponse()
                status = resp.status
                return (status, resp.getheaders(), resp.read())
        except (Exception, Timeout) as e:
            # Print error log
            print >> sys.stderr, peer + ': Exception, Timeout error: %s' % e

        print '<<<<<<<< HTTP_SERVICE_UNAVAILABLE'
开发者ID:davidhadas,项目名称:Autosync,代码行数:38,代码来源:autosync.py


注:本文中的eventlet.green.httplib.HTTPSConnection.putheader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。