Web client through https proxy - is it even possible?

Matt Pruden <[email protected]>
Newsgroups gmane.comp.python.twisted.web
Message-ID <[email protected]>
I'm trying to post some data to a web server, but need to go through
an https proxy.  I can't seem to find anyone that's pulled this off
with a twisted web client.   I've been sniffing traffic and have it
close, but can't quite get past creating the SSL socket.  Anything I
attempt to write to the transport after swapping out the standard
socket for SSL.Connection fails the SSL handshake on the remote end.

Here's the code so far:
class MyProtocol(client.HTTPPageGetter):

    got_connect = False

    def connectionMade(self):
        proxy = os.environ.get('https_proxy')
        if proxy:
            self.transport.write('CONNECT %s:%s HTTP/1.0\r\n' %
(self.factory.host, self.factory.port))
            self.sendHeader('Host', self.factory.headers.get("host",
self.factory.host))
            self.sendHeader('User-Agent', self.factory.agent)
            self.transport.write('\r\n')
        else:
            self.got_connect = True

        if self.got_connect:
            client.HTTPPageGetter.connectionMade(self)

    def lineReceived(self, line):
        if not self.got_connect:
            self.got_connect == True
            ctx = ssl.ClientContextFactory()
            self.transport.stopReading()
            self.transport.stopWriting()
            self.transport.socket = SSL.Connection(ctx.getContext(),
                                                self.transport.socket)
            self.transport.fileno = self.transport.socket.fileno
            self.transport.startReading()
            client.HTTPPageGetter.connectionMade(self)
        else:
            client.HTTPPageGetter.lineReceived(self, line)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.