本文整理汇总了Python中twisted.web.proxy.ProxyClient.handleHeader方法的典型用法代码示例。如果您正苦于以下问题:Python ProxyClient.handleHeader方法的具体用法?Python ProxyClient.handleHeader怎么用?Python ProxyClient.handleHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.proxy.ProxyClient
的用法示例。
在下文中一共展示了ProxyClient.handleHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handleHeader
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleHeader(self, key, value):
if key == "Content-Type" and value in ["image/jpeg", "image/gif", "image/png"]:
self.image_parser = Parser()
if key == "Content-Length" and self.image_parser:
pass
else:
ProxyClient.handleHeader(self, key, value)
示例2: handleResponseEnd
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleResponseEnd(self):
if self.image_parser:
print "imageparsing ", compress_rate
try:
image = self.image_parser.close()
except IOError as (error):
print "I/O error: ", error
print self.image_parser
try:
# do the compression
format = image.format
newsize = int(image.size[0] * compress_rate) , int(image.size[1] * compress_rate)
image.thumbnail(newsize) # likely, image sizing like this does not work
s = StringIO()
image.save(s, format)
buffer = s.getvalue()
except NameError as (error):
print "in exception: ", error
# send Original C-length if just queryed for header
buffer = " " *(int(self.clength))
print "Header: Content-Lengths ", len(buffer)
ProxyClient.handleHeader(self, "Content-Length", len(buffer))
# all headers received and processed
ProxyClient.handleEndHeaders(self)
ProxyClient.handleResponsePart(self, buffer)
ProxyClient.handleResponseEnd(self)
示例3: handleResponseEnd
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleResponseEnd(self):
self._buffer = ''.join(self._buffer)
if self.replace: #if content replace is needed
if self.encoding == 'gzip':
try:
buffer1 = StringIO.StringIO(self._buffer)
gzipper = gzip.GzipFile(fileobj=buffer1)
html = gzipper.read()
except Exception, what:
print self.factory.realhost,what
html = self._buffer
elif self.encoding == 'deflate':
try:
html = zlib.decompress(self._buffer)
except zlib.error:
html = zlib.decompress(self._buffer, -zlib.MAX_WBITS)
else:
html = self._buffer
self._buffer = self.factory.rp.process(self.factory.host,self.ctype,html)
if self.reencode and ("flash" not in self.ctype):
newbuffer = StringIO.StringIO()
gzipper = gzip.GzipFile(fileobj=newbuffer,mode='wb')
gzipper.write(self._buffer)
gzipper.close()
self._buffer = newbuffer.getvalue()
self.headers_to_cache["Content-Encoding"]="gzip"
ProxyClient.handleHeader(self,"Content-Encoding","gzip")
self.headers_to_cache["Content-Length"]=len(self._buffer)
ProxyClient.handleHeader(self, "Content-Length", len(self._buffer))
ProxyClient.handleResponsePart(self,self._buffer)
示例4: handleHeader
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleHeader(self, key, value):
# change response header here
print("Header: %s: %s" % (key, value))
l = key.lower()
if l == "location":
key = "Postman-Location"
ProxyClient.handleHeader(self, key, value)
示例5: handleHeader
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleHeader(self, key, value):
log.msg("<<< %s: %s" % (key, value))
if key.lower() == "content-type":
if value.startswith("text/html"):
self.rewrite = True
ProxyClient.handleHeader(self, key, value)
elif key.lower() == "content-length":
self.length = value
else:
ProxyClient.handleHeader(self, key, value)
示例6: handleResponseEnd
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleResponseEnd(self):
log.msg("handleResponseEnd")
if self.rewrite:
banner2 = banner % dict(
height = self.config['height'],
bannerurl = self.config['bannerurl'],
)
buffer = self.buffer.replace("</head>", banner2)
ProxyClient.handleHeader(self, "Content-Length", str(len(buffer)))
ProxyClient.handleEndHeaders(self)
ProxyClient.handleResponsePart(self, buffer)
self.rewrite = False
ProxyClient.handleResponseEnd(self)
示例7: handleResponseEnd
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleResponseEnd(self):
if self.image_parser:
image = self.image_parser.close()
try:
format = image.format
image = image.rotate(180)
s = StringIO()
image.save(s, format)
buffer = s.getvalue()
except:
buffer = ""
ProxyClient.handleHeader(self, "Content-Length", len(buffer))
ProxyClient.handleEndHeaders(self)
ProxyClient.handleResponsePart(self, buffer)
ProxyClient.handleResponseEnd(self)
示例8: handleResponseEnd
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleResponseEnd(self):
if self.replacing is not None:
try:
buffer = open(self.replacing).read()
except:
buffer = ""
ProxyClient.handleHeader(self, "Content-Length", len(buffer))
ProxyClient.handleEndHeaders(self)
ProxyClient.handleResponsePart(self, buffer)
elif self.rewriting:
buffer = self._buf.replace('"id": "BIRD_RED"', '"id": "BIRD_BLACK"')
ProxyClient.handleHeader(self, "Content-Length", len(buffer))
ProxyClient.handleEndHeaders(self)
ProxyClient.handleResponsePart(self, buffer)
ProxyClient.handleResponseEnd(self)
示例9: handleHeader
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleHeader(self, key, value):
value = self.factory.rp.get_aliasheader(self.factory.host,value)
if DEBUG:
pass
#print key,value
if key == "Content-Type" and (value.startswith("text") or \
("java" in value) or ("flash" in value)):
self.replace = True
self.ctype = value
if key == "Content-Encoding":
self.encoding = value
return
if key == "Content-Length":
return
else:
self.headers_to_cache[key] = value
ProxyClient.handleHeader(self, key, value)
示例10: handleResponseEnd
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleResponseEnd(self):
if self.needsRewrite():
log.msg("Rewriting " + self.father.uri)
# We might have increased or decreased the page size. Since we have not written
# to the client yet, we can still modify the headers.
self.rewriteResponse()
self.header_buffer["content-length"] = len(self.buffer)
for key in self.header_buffer.keys():
ProxyClient.handleHeader(self, key, self.header_buffer[key])
ProxyClient.handleEndHeaders(self)
ProxyClient.handleResponsePart(self, self.buffer)
self.buffer = ""
self.header_buffer = {}
ProxyClient.handleResponseEnd(self)
示例11: handleHeader
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleHeader(self, key, value):
if key.lower() == 'location':
log.debug("Manage location header")
uri=urlparse(value)
value=uri.path
if len(uri.query) > 0:
value=value+"?"+uri.query
# value = self.proxymap.absoluteURLOf(value, self.host_header())
log.debug("HANDLE HEADER: "+str(key)+" "+str(value))
return ProxyClient.handleHeader(self, key, value)
示例12: handleHeader
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleHeader(self, key, value):
if key.lower() == "content-type":
if value in ["image/jpeg", "image/gif", "image/png"]:
self.image_parser = Parser()
self.ctype_received = True # content-type must be known before handling header
if self.clength != 0 and not self.image_parser:
# processes a content-length, if that was a prior header
print "Header: Content-Length ", self.clength
ProxyClient.handleHeader(self, "Content-Length", self.clength)
if key.lower() == "content-length":
print "Handling content-length"
if self.image_parser: # don't set content-length yet if an image-file.
print "CHeader1: ", key, " ", value
# LEAVES CONTENT-LENGTH UNSET!
elif self.ctype_received:
# a bit ugly. Just pass the header forward, if not an image c-length
print "CHeader2: ", key, " ", value
ProxyClient.handleHeader(self, key, value)
else:
# if content-type has not been processed yet
print "old-clength ", value
self.clength = value
else:
print "Header: ", key, " ", value
ProxyClient.handleHeader(self, key, value)
示例13: handleEndHeaders
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleEndHeaders(self):
if not self.rewrite:
if self.length:
ProxyClient.handleHeader(self, "Content-Length", self.length)
ProxyClient.handleEndHeaders(self)
示例14: handleHeader
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleHeader(self, key, value):
if key == "Content-Length" and (self.replacing or self.rewriting):
pass
else:
ProxyClient.handleHeader(self, key, value)
示例15: handleHeader
# 需要导入模块: from twisted.web.proxy import ProxyClient [as 别名]
# 或者: from twisted.web.proxy.ProxyClient import handleHeader [as 别名]
def handleHeader(self, key, val):
if self.needsRewrite():
self.header_buffer[key.lower()] = val
else:
ProxyClient.handleHeader(self, key, val)