Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: Tools/Scripts/webkitpy/thirdparty/mod_pywebsocket/extensions.py

Issue 314043002: [WebSocket] Add tests for permessage deflate split frames. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2012, Google Inc. 1 # Copyright 2012, Google Inc.
2 # All rights reserved. 2 # All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 _compression_extension_names.append(common.DEFLATE_FRAME_EXTENSION) 323 _compression_extension_names.append(common.DEFLATE_FRAME_EXTENSION)
324 324
325 _available_processors[common.X_WEBKIT_DEFLATE_FRAME_EXTENSION] = ( 325 _available_processors[common.X_WEBKIT_DEFLATE_FRAME_EXTENSION] = (
326 DeflateFrameExtensionProcessor) 326 DeflateFrameExtensionProcessor)
327 _compression_extension_names.append(common.X_WEBKIT_DEFLATE_FRAME_EXTENSION) 327 _compression_extension_names.append(common.X_WEBKIT_DEFLATE_FRAME_EXTENSION)
328 328
329 329
330 def _parse_compression_method(data): 330 def _parse_compression_method(data):
331 """Parses the value of "method" extension parameter.""" 331 """Parses the value of "method" extension parameter."""
332 332
333 return common.parse_extensions(data, allow_quoted_string=True) 333 return common.parse_extensions(data)
334 334
335 335
336 def _create_accepted_method_desc(method_name, method_params): 336 def _create_accepted_method_desc(method_name, method_params):
337 """Creates accepted-method-desc from given method name and parameters""" 337 """Creates accepted-method-desc from given method name and parameters"""
338 338
339 extension = common.ExtensionParameter(method_name) 339 extension = common.ExtensionParameter(method_name)
340 for name, value in method_params: 340 for name, value in method_params:
341 extension.add_parameter(name, value) 341 extension.add_parameter(name, value)
342 return common.format_extension(extension) 342 return common.format_extension(extension)
343 343
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 return 414 return
415 self._compression_processor.setup_stream_options(stream_options) 415 self._compression_processor.setup_stream_options(stream_options)
416 416
417 def set_compression_processor_hook(self, hook): 417 def set_compression_processor_hook(self, hook):
418 self._compression_processor_hook = hook 418 self._compression_processor_hook = hook
419 419
420 def get_compression_processor(self): 420 def get_compression_processor(self):
421 return self._compression_processor 421 return self._compression_processor
422 422
423 423
424 class PerFrameCompressExtensionProcessor(CompressionExtensionProcessorBase):
425 """perframe-compress processor.
426
427 Specification:
428 http://tools.ietf.org/html/draft-ietf-hybi-websocket-perframe-compression
429 """
430
431 _DEFLATE_METHOD = 'deflate'
432
433 def __init__(self, request):
434 CompressionExtensionProcessorBase.__init__(self, request)
435
436 def name(self):
437 return common.PERFRAME_COMPRESSION_EXTENSION
438
439 def _lookup_compression_processor(self, method_desc):
440 if method_desc.name() == self._DEFLATE_METHOD:
441 return DeflateFrameExtensionProcessor(method_desc)
442 return None
443
444
445 _available_processors[common.PERFRAME_COMPRESSION_EXTENSION] = (
446 PerFrameCompressExtensionProcessor)
447 _compression_extension_names.append(common.PERFRAME_COMPRESSION_EXTENSION)
448
449
450 class PerMessageDeflateExtensionProcessor(ExtensionProcessorInterface): 424 class PerMessageDeflateExtensionProcessor(ExtensionProcessorInterface):
451 """permessage-deflate extension processor. It's also used for 425 """permessage-deflate extension processor. It's also used for
452 permessage-compress extension when the deflate method is chosen. 426 permessage-compress extension when the deflate method is chosen.
453 427
454 Specification: 428 Specification:
455 http://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-08 429 http://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-08
456 """ 430 """
457 431
458 _SERVER_MAX_WINDOW_BITS_PARAM = 'server_max_window_bits' 432 _SERVER_MAX_WINDOW_BITS_PARAM = 'server_max_window_bits'
459 _SERVER_NO_CONTEXT_TAKEOVER_PARAM = 'server_no_context_takeover' 433 _SERVER_NO_CONTEXT_TAKEOVER_PARAM = 'server_no_context_takeover'
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 message = message.encode('utf-8') 657 message = message.encode('utf-8')
684 658
685 if not self._compress_outgoing_enabled: 659 if not self._compress_outgoing_enabled:
686 return message 660 return message
687 661
688 original_payload_size = len(message) 662 original_payload_size = len(message)
689 self._outgoing_average_ratio_calculator.add_original_bytes( 663 self._outgoing_average_ratio_calculator.add_original_bytes(
690 original_payload_size) 664 original_payload_size)
691 665
692 message = self._rfc1979_deflater.filter( 666 message = self._rfc1979_deflater.filter(
693 message, flush=end, bfinal=self._bfinal) 667 message, end=end, bfinal=self._bfinal)
694 668
695 filtered_payload_size = len(message) 669 filtered_payload_size = len(message)
696 self._outgoing_average_ratio_calculator.add_result_bytes( 670 self._outgoing_average_ratio_calculator.add_result_bytes(
697 filtered_payload_size) 671 filtered_payload_size)
698 672
699 _log_outgoing_compression_ratio( 673 _log_outgoing_compression_ratio(
700 self._logger, 674 self._logger,
701 original_payload_size, 675 original_payload_size,
702 filtered_payload_size, 676 filtered_payload_size,
703 self._outgoing_average_ratio_calculator.get_average_ratio()) 677 self._outgoing_average_ratio_calculator.get_average_ratio())
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 name = processor.name() 811 name = processor.name()
838 if name == self.name(): 812 if name == self.name():
839 before_mux = False 813 before_mux = False
840 continue 814 continue
841 if not processor.is_active(): 815 if not processor.is_active():
842 continue 816 continue
843 if before_mux: 817 if before_mux:
844 # Mux extension cannot be used after extensions 818 # Mux extension cannot be used after extensions
845 # that depend on frame boundary, extension data field, or any 819 # that depend on frame boundary, extension data field, or any
846 # reserved bits which are attributed to each frame. 820 # reserved bits which are attributed to each frame.
847 if (name == common.PERFRAME_COMPRESSION_EXTENSION or 821 if (name == common.DEFLATE_FRAME_EXTENSION or
848 name == common.DEFLATE_FRAME_EXTENSION or
849 name == common.X_WEBKIT_DEFLATE_FRAME_EXTENSION): 822 name == common.X_WEBKIT_DEFLATE_FRAME_EXTENSION):
850 self.set_active(False) 823 self.set_active(False)
851 return 824 return
852 else: 825 else:
853 # Mux extension should not be applied before any history-based 826 # Mux extension should not be applied before any history-based
854 # compression extension. 827 # compression extension.
855 if (name == common.PERFRAME_COMPRESSION_EXTENSION or 828 if (name == common.DEFLATE_FRAME_EXTENSION or
856 name == common.DEFLATE_FRAME_EXTENSION or
857 name == common.X_WEBKIT_DEFLATE_FRAME_EXTENSION or 829 name == common.X_WEBKIT_DEFLATE_FRAME_EXTENSION or
858 name == common.PERMESSAGE_COMPRESSION_EXTENSION or 830 name == common.PERMESSAGE_COMPRESSION_EXTENSION or
859 name == common.X_WEBKIT_PERMESSAGE_COMPRESSION_EXTENSION): 831 name == common.X_WEBKIT_PERMESSAGE_COMPRESSION_EXTENSION):
860 self.set_active(False) 832 self.set_active(False)
861 return 833 return
862 834
863 def _get_extension_response_internal(self): 835 def _get_extension_response_internal(self):
864 self._active = False 836 self._active = False
865 quota = self._request.get_parameter_value(self._QUOTA_PARAM) 837 quota = self._request.get_parameter_value(self._QUOTA_PARAM)
866 if quota is not None: 838 if quota is not None:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 if processor_class is None: 876 if processor_class is None:
905 return None 877 return None
906 return processor_class(extension_request) 878 return processor_class(extension_request)
907 879
908 880
909 def is_compression_extension(extension_name): 881 def is_compression_extension(extension_name):
910 return extension_name in _compression_extension_names 882 return extension_name in _compression_extension_names
911 883
912 884
913 # vi:sts=4 sw=4 et 885 # vi:sts=4 sw=4 et
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698