[IronPython] ssl server mode issue
qiuyingbo at sohu.com
qiuyingbo at sohu.com
Thu Apr 15 02:40:47 CEST 2010
I'm doing a web browser to ironpython connection. It is difficult to explain what I am doing, I'm hacking a http proxy that inherit BaseHTTPServer.BaseHTTPRequestHandler. Next code snippets show how I support HTTPS proxy.. (Linux version run well)
class ProxyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_CONNECT(self): # print self.raw_requestline # "CONNECT twitter.com:443 HTTP/1.1" self.sslhost = self.raw_requestline.split()[1] self.wfile.write(self.protocol_version + " 200 Connection established\r\n") self.wfile.write("Proxy-agent: qiuyingbo\r\n\r\n") import ssl self.rfile = pseudofile(ssl.wrap_socket(self.connection, None, CERTFILE, True)) self.wfile = self.rfile self.handle_one_request()
class pseudofile(): ''' SSL Pseudo File Object''' def __init__(self, sslobj): self.sslobj = sslobj self.closed = 0
def read(self, size): chunks = [] read = 0 while read < size: data = self.sslobj.read(size-read) read += len(data) chunks.append(data) return ''.join(chunks)
def readline(self): line = [] while 1: char = self.sslobj.read(1) line.append(char) if char == "\n": return ''.join(line)
def write(self, data): bytes = len(data) while bytes > 0: sent = self.sslobj.write(data) if sent == bytes: break # avoid copy data = data[sent:] bytes = bytes - sent
def flush(self): pass
close = flush
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100415/7b0b4b83/attachment.html>
More information about the Ironpython-users
mailing list