本文整理汇总了Python中httplib.HTTPResponse.close方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPResponse.close方法的具体用法?Python HTTPResponse.close怎么用?Python HTTPResponse.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类httplib.HTTPResponse
的用法示例。
在下文中一共展示了HTTPResponse.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_and_recv
# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import close [as 别名]
def send_and_recv(self):
try:
# because www.dream-pro.info is tlanslated to 127.0.0.1 using hosts' entry,
# send message to www.dream-pro.info with socket.socket to make
# http connection
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect((WWW_DREAM_PRO_INFO,80))
sock.sendall(str(self))
except:
print 'SocketError'
return
res = HTTPResponse(sock)
res.begin()
res_body = res.read()
res.close()
if 'transfer-encoding' in res.msg:
# httplib.HTTPResponse automatically concatenate chunked response
# but do not delete 'transfer-encoding' header
# so the header must be deleted
res.msg.__delitem__('transfer-encoding')
compmeth = res.msg.getheader('content-encoding','').lower()
if compmeth and compmeth.find('identity') != 0 :
# response body is compressed with some method
offset = 0
if compmeth.find('gzip') != -1:
# if body is gziped, header offset value is 47
# if not, offset value is 0
# this server does not support sdch...
offset += 47
res_body = decompress(res_body,offset)
res.msg['content-encoding'] = 'identity'
return res, res_body
示例2: HTTPResponse
# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import close [as 别名]
self._proxy_sock.sendall(self.mitm_request(req))
# Parse response
h = HTTPResponse(self._proxy_sock)
h.begin()
# Get rid of the pesky header
del h.msg['Transfer-Encoding']
# Time to relay the message across
res = '%s %s %s\r\n' % (self.request_version, h.status, h.reason)
res += '%s\r\n' % h.msg
res += h.read()
# Let's close off the remote end
h.close()
self._proxy_sock.close()
# Relay the message
self.request.sendall(self.mitm_response(res))
def mitm_request(self, data):
for p in self.server._req_plugins:
data = p(self.server, self).do_request(data)
return data
def mitm_response(self, data):
for p in self.server._res_plugins:
data = p(self.server, self).do_response(data)
return data
示例3: do_COMMAND
# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import close [as 别名]
def do_COMMAND(self):
global allCache
global dumpToDisk
cacheHit = False
sendNotModifiesResponse = False
cacheurl = self.path
print cacheurl
# checking if we have a cache hit
if not ('?' in cacheurl) and (cacheurl in allCache):
#in all cache array add two more fields max-age and date,time when added, and check if the object is valid before
#making cachehit true
cacheHit = True
#------ code below uncomment
# if 'If-Modified-Since' in self.headers:
# last_modified_date = self.headers['If-Modified-Since']
# formatter_string = "%a, %d %b %Y %H:%M:%S %Z"
# in_req_modified_date = datetime.strptime(last_modified_date, formatter_string)
# #get the other date from cache
# in_cache_modified_date = allCache[cacheurl][3]
# if in_req_modified_date > in_cache_modified_date:
# #can be served from cache
sendNotModifiesResponse = False
# No cache hit, fetch from Internet
if not cacheHit:
# Is this an SSL tunnel?
if not self.is_connect:
try:
# Connect to destination
self._connect_to_host()
except Exception, e:
self.send_error(500, str(e))
return
# Extract path
# Build request
req = '%s %s %s\r\n' % (self.command, self.path, self.request_version)
# Add headers to the request
req += '%s\r\n' % self.headers
# Append message body if present to the request
if 'Content-Length' in self.headers:
req += self.rfile.read(int(self.headers['Content-Length']))
# Send it down the pipe!
self._proxy_sock.sendall(self.mitm_request(req))
# Parse response
h = HTTPResponse(self._proxy_sock)
h.begin()
# Get rid of the pesky header
del h.msg['Transfer-Encoding']
# Time to relay the message across
res = '%s %s %s\r\n' % (self.request_version, h.status, h.reason)
res += '%s\r\n' % h.msg
toWrite=h.read()
res += toWrite
# fetched an object from the Internet, need to add it to memory and dump it to disk
if not ("?" in cacheurl):
fileName=cacheFileName()
tempObject=CacheObject(cacheurl, h.getheaders(), h.status, h.reason, toWrite,fileName)
#
current_datetime = datetime.now()
#
allCache[cacheurl]=['memory', tempObject, fileName, current_datetime]
dumpToDisk.append(tempObject)
h.close()
self._proxy_sock.close()
开发者ID:aliraza0337,项目名称:ExtremeCache,代码行数:89,代码来源:proxy+(Punchabi+Meyer's+conflicted+copy+2015-07-13).py
示例4: str
# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import close [as 别名]
self.send_error(500, str(e))
return
request = "%s %s %s\r\n" % (self.command, self.path, self.request_version)
request += "%s\r\n" % self.headers
if "Content-Length" in self.headers:
request += self.rfile.read(int(self.headers["Content-Length"]))
self._pipe_socket.sendall(request)
http_response = HTTPResponse(self._pipe_socket)
http_response.begin()
response = "%s %s %s\r\n" % (self.request_version, http_response.status, http_response.reason)
response += "%s\r\n" % http_response.msg
response += http_response.read()
http_response.close()
self._pipe_socket.close()
try:
self.request.sendall(response)
except Exception, e:
print "ERROR request relay: ", e
def do_GET(self):
self.do_RELAY()
def do_POST(self):
self.do_RELAY()
def finish(self):
try: