Post Reply 
ProxHTTPSProxy, a Proxomitron SSL Helper Program
May. 20, 2010, 03:19 AM
Post: #8
RE: ProxHTTPSProxy, a Proxomitron SSL Helper Program
(May. 19, 2010 09:26 PM)Graycode Wrote:  I think for example AJAX may allow a POST having zero content

Thanks. Now it is:
Code:
post_data = self.rfile.read(post_data_len) if post_data_len > 0 else ''

(May. 19, 2010 09:26 PM)Graycode Wrote:  
Code:
self.send_response(200)
I'm lost there. What if the server's response code was not 200? For example a 304 is very common.

Python's urllib2 module handles redirections, cookies and many other things so I assume it will finally fetch the content.

If not for example 304 it will raise an Exception, which will be caught in my try statement and the response code will be passed to the browser.

(May. 19, 2010 09:26 PM)Graycode Wrote:  Also unclear whether that's a HTTP/1.0 or 1.1 response, but maybe connection persistence is not a factor in what you're using this for.

To keep things simple, I am adding "Connection: close" to each request.
Code:
req.add_header("Connection", "close")

(May. 19, 2010 09:26 PM)Graycode Wrote:  
Code:
if keyword.lower() in ('transfer-encoding',):
    #print '%s: %s removed' % (keyword, value)
    continue
Dropping the Transfer-Encoding header seems odd, apparently Python already accounted for chunked data but not for gzip, deflate, etc? I'm not sure if any consideration for Content-Encoding is desired in that situation.

Yes, urllib2 handles chunked data but won't touch gzip, deflate etc. That's why I dropped Transfer-Encoding header while keep Content-Encoding header.

(May. 19, 2010 09:26 PM)Graycode Wrote:  
Code:
def do_CONNECT(self):
        host_port = self.path
I don't see how the Python proxy would know the requested path. The SSL CONNECT method normally just has '/' even if the browser wanted '/something/other.htm'. It looks to my non-Python eyes that the 307 redirection would always send the browser to the root of the SSL host and not to the location that was wanted.

As the statement itself explained, I get only "host_port" from "self.path".

I am reading the requested path from the following http request in the SSL tunnel:
Code:
# Read 512 bytes to extract url path
# Will it cause issue not reading all data?
path = ssl_sock.recv(512).split(None, 2)[1]

From your point of view, will it cause issue not reading all data from the socket?

(May. 19, 2010 09:26 PM)Graycode Wrote:  
Code:
resp = 'HTTP/1.1 307 Moved Temporarily\r\nLocation: http://%s%s\r\n\r\n' % (host_port, path)
        ssl_sock.send(resp)
        ssl_sock.close()
The response is HTTP/1.1 so Proxo should assume persistence, but then its socket gets quickly closed.
Consider adding 'Connection: Close\r\n' to that, and maybe also 'Content-Length: 0\r\n'.

Thanks. Now I understand why sidki's config was adding 'Content-Length: 0' to my response. Where are you sidki? Come back please ...

Now it is:
Code:
resp = ('HTTP/1.1 307 Moved Temporarily\r\n',
                'Location: http://%s%s\r\n' % (host_port, path),
                'Connection: Close\r\n',
                'Content-Length: 0\r\n',
                '\r\n')
        ssl_sock.send(''.join(resp))
Add Thank You Quote this message in a reply
Post Reply 


Messages In This Thread
RE: ProxHTTPSProxy, a Proxomitron SSL Helper Program - whenever - May. 20, 2010 03:19 AM

Forum Jump: