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


Python HTTPResponse.getheaders方法代码示例

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


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

示例1: parseNewResponse

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [as 别名]
 def parseNewResponse(self, packetString, src, dst, tcp):
     responseCode = packetString[9:12]
     if responseCode == '200': # just okay responses for now        
         if '\r\n\r\n' in packetString: # only proceed if the response has a body
             bodyIndex = packetString.index('\r\n\r\n') + 4
             body = packetString[bodyIndex:]
             socket = FakeSocket(packetString)
             response = HTTPResponse(socket)
             response.begin()
             headerArray = response.getheaders()
             for item in headerArray:
                 flowKey = (src, dst)
                 if item[0] == 'content-type' and 'text/html' in item[1]: # accept any kind of text content
                     print headerArray
                     for item in headerArray:
                         if item[0] == 'content-length':
                             print 'found fixed length'
                             length = int(item[1])
                             if length is not 0:
                                 self.parseFixedLengthResponse(flowKey, body, length, src, dst, tcp, responseCode)
                             else:
                                 print "warning, content-length is zero!"
                         elif item[0] == 'transfer-encoding' and item[1] == 'chunked':
                             print 'found chunked'
                             self.parseChunkedResponse(flowKey, body, src, dst, tcp, responseCode)
         else:
             print "body not found"
开发者ID:sidechained,项目名称:Amalgam,代码行数:29,代码来源:packet-analyser.py

示例2: do_proxy

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [as 别名]
 def do_proxy(self):
     try:
         if self.s == 0:
             self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             self.s.connect((proxy_host, proxy_port))
         self.s.send(self.requestline.encode('ascii') + b'\r\n')
         # Add Sogou Verification Tags
         self.headers['X-Sogou-Auth'] = x_sogou_auth
         t = hex(int(time.time()))[2:].rstrip('L').zfill(8)
         self.headers['X-Sogou-Tag'] = calc_sogou_hash(t, self.headers['Host'])
         self.headers['X-Sogou-Timestamp'] = t
         self.s.send(str(self.headers).encode('ascii') + b'\r\n')
         # Send Post data
         if(self.command=='POST'):
             self.s.send(self.rfile.read(int(self.headers['Content-Length'])))
         response = HTTPResponse(self.s, method=self.command, buffering=True)
         response.begin()
         # Reply to the browser
         status = 'HTTP/1.1 ' + str(response.status) + ' ' + response.reason
         self.wfile.write(status.encode('ascii') + b'\r\n')
         h = ''
         for hh, vv in response.getheaders():
             if hh.upper()!='TRANSFER-ENCODING':
                 h += hh + ': ' + vv + '\r\n'
         self.wfile.write(h.encode('ascii') + b'\r\n')
         while True:
             response_data = response.read(8192)
             if(len(response_data) == 0):
                 break
             self.wfile.write(response_data)
     except socket.error:
         print('socket error for ' + self.requestline)
开发者ID:kinhung,项目名称:sogou-proxy,代码行数:34,代码来源:proxy.py

示例3: issue_row

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [as 别名]
def issue_row(raw_row):
    issue_row = {}
    for column in COLUMN_HEADERS:
        column_data_raw = raw_row.findtext(column)
        if column_data_raw:
            if column in ["issueDetail", "issueBackground", "remediationBackground"]:
                issue_row[column] = htmltext(column_data_raw)
            else:
                issue_row[column] = column_data_raw

            if len(issue_row[column]) > 32000:
                issue_row[column] = "".join(issue_row[column][:32000], " [Text Cut Due To Length]")

    request = raw_row.findtext("./requestresponse/request")
    if request:
        parsed_request = HTTPRequest(binascii.a2b_base64(request))
        formatted_request_a = "command : {}\nuri : {}\nrequest_version : {}".format(
            parsed_request.command, parsed_request.path, parsed_request.request_version
        )
        formatted_request_b = "\n".join(
            "{}: {}".format(header, parsed_request.headers[header]) for header in parsed_request.headers.keys()
        )
        issue_row["requestHeaders"] = "{}\n{}".format(formatted_request_a, formatted_request_b)

    response = raw_row.findtext("./requestresponse/response")
    if response:
        parsed_response = HTTPResponse(FakeSocket(binascii.a2b_base64(response)))
        parsed_response.begin()
        formatted_response = "\n".join(
            ["{} : {}".format(header_item[0], header_item[1]) for header_item in parsed_response.getheaders()]
        )
        issue_row["responseHeaders"] = formatted_response

    return issue_row
开发者ID:CyberLight,项目名称:discover,代码行数:36,代码来源:parse-burp.py

示例4: process_record

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [as 别名]
    def process_record(self, record):
        content = None
        try:
            payload = record.payload.read()
            s = FakeSocket(payload)
            response = HTTPResponse(s)
            response.begin()
            status_code = response.status
            if status_code != 200:
                return
            content_type = response.getheader('Content-Type', '')
            if 'text/html' not in content_type:
                return

            headers = response.getheaders()
            content = response.read(len(payload))
        except Exception:
            self.increment_counter('errors', 'process_record', 1)
            logging.error('Error processing record: {}', traceback.format_exc())
            return

        if content is not None:
            content = content.strip()

        if not content:
            return

        for item in self.process_content(record.url, headers, content):
            yield item
开发者ID:openvenues,项目名称:common_crawl,代码行数:31,代码来源:base.py

示例5: getheaders

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [as 别名]
    def getheaders(self):
        """Return all headers from the response

        This gives the ability to access all HTTP headers of a discovery response.

        :return: dict[str, str]
        """
        return HTTPResponse.getheaders(self)
开发者ID:LarsMichelsen,项目名称:pmatic,代码行数:10,代码来源:discover.py

示例6: __init__

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [as 别名]
    def __init__(self, response_text):
        self.fp = FakeSocket(response_text)
        res = HTTPR(self.fp)
        res.begin()

        headers = res.getheaders()
        for header in headers:
            self.headers[header[0]] = header[1]

        self.length = res.getheader('Content-Length')
        self.chunked = res.getheader('Transfer-Encoding')
开发者ID:jseidl,项目名称:bifrost,代码行数:13,代码来源:bifrost.py

示例7: proccessHttpResponse

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [as 别名]
 def proccessHttpResponse(self, burpHttpReqResp):
     """ Processes only the HTTP repsonses with a CSP header """
     byteResponse = burpHttpReqResp.getResponse()
     httpSocket = HttpDummySocket(bytearray(byteResponse))
     response = HTTPResponse(httpSocket)
     response.begin()
     issues = []
     for header in response.getheaders():
         if header[0].lower() in ContentSecurityPolicy.HEADERS:
             findings = self.parseContentSecurityPolicy(header, burpHttpReqResp)
             issues.extend(findings)
     return issues
开发者ID:echodaemon,项目名称:CSP-Bypass,代码行数:14,代码来源:burp_csp_bypass.py

示例8: parse_response

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [as 别名]
def parse_response(response_text):
    """
        Given an HTTP response line and headers, return a requests.Response object.
    """
    class FakeSocket():
        def __init__(self, response_str):
            self._file = StringIO(response_str)

        def makefile(self, *args, **kwargs):
            return self._file

    source = FakeSocket(response_text)
    response = HTTPResponse(source)
    response.begin()
    requests_response = requests.Response()
    requests_response.status_code = response.status
    requests_response.headers = CaseInsensitiveDict(response.getheaders())
    return requests_response
开发者ID:thatandromeda,项目名称:perma,代码行数:20,代码来源:tasks.py

示例9: run

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [as 别名]
    def run(self):
        try:
            remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            remote.connect((self.ip, int(port)))
            remote.send(self.clientSendData)
            response = HTTPResponse(remote)
            response.begin()
            for hh, vv in response.getheaders():
                if hh.upper()!='TRANSFER-ENCODING':
                    self.clientRecvData += hh + ': ' + vv + '\r\n'

            self.clientRecvData += "\r\n"
            self.status = response.status
            print (self.ip + " response: %d"%(response.status))
            while True:
                d = remote.recv(MAX_RECV)
                if (len(d)==0): break
                self.clientRecvData += d
            
        except:
            exc_type, self.error, exc_traceback = sys.exc_info()
            print (self.ip+":"+self.port + " error: " , exc_type , self.error)
            sys.stdout.flush()
开发者ID:11liju,项目名称:west-chamber-season-3,代码行数:25,代码来源:multi-thread-socket.py

示例10: proxy

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [as 别名]

#.........这里部分代码省略.........
                    path = "/"
                print " ".join((self.command, path, self.request_version)) + "\r\n"
                self.remote.send(" ".join((self.command, path, self.request_version)) + "\r\n")
                # Send headers
                self.remote.send(str(self.headers) + "\r\n")
                # Send Post data
                if(self.command=='POST'):
                    self.remote.send(self.rfile.read(int(self.headers['Content-Length'])))
                response = HTTPResponse(self.remote, method=self.command)
                badStatusLine = False
                msg = "http405"
                try :
                    response.begin()
                    print host + " response: %d"%(response.status)
                    msg = "http%d"%(response.status)
                except BadStatusLine:
                    print host + " response: BadStatusLine"
                    msg = "badStatusLine"
                    badStatusLine = True
                except:
                    raise

                if doInject and (response.status == 400 or response.status == 405 or badStatusLine) and host != gConfig["PROXY_SERVER_SIMPLE"]:
                    self.remote.close()
                    self.remote = None
                    domainWhiteList.append(host)
                    errpath = (msg + "/host/" + host)
                    continue
                break
            # Reply to the browser
            status = "HTTP/1.1 " + str(response.status) + " " + response.reason
            self.wfile.write(status + "\r\n")
            h = ''
            for hh, vv in response.getheaders():
                if hh.upper()!='TRANSFER-ENCODING':
                    h += hh + ': ' + vv + '\r\n'
            self.wfile.write(h + "\r\n")

            dataLength = 0
            while True:
                response_data = response.read(8192)
                if(len(response_data) == 0): break
                if dataLength == 0 and (len(response_data) <= 320):
                    if response_data.find("<title>400 Bad Request") != -1 or response_data.find("<title>501 Method Not Implemented") != -1:
                        print host + " not supporting injection"
                        domainWhiteList.append(host)
                        response_data = gConfig["PAGE_RELOAD_HTML"]
                self.wfile.write(response_data)
                dataLength += len(response_data)
                if gOptions.log > 1: print "data length: %d"%dataLength
            self.wfile.close()
        except:
            if self.remote:
                self.remote.close()
                self.remote = None

            exc_type, exc_value, exc_traceback = sys.exc_info()
             

            if exc_type == socket.error:
                code, msg = str(exc_value).split('] ')
                code = code[1:].split(' ')[1]
                if code in ["32", "10053"]: #errno.EPIPE, 10053 is for Windows
                    if gOptions.log > 0: print "Detected remote disconnect: " + host
                    self.wfile.close()
                    return
开发者ID:dragonov,项目名称:west-chamber-season-3,代码行数:70,代码来源:westchamberproxy.py

示例11: proxy

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [as 别名]

#.........这里部分代码省略.........
                    doInject = self.enableInjection(host, connectHost)
                
                self.remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                if gOptions.log > 1: print "connect to " + host + ":" + str(port)
                self.remote.connect((connectHost, port))
                if doInject: 
                    if gOptions.log > 0: print "inject http for "+host
                    self.remote.send("\r\n\r\n")
                # Send requestline
                if path == "":
                    path = "/"
                print " ".join((self.command, path, self.request_version)) + "\r\n"
                self.remote.send(" ".join((self.command, path, self.request_version)) + "\r\n")
                # Send headers
                if host[-12:] == ".appspot.com":
                    print "add version code " + gConfig["VERSION"] + " in HTTP header"
                    self.headers["X-WCProxy"] = gConfig["VERSION"]
                    self.headers["X-WCPasswd"] = gConfig["PROXY_PASSWD"]
                self.remote.send(str(self.headers) + "\r\n")
                # Send Post data
                if(self.command=='POST'):
                    self.remote.send(self.rfile.read(int(self.headers['Content-Length'])))
                response = HTTPResponse(self.remote, method=self.command)
                badStatusLine = False
                msg = "http405"
                try :
                    response.begin()
                    print host + " response: %d"%(response.status)
                    msg = "http%d"%(response.status)
                except BadStatusLine:
                    print host + " response: BadStatusLine"
                    msg = "badStatusLine"
                    badStatusLine = True
                except:
                    raise

                if doInject and (response.status == 400 or response.status == 405 or badStatusLine):
                    self.remote.close()
                    self.remote = None
                    if gOptions.log > 0: print host + " seem not support inject, " + msg
                    domainWhiteList.append(host)
                    return self.do_METHOD_Tunnel()

            # Reply to the browser
            status = "HTTP/1.1 " + str(response.status) + " " + response.reason
            self.wfile.write(status + "\r\n")
            h = ''
            for hh, vv in response.getheaders():
                if hh.upper()!='TRANSFER-ENCODING':
                    h += hh + ': ' + vv + '\r\n'
            self.wfile.write(h + "\r\n")

            dataLength = 0
            while True:
                response_data = response.read(8192)
                if(len(response_data) == 0): break
                if dataLength == 0 and (len(response_data) <= 501):
                    if response_data.find("<title>400 Bad Request") != -1 or response_data.find("<title>501 Method Not Implemented") != -1:
                        print host + " not supporting injection"
                        domainWhiteList.append(host)
                        response_data = gConfig["PAGE_RELOAD_HTML"]
                self.wfile.write(response_data)
                dataLength += len(response_data)
                if gOptions.log > 1: print "data length: %d"%dataLength
        except:
            if self.remote:
                self.remote.close()
                self.remote = None

            (scm, netloc, path, params, query, _) = urlparse.urlparse(self.path)
            status = "HTTP/1.1 302 Found"
            if host in gConfig["HSTS_ON_EXCEPTION_DOMAINS"]:
                redirectUrl = "https://" + self.path[7:]
                self.wfile.write(status + "\r\n")
                self.wfile.write("Location: " + redirectUrl + "\r\n")

            exc_type, exc_value, exc_traceback = sys.exc_info()

            if exc_type == socket.error:
                code, msg = str(exc_value).split('] ')
                code = code[1:].split(' ')[1]
                if code in ["32", "10053"]: #errno.EPIPE, 10053 is for Windows
                    if gOptions.log > 0: print "Detected remote disconnect: " + host
                    return
                if code in ["61"]: #server not support injection
                    if doInject:
                        print "try not inject " + host
                        domainWhiteList.append(host)
                        self.do_METHOD_Tunnel()
                        return
 
            print "error in proxy: ", self.requestline
            print exc_type
            print str(exc_value) + " " + host
            if exc_type == socket.timeout or (exc_type == socket.error and code in ["60", "110", "10060"]): #timed out, 10060 is for Windows
                if not inWhileList:
                    if gOptions.log > 0: print "add "+host+" to blocked domains"
                    gConfig["BLOCKED_DOMAINS"][host] = True

            return self.do_METHOD_Tunnel()
开发者ID:flf21,项目名称:west-chamber-season-3,代码行数:104,代码来源:westchamberproxy.py

示例12: proxy

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [as 别名]
    def proxy(self):
        doInject = False
        try:
            print self.requestline
            port = 80
            host = self.headers["Host"]
            if host.find(":") != -1:
                port = int(host.split(":")[1])
                host = host.split(":")[0]

            redirectUrl = self.path
            while True:
                (scm, netloc, path, params, query, _) = urlparse.urlparse(redirectUrl)

                if (netloc not in gConfig["REDIRECT_DOMAINS"]):
                    break
                prefixes = gConfig["REDIRECT_DOMAINS"][netloc].split('|')
                found = False
                for prefix in prefixes:
                    prefix = prefix + "="
                    for param in query.split('&') :
                        if param.find(prefix) == 0:
                            print "redirect to " + urllib.unquote(param[len(prefix):])
                            redirectUrl = urllib.unquote(param[len(prefix):])
                            found = True
                            continue 
                if not found:
                    break
            #redirect 
            if (redirectUrl != self.path):
                status = "HTTP/1.1 302 Found"
                self.wfile.write(status + "\r\n")
                self.wfile.write("Location: " + redirectUrl + "\r\n")
                self.connection.close()
                return
            # Remove http://[host]
            path = self.path[self.path.find(netloc) + len(netloc):]
            connectHost = self.getip(host)
            
            self.lastHost = self.headers["Host"]

            while True:
                doInject = self.enableInjection(host, connectHost)
                if self.remote is None or self.lastHost != self.headers["Host"]:
                    self.remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                    print "connect to " + host + ":" + str(port)
                    self.remote.connect((connectHost, port))
                    if doInject: 
                        self.remote.send("\r\n\r\n")
                # Send requestline
                self.remote.send(" ".join((self.command, (doInject and [path] or [self.path])[0], self.request_version)) + "\r\n")
                # Send headers
                self.remote.send(str(self.headers) + "\r\n")
                # Send Post data
                if(self.command=='POST'):
                    self.remote.send(self.rfile.read(int(self.headers['Content-Length'])))
                response = HTTPResponse(self.remote, method=self.command)
                badStatusLine = False
                msg = "http405"
                try :
                    response.begin()
                    print host + " response: %d"%(response.status)
                    msg = "http%d"%(response.status)
                except BadStatusLine:
                    print host + " response: BadStatusLine"
                    msg = "badStatusLine"
                    badStatusLine = True

                if doInject and (response.status == 400 or response.status == 405 or badStatusLine):
                    self.remote.close()
                    self.remote = None
                    domainWhiteList.append(host)
                    self.netlog(msg + "/host/" + host)
                    continue
                break
            # Reply to the browser
            status = "HTTP/1.1 " + str(response.status) + " " + response.reason
            self.wfile.write(status + "\r\n")
            h = ''
            for hh, vv in response.getheaders():
                if hh.upper()!='TRANSFER-ENCODING':
                    h += hh + ': ' + vv + '\r\n'
            self.wfile.write(h + "\r\n")
            while True:
                response_data = response.read(8192)
                if(len(response_data) == 0): break
                self.wfile.write(response_data)
        except:
            if self.remote:
                self.remote.close()
                self.remote = None

            exc_type, exc_value, exc_traceback = sys.exc_info()
            print "error in proxy: ", self.requestline
            print exc_type
            print str(exc_value) + " " + host
            path = ""
            if exc_type == socket.error:
                code, msg = str(exc_value).split('] ')
                code = code[1:].replace(" ", "")
#.........这里部分代码省略.........
开发者ID:hifoxwei,项目名称:west-chamber-season-3,代码行数:103,代码来源:westchamberproxy.py

示例13: HTTPResponse

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [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
			content_received = h.read()
			res += content_received
			#log the size
			logger_4.info('OBJECT : ' + str(len(res)) )
			try:
				HTTPObject_received = controller.HTTPObject(h.getheaders(), url_requested , content_received, h.status, h.reason, self.request_version, webpage, phase, self.rtt) # TODO replace the 100 with RTT
				controller.createObject(HTTPObject_received)
			except Exception,e: 
				print str(e)

			self.request.sendall(self.mitm_response(res))

		except SocketError as e:
			if e.errno != errno.ECONNRESET:
				raise
			pass
		# Let's close off the remote end
		if h != None:
			h.close()
		self._proxy_sock.close()
开发者ID:aliraza0337,项目名称:Xcache,代码行数:32,代码来源:CloudController.py

示例14: proxy

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [as 别名]
    def proxy(self):
        doProxy = False
        inWhileList = False
        logging.info (self.requestline)
        port = 80
        host = self.headers["Host"]
        
        if host.find(":") != -1:
            port = int(host.split(":")[1])
            host = host.split(":")[0]
        (scm, netloc, path, params, query, _) = urlparse.urlparse(self.path)

        if host in ["127.0.0.1", "localhost"]:
            basedir = os.path.dirname(__file__)
            htmlTemplate = os.path.join(basedir, "index.html")
            htmlFile = open(htmlTemplate)
            html = htmlFile.read()
            htmlFile.close()
            status = "HTTP/1.1 200 OK"
            if path == "/save":
                postData = self.rfile.read(int(self.headers['Content-Length']))
                data = urlparse.parse_qs(postData)
                logging.info(str(data))
                key = data["id"][0]
                value = data["value"][0]
                if key in gConfig:
                    if type(gConfig[key]) == type(True):
                        if value == "true": gConfig[key] = True
                        if value == "false": gConfig[key] = False
                    else: 
                        gConfig[key] = type(gConfig[key]) (value)
                self.wfile.write(status + "\r\n\r\n" + value)
                return
            if path == "/add":
                postData = self.rfile.read(int(self.headers['Content-Length']))
                data = urlparse.parse_qs(postData)
                if "BLOCKED_DOMAINS" in data:
                    domain = data["BLOCKED_DOMAINS"][0]
                    if domain[:4] == "http":
                        (scm, netloc, path, params, query, _) = urlparse.urlparse(domain)
                        domain = netloc
                    gConfig["BLOCKED_DOMAINS"][domain] = True
                    
                self.wfile.write("HTTP/1.1 302 FOUND\r\n" + "Location: /\r\n\r\n" + domain)
                return
            #TODO: pac
            for key in gConfig:
                if type(gConfig[key]) in [str,int] :
                    html = html.replace("{"+key+"}", str(gConfig[key]))
                else :
                    html = html.replace("{" + key + "}", str(gConfig[key]))
            self.wfile.write(status + "\r\n\r\n" + html)
            return
        try:
            
            if (gConfig["ADSHOSTON"] and host in gConfig["ADSHOST"]):
                status = "HTTP/1.1 404 Not Found"
                self.wfile.write(status + "\r\n\r\n")
                return

            # Remove http://[host] , for google.com.hk
            path = self.path[self.path.find(netloc) + len(netloc):]

            connectHost = self.getip(host)
            logging.info ("Resolved " + host + " => " + connectHost)

            if isDomainBlocked(host) or isIpBlocked(connectHost):
                self.remote = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
                logging.info("connect to " + host + ":" + str(port) + " var socks5 proxy")
                self.remote.connect((connectHost, port))
                doProxy = True
            else:
                self.remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                logging.debug( "connect to " + host + ":" + str(port))
                self.remote.connect((connectHost, port))

            # Send requestline
            if path == "":
                path = "/"
            print " ".join((self.command, path, self.request_version)) + "\r\n"
            self.remote.send(" ".join((self.command, path, self.request_version)) + "\r\n")
                
            self.remote.send(str(self.headers) + "\r\n")
            # Send Post data
            if(self.command=='POST'):
                self.remote.send(self.rfile.read(int(self.headers['Content-Length'])))
            response = HTTPResponse(self.remote, method=self.command)
            response.begin()
            print host + " response: %d"%(response.status)

            # Reply to the browser
            status = "HTTP/1.1 " + str(response.status) + " " + response.reason
            self.wfile.write(status + "\r\n")
            h = ''
            for hh, vv in response.getheaders():
                if hh.upper()!='TRANSFER-ENCODING':
                    h += hh + ': ' + vv + '\r\n'
            self.wfile.write(h + "\r\n")

            dataLength = 0
#.........这里部分代码省略.........
开发者ID:447327642,项目名称:west-chamber-season-3,代码行数:103,代码来源:westchamberproxy.py

示例15: HTTPResponse

# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import getheaders [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
            content_received = h.read()
            res += content_received

            HTTPObject_received = controller.HTTPObject(h.getheaders(), url_requested , content_received, h.status)
            controller.createObject(HTTPObject_received)

            # Relay the message
            self.request.sendall(self.mitm_response(res))

        except SocketError as e:
            if e.errno != errno.ECONNRESET:
                raise
            pass

        # Let's close off the remote end
        if h != None:
            h.close()
        self._proxy_sock.close()
开发者ID:aliraza0337,项目名称:ExtremeCache,代码行数:32,代码来源:proxy.py


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