<P>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)</P>
<P> </P>
<P>class ProxyHandler(BaseHTTPServer.BaseHTTPRequestHandler):</P>
<P> def do_CONNECT(self):<BR> # print self.raw_requestline <BR> # "CONNECT twitter.com:443 HTTP/1.1"<BR> self.sslhost = self.raw_requestline.split()[1]<BR> self.wfile.write(self.protocol_version + " 200 Connection established\r\n")<BR> self.wfile.write("Proxy-agent: qiuyingbo\r\n\r\n")<BR> import ssl<BR> self.rfile = pseudofile(ssl.wrap_socket(self.connection, None, CERTFILE, True))<BR> self.wfile = self.rfile<BR> self.handle_one_request()<BR></P>
<P> </P>
<P>class pseudofile():<BR> ''' SSL Pseudo File Object'''<BR> def __init__(self, sslobj):<BR> self.sslobj = sslobj<BR> self.closed = 0</P>
<P> </P>
<P> def read(self, size):<BR> chunks = []<BR> read = 0<BR> while read < size:<BR> data = self.sslobj.read(size-read)<BR> read += len(data)<BR> chunks.append(data)<BR> return ''.join(chunks)</P>
<P> </P>
<P> def readline(self):<BR> line = []<BR> while 1:<BR> char = self.sslobj.read(1)<BR> line.append(char)<BR> if char == "\n": return ''.join(line)</P>
<P> </P>
<P> def write(self, data):<BR> bytes = len(data)<BR> while bytes > 0:<BR> sent = self.sslobj.write(data)<BR> if sent == bytes:<BR> break # avoid copy<BR> data = data[sent:]<BR> bytes = bytes - sent</P>
<P><BR> def flush(self):<BR> pass<BR></P>
<P> close = flush</P>