1616# USA
1717#
1818
19- import logging , re , string , random
19+ import logging , re , string , random , zlib , gzip , StringIO
2020
2121from twisted .web .http import HTTPClient
2222from URLMonitor import URLMonitor
@@ -40,6 +40,7 @@ def __init__(self, command, uri, postData, headers, client):
4040 self .client = client
4141 self .urlMonitor = URLMonitor .getInstance ()
4242 self .isImageRequest = False
43+ self .isCompressed = False
4344 self .contentLength = None
4445 self .shutdownComplete = False
4546
@@ -87,7 +88,11 @@ def handleHeader(self, key, value):
8788 self .isImageRequest = True
8889 logging .debug ("Response is image content, not scanning..." )
8990
90- if (key .lower () == 'content-length' ):
91+ if (key .lower () == 'content-encoding' ):
92+ if (value .find ('gzip' ) != - 1 ):
93+ logging .debug ("Response is compressed..." )
94+ self .isCompressed = True
95+ elif (key .lower () == 'content-length' ):
9196 self .contentLength = value
9297 elif (key .lower () == 'set-cookie' ):
9398 self .client .responseHeaders .addRawHeader (key , value )
@@ -114,6 +119,10 @@ def handleResponseEnd(self):
114119 HTTPClient .handleResponseEnd (self )
115120
116121 def handleResponse (self , data ):
122+ if (self .isCompressed ):
123+ logging .debug ("Decompressing content..." )
124+ data = gzip .GzipFile ('' , 'rb' , 9 , StringIO .StringIO (data )).read ()
125+
117126 logging .log (self .getLogLevel (), "Read from server:\n " + data )
118127
119128 data = self .replaceSecureLinks (data )
0 commit comments