本文整理汇总了Python中eventlet.green.httplib.HTTPConnection类的典型用法代码示例。如果您正苦于以下问题:Python HTTPConnection类的具体用法?Python HTTPConnection怎么用?Python HTTPConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTTPConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GET
def GET(self, req):
"""Handle the query request."""
conn = HTTPConnection('%s:%s' % (self.mds_ip, self.mds_port))
headers = req.params
conn.request('GET', req.path, headers=headers)
resp = conn.getresponse()
return Response(request=req, body=resp.read(), content_type=resp.getheader('Content-Type'))
示例2: POST
def POST(self, env):
"""Handle posts dealing with metadata alteration"""
req = Request(env)
conn = HTTPConnection('%s:%s' % (self.mds_ip, self.mds_port))
headers = req.params
version, acc, con, obj = split_path(req.path, 1, 4, True)
if not con:
try:
info = get_account_info(env, self.app)
if info:
stor_policy = info['storage_policy']
headers['storage_policy'] = stor_policy
except:
pass
else:
try:
info = get_container_info(env, self.app)
if info:
stor_policy = info['storage_policy']
headers['storage_policy'] = stor_policy
except:
pass
conn.request('POST', req.path, headers=headers)
resp = conn.getresponse()
#confirm response then pass along the request
return self.app
示例3: COPY
def COPY(self, env):
"""Eliminate metadata for deleted objects"""
req = Request(env)
conn = HTTPConnection('%s:%s' % (self.mds_ip, self.mds_port))
headers = req.params
conn.request('COPY', req.path, headers=headers)
resp = conn.getresponse()
#confirm response then pass along the request
return self.app
示例4: http_connect
def http_connect(host, method, path, headers=None):
conn = HTTPConnection(host)
conn.path = path
conn.putrequest(method, path)
if headers:
for header, value in headers.items():
if isinstance(value, (list, tuple)):
for k in value:
conn.putheader(header, str(k))
else:
conn.putheader(header, str(value))
conn.endheaders()
return conn
示例5: sendData
def sendData(self, metaList, data_type, server_ip, server_port):
ip = server_ip
port = server_port
updatedData = json.dumps(metaList)
headers = {'user-agent': data_type}
with ConnectionTimeout(self.conn_timeout):
try:
conn = HTTPConnection('%s:%s' % (ip, port))
conn.request('PUT', '/', headers=headers, body=updatedData)
resp = conn.getresponse()
return resp
except (Exception, Timeout):
return HTTP_INTERNAL_SERVER_ERROR
示例6: PUT
def PUT(self, env):
"""Handle PUT requests related to metadata"""
req = Request(env)
conn = HTTPConnection('%s:%s' % (self.mds_ip, self.mds_port))
headers = req.params
try:
info = get_container_info(env, self.app)
if info:
stor_policy = info['storage_policy']
headers['storage_policy'] = stor_policy
except:
pass
conn.request('PUT', req.path, headers=headers)
resp = conn.getresponse()
return self.app
示例7: getresponse
def getresponse(self):
response = HTTPConnection.getresponse(self)
logging.debug(("HTTP PERF: %(time).5f seconds to %(method)s "
"%(host)s:%(port)s %(path)s)"),
{'time': time.time() - self._connected_time, 'method': self._method,
'host': self.host, 'port': self.port, 'path': self._path})
return response
示例8: http_connect
def http_connect(host, method, path, headers=None):
conn = HTTPConnection(host)
conn.path = path
conn.putrequest(method, path)
if headers:
for header, value in headers.iteritems():
conn.putheader(header, str(value))
conn.endheaders()
return conn
示例9: connect
def connect(self):
#self._connected_time = time.time()
#return HTTPConnection.connect(self)
#with open("/home/ubuntu/spawn.txt", "a") as tran_file:
# tran_file.write("At Connect = "+str(datetime.now())+"\n")
self._connected_time = time.time()
ret = HTTPConnection.connect(self)
#self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
#self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
#self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
return ret
示例10: getresponse
def getresponse(self):
response = HTTPConnection.getresponse(self)
LOG.debug(
"HTTP PERF: %(time).5f seconds to %(method)s " "%(host)s:%(port)s %(path)s)",
{
"time": time.time() - self._connected_time,
"method": self._method,
"host": self.host,
"port": self.port,
"path": self._path,
},
)
return response
示例11: putrequest
def putrequest(self, method, url, skip_host=0, skip_accept_encoding=0):
'''Send a request to the server.
:param method: specifies an HTTP request method, e.g. 'GET'.
:param url: specifies the object being requested, e.g. '/index.html'.
:param skip_host: if True does not add automatically a 'Host:' header
:param skip_accept_encoding: if True does not add automatically an
'Accept-Encoding:' header
'''
self._method = method
self._path = url
return HTTPConnection.putrequest(self, method, url, skip_host,
skip_accept_encoding)
示例12: http_connection
def http_connection(url, proxy=None):
"""
Make an HTTPConnection or HTTPSConnection
:param url: url to connect to
:param proxy: proxy to connect through, if any; None by default; str of the
format 'http://127.0.0.1:8888' to set one
:returns: tuple of (parsed url, connection object)
:raises ClientException: Unable to handle protocol scheme
"""
parsed = urlparse(url)
proxy_parsed = urlparse(proxy) if proxy else None
if parsed.scheme == 'http':
conn = HTTPConnection((proxy_parsed if proxy else parsed).netloc)
elif parsed.scheme == 'https':
conn = HTTPSConnection((proxy_parsed if proxy else parsed).netloc)
else:
raise ClientException('Cannot handle protocol scheme %s for url %s' %
(parsed.scheme, repr(url)))
if proxy:
conn._set_tunnel(parsed.hostname, parsed.port)
return parsed, conn
示例13: getresponse
def getresponse(self):
response = HTTPConnection.getresponse(self)
return response
示例14: putrequest
def putrequest(self, method, url, skip_host=0, skip_accept_encoding=0):
self._method = method
self._path = url
return HTTPConnection.putrequest(self, method, url, skip_host,
skip_accept_encoding)
示例15: connect
def connect(self):
self._connected_time = time.time()
return HTTPConnection.connect(self)