3131
3232You can turn auto-decompression/auto-compression off with:
3333
34- >>> conf.contribs["http"]["auto_compression"] = True
34+ >>> conf.contribs["http"]["auto_compression"] = False
35+
36+ (Defaults to True)
3537"""
3638
3739# This file is a modified version of the former scapy_http plugin.
5961
6062try :
6163 import brotli
62- is_brotli_available = True
64+ _is_brotli_available = True
6365except ImportError :
64- is_brotli_available = False
65- log_loading .info ("Can't import brotli. Won't be able to decompress "
66- "data streams compressed with brotli." )
66+ _is_brotli_available = False
6767
6868if "http" not in conf .contribs :
6969 conf .contribs ["http" ] = {}
@@ -310,8 +310,14 @@ def post_dissect(self, s):
310310 elif "compress" in encodings :
311311 import lzw
312312 s = lzw .decompress (s )
313- elif "br" in encodings and is_brotli_available :
314- s = brotli .decompress (s )
313+ elif "br" in encodings :
314+ if _is_brotli_available :
315+ s = brotli .decompress (s )
316+ else :
317+ log_loading .info (
318+ "Can't import brotli. brotli decompression "
319+ "will be ignored !"
320+ )
315321 except Exception :
316322 # Cannot decompress - probably incomplete data
317323 pass
@@ -330,8 +336,14 @@ def post_build(self, pkt, pay):
330336 elif "compress" in encodings :
331337 import lzw
332338 pay = lzw .compress (pay )
333- elif "br" in encodings and is_brotli_available :
334- pay = brotli .compress (pay )
339+ elif "br" in encodings :
340+ if _is_brotli_available :
341+ pay = brotli .compress (pay )
342+ else :
343+ log_loading .info (
344+ "Can't import brotli. brotli compression will "
345+ "be ignored !"
346+ )
335347 return pkt + pay
336348
337349 def self_build (self , field_pos_list = None ):
@@ -569,7 +581,7 @@ def tcp_reassemble(cls, data, metadata):
569581 chunked = ("chunked" in encodings )
570582 is_response = isinstance (http_packet .payload , HTTPResponse )
571583 if chunked :
572- detect_end = lambda dat : dat .endswith (b"\r \n \r \n " )
584+ detect_end = lambda dat : dat .endswith (b"0 \r \n \r \n " )
573585 # HTTP Requests that do not have any content,
574586 # end with a double CRLF
575587 elif isinstance (http_packet .payload , HTTPRequest ):
0 commit comments