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
_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to