fixed threading
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Fri, 8 Jan 2010 14:56:39 +0000 (14:56 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Fri, 8 Jan 2010 14:56:39 +0000 (14:56 +0000)
fixed socket.send (sendall)
option dump-lenght

sproxy

diff --git a/sproxy b/sproxy
index 3580560602169a080e07b8065b92dea02b0ddea6..e8c4e47287957ea59f77d5a2a0e70a946757d625 100755 (executable)
--- a/sproxy
+++ b/sproxy
@@ -173,7 +173,7 @@ class HttpBase:
             try:
                 new_raw_data = sock.recv(1500) # usual IP MTU, for speed
             except SSL.Error, err:
-                logging.debug('Error during sock.recv: %s', repr(err))
+                logging.debug('SSL.Error during sock.recv: %s', repr(err))
                 return # connection failure
             if not new_raw_data:
                 return # connection was closed
@@ -203,9 +203,9 @@ class HttpBase:
         Otherwise, it will produce a full absolute url
         """
         try:
-            sock.send(self.all_headers(abs_path=abs_path))
+            sock.sendall(self.all_headers(abs_path=abs_path))
             if self.data != '':
-                sock.send(self.data)
+                sock.sendall(self.data)
         except (socket.error, SSL.SysCallError), err:
             logging.error('Error during sock.send: %s', err.args[1])
             # do nothing
@@ -222,12 +222,11 @@ class HttpBase:
             else:
                 logging.debug('%s (NO VALUE)', repr(header[0]))
     def debug_dump_data(self):
-        DUMP_DATA_MAX_LEN = 160
         if self.data:
             data_length = len(self.data)
-            truncate = data_length > DUMP_DATA_MAX_LEN
+            truncate = data_length > options.dump_length
             if truncate:
-                printed_data = repr(self.data[:DUMP_DATA_MAX_LEN])+'...'
+                printed_data = repr(self.data[:options.dump_length])+'...'
             else:
                 printed_data = repr(self.data)
 
@@ -510,8 +509,8 @@ class ProxyConnectionIn(threading.Thread):
                 logging.info("%s %s %s %s %s", request_in.http_method, request_in.parsed_url.geturl(), request_in.http_version, response.line1[9:12], len(response.data) or '-')
 
             elif request_in.http_method == 'CONNECT':
-                HttpErrorResponse(200, 'Proceed', '\r\n').send_to(self.clientsocket)
-                #self.clientsocket.send('HTTP/1.1 200 Proceed\r\n\r\n')
+                #HttpErrorResponse(200, 'Proceed', '\r\n').send_to(self.clientsocket)
+                self.clientsocket.send('HTTP/1.1 200 Proceed\r\n\r\n\r\n')
 
                 ssl_context = SSL.Context(SSL.SSLv23_METHOD)
                 ssl_context.use_privatekey_file ('certs/proxy.key')
@@ -596,10 +595,11 @@ def main():
             logging.info('Ctrl+C received. Shutting down.')
             break
 
+        logging.debug('thread count: %s', threading.activeCount())
         if options.debug_connections:
             logging.debug('Connection from %s', format_ip_port(*address))
         cnx_thread = ProxyConnectionIn(clientsocket)
-        cnx_thread .run()
+        cnx_thread.start()
 
 
 if __name__ == '__main__':
@@ -642,6 +642,10 @@ if __name__ == '__main__':
         action='store_true', dest='debug_length', default=False,
         help="dump lengthes information")
     
+    parser.add_option('--dump-length',
+        action='store', type='int', dest='dump_length', default=160,
+        help="length of data dump")
+    
 
     options, args = parser.parse_args()
     main(*args)