draft-ietf-hybi-permessage-compression-08.txt   draft-ietf-hybi-permessage-compression-09.txt 
HyBi Working Group T. Yoshino HyBi Working Group T. Yoshino
Internet-Draft Google, Inc. Internet-Draft Google, Inc.
Intended status: Standards Track April 1, 2013 Intended status: Standards Track April 25, 2013
Expires: October 3, 2013 Expires: October 27, 2013
Compression Extensions for WebSocket Compression Extensions for WebSocket
draft-ietf-hybi-permessage-compression-08 draft-ietf-hybi-permessage-compression-09
Abstract Abstract
This document specifies a framework for creating WebSocket extensions This document specifies a framework for creating WebSocket extensions
that add compression functionality to the WebSocket Protocol. An that add compression functionality to the WebSocket Protocol. An
extension based on this framework compresses the payload data portion extension based on this framework compresses the payload data portion
of non-control WebSocket messages on per-message basis using of non-control WebSocket messages on a per-message basis using
parameters negotiated during the opening handshake. This framework parameters negotiated during the opening handshake. This framework
provides a general method to apply a compression algorithm to the provides a general method to apply a compression algorithm to the
contents of WebSocket messages. For each compression algorithm, an contents of WebSocket messages. For each compression algorithm, an
extension is defined by specifying parameter negotiation and extension is defined by specifying parameter negotiation and
compression algorithm in detail. This document also specifies one compression algorithm in detail. This document also specifies one
specific compression extension using the DEFLATE algorithm. specific compression extension using the DEFLATE algorithm.
Please send feedback to the hybi@ietf.org mailing list. Please send feedback to the hybi@ietf.org mailing list.
Status of this Memo Status of this Memo
skipping to change at page 1, line 41 skipping to change at page 1, line 41
Internet-Drafts are working documents of the Internet Engineering Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF). Note that other groups may also distribute Task Force (IETF). Note that other groups may also distribute
working documents as Internet-Drafts. The list of current Internet- working documents as Internet-Drafts. The list of current Internet-
Drafts is at http://datatracker.ietf.org/drafts/current. Drafts is at http://datatracker.ietf.org/drafts/current.
Internet-Drafts are draft documents valid for a maximum of six months Internet-Drafts are draft documents valid for a maximum of six months
and may be updated, replaced, or obsoleted by other documents at any and may be updated, replaced, or obsoleted by other documents at any
time. It is inappropriate to use Internet-Drafts as reference time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress." material or to cite them other than as "work in progress."
This Internet-Draft will expire on October 3, 2013. This Internet-Draft will expire on October 27, 2013.
Copyright Notice Copyright Notice
Copyright (c) 2013 IETF Trust and the persons identified as the Copyright (c) 2013 IETF Trust and the persons identified as the
document authors. All rights reserved. document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents Provisions Relating to IETF Documents
(http://trustee.ietf.org/license-info) in effect on the date of (http://trustee.ietf.org/license-info) in effect on the date of
publication of this document. Please review these documents publication of this document. Please review these documents
carefully, as they describe your rights and restrictions with respect carefully, as they describe your rights and restrictions with respect
to this document. Code Components extracted from this document must to this document. Code Components extracted from this document must
include Simplified BSD License text as described in Section 4.e of include Simplified BSD License text as described in Section 4.e of
the Trust Legal Provisions and are provided without warranty as the Trust Legal Provisions and are provided without warranty as
described in the Simplified BSD License. described in the Simplified BSD License.
Table of Contents Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3
2. Conformance Requirements and Terminology . . . . . . . . . . . 4 2. Conformance Requirements and Terminology . . . . . . . . . . . 4
3. WebSocket Per-message Compression Extension . . . . . . . . . 5 3. Complementary Terminology . . . . . . . . . . . . . . . . . . 5
4. Extension Negotiation . . . . . . . . . . . . . . . . . . . . 6 4. WebSocket Per-message Compression Extension . . . . . . . . . 6
4.1. Negotiation Examples . . . . . . . . . . . . . . . . . . . 7 5. Extension Negotiation . . . . . . . . . . . . . . . . . . . . 7
5. Framing . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 5.1. Negotiation Examples . . . . . . . . . . . . . . . . . . . 8
5.1. Compression . . . . . . . . . . . . . . . . . . . . . . . 8 6. Framing . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5.2. Decompression . . . . . . . . . . . . . . . . . . . . . . 9 6.1. Compression . . . . . . . . . . . . . . . . . . . . . . . 9
6. permessage-deflate extension . . . . . . . . . . . . . . . . . 10 6.2. Decompression . . . . . . . . . . . . . . . . . . . . . . 10
6.1. Method Parameters . . . . . . . . . . . . . . . . . . . . 11 7. Intermediaries . . . . . . . . . . . . . . . . . . . . . . . . 12
6.1.1. Context Takeover Control . . . . . . . . . . . . . . . 11 8. permessage-deflate extension . . . . . . . . . . . . . . . . . 13
6.1.2. Limiting the LZ77 sliding window size . . . . . . . . 11 8.1. Method Parameters . . . . . . . . . . . . . . . . . . . . 14
6.1.3. Example . . . . . . . . . . . . . . . . . . . . . . . 12 8.1.1. Context Takeover Control . . . . . . . . . . . . . . . 14
6.2. Payload Data Transformation . . . . . . . . . . . . . . . 13 8.1.2. Limiting the LZ77 sliding window size . . . . . . . . 15
6.2.1. Compression . . . . . . . . . . . . . . . . . . . . . 13 8.1.3. Example . . . . . . . . . . . . . . . . . . . . . . . 15
6.2.2. Decompression . . . . . . . . . . . . . . . . . . . . 14 8.2. Message Payload Transformation . . . . . . . . . . . . . . 16
6.2.3. Examples . . . . . . . . . . . . . . . . . . . . . . . 15 8.2.1. Compression . . . . . . . . . . . . . . . . . . . . . 16
6.3. Intermediaries . . . . . . . . . . . . . . . . . . . . . . 18 8.2.2. Decompression . . . . . . . . . . . . . . . . . . . . 18
6.4. Implementation Notes . . . . . . . . . . . . . . . . . . . 18 8.2.3. Examples . . . . . . . . . . . . . . . . . . . . . . . 18
7. Security Considerations . . . . . . . . . . . . . . . . . . . 19 8.3. Implementation Notes . . . . . . . . . . . . . . . . . . . 21
8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 20 8.4. Intermediaries . . . . . . . . . . . . . . . . . . . . . . 21
8.1. Registration of the "permessage-deflate" WebSocket 9. Security Considerations . . . . . . . . . . . . . . . . . . . 23
Extension Name . . . . . . . . . . . . . . . . . . . . . . 20 10. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 24
8.2. Registration of the "Per-message Compressed" WebSocket 10.1. Registration of the "permessage-deflate" WebSocket
Framing Header Bit . . . . . . . . . . . . . . . . . . . . 20 Extension Name . . . . . . . . . . . . . . . . . . . . . . 24
9. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 21 10.2. Registration of the "Per-message Compressed" WebSocket
10. References . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Framing Header Bit . . . . . . . . . . . . . . . . . . . . 24
10.1. Normative References . . . . . . . . . . . . . . . . . . . 22 11. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 25
10.2. Informative References . . . . . . . . . . . . . . . . . . 22 12. References . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 23 12.1. Normative References . . . . . . . . . . . . . . . . . . . 26
12.2. Informative References . . . . . . . . . . . . . . . . . . 26
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 27
1. Introduction 1. Introduction
This document specifies a framework to add compression functionality This document specifies a framework to add compression functionality
to the WebSocket Protocol [RFC6455]. This framework specifies how to to the WebSocket Protocol [RFC6455]. This framework specifies how to
define WebSocket Per-message Compression Extensions (PMCEs) define WebSocket Per-message Compression Extensions (PMCEs)
individually for various compression algorithms based on the individually for various compression algorithms based on the
extension concept of the WebSocket Protocol specified in Section 9 of extension concept of the WebSocket Protocol specified in Section 9 of
[RFC6455]. A WebSocket client and a peer WebSocket server negotiate [RFC6455]. A WebSocket client and a peer WebSocket server negotiate
use of a PMCE and determines parameters to configure the compression use of a PMCE and determine parameters to configure the compression
algorithm during the WebSocket opening handshake. The client and algorithm during the WebSocket opening handshake. The client and
server then can exchange non-control messages using frames with server can then exchange non-control messages using frames with
compressed data in the payload data portion. This framework compressed data in the payload data portion. This framework
specifies a general method to apply a compression algorithm to the specifies a general method to apply a compression algorithm to the
contents of WebSocket messages. A document specifying an individual contents of WebSocket messages. A document specifying an individual
PMCE describes how to negotiate configuration parameters for the PMCE describes how to negotiate configuration parameters for the
compression algorithm and how to transform (compress and decompress) compression algorithm and how to transform (compress and decompress)
data in the payload data portion in detail. A WebSocket client may data in the payload data portion in detail. A WebSocket client may
offer multiple PMCEs during the WebSocket opening handshake. A peer offer multiple PMCEs during the WebSocket opening handshake. A peer
WebSocket server received those offers may choose and accept WebSocket server received those offers may choose and accept
preferred one or decline all of them. PMCEs use the RSV1 bit of the preferred one or decline all of them. PMCEs use the RSV1 bit of the
WebSocket frame header to indicate whether a message is compressed or WebSocket frame header to indicate whether a message is compressed or
not, so that an endpoint can choose not to compress messages with not, so that an endpoint can choose not to compress messages with
incompressible contents. incompressible contents.
This document also specifies one specific PMCE based on the DEFLATE This document also specifies one specific PMCE based on the DEFLATE
[RFC1951] algorithm. The extension name of the PMCE is "permessage- [RFC1951] algorithm. The extension name of the PMCE is "permessage-
deflate". We chose the DEFLATE since it's widely available as a deflate". We chose DEFLATE since it's widely available as a library
library on various platforms and the overhead of the DEFLATE is on various platforms and the overhead is small. To align the end of
small. To align the end of compressed data to octet boundary, this compressed data to an octet boundary, this extension uses the
extension uses the algorithm described in Section 2.1 of the PPP algorithm described in Section 2.1 of the PPP Deflate Protocol
Deflate Protocol [RFC1979]. Endpoints can take over the LZ77 sliding [RFC1979]. Endpoints can take over the LZ77 sliding window [LZ77]
window [LZ77] used to build frames for previous messages to get used to build frames for previous messages to get better compression
better compression ratio. For resource-limited devices, this ratio. For resource-limited devices, this extension provides
extension provides parameters to limit memory usage for compression parameters to limit memory usage for compression context.
context.
2. Conformance Requirements and Terminology 2. Conformance Requirements and Terminology
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in [RFC2119]. document are to be interpreted as described in [RFC2119].
Requirements phrased in the imperative as part of algorithms (such as Requirements phrased in the imperative as part of algorithms (such as
"strip any leading space characters" or "return false and abort these "strip any leading space characters" or "return false and abort these
steps") are to be interpreted with the meaning of the key word steps") are to be interpreted with the meaning of the key word
skipping to change at page 4, line 26 skipping to change at page 4, line 26
Conformance requirements phrased as algorithms or specific steps can Conformance requirements phrased as algorithms or specific steps can
be implemented in any manner, so long as the end result is be implemented in any manner, so long as the end result is
equivalent. In particular, the algorithms defined in this equivalent. In particular, the algorithms defined in this
specification are intended to be easy to understand and are not specification are intended to be easy to understand and are not
intended to be performant. intended to be performant.
This document references the procedure to _Fail the WebSocket This document references the procedure to _Fail the WebSocket
Connection_. This procedure is defined in Section 7.1.7 of Connection_. This procedure is defined in Section 7.1.7 of
[RFC6455]. [RFC6455].
This document references the event that _the WebSocket Connection is This document references the event that _The WebSocket Connection is
established_ and the event that _A WebSocket Message Has Been Established_ and the event that _A WebSocket Message Has Been
Received_. This event is defined in Section 4.1 of [RFC6455]. Received_. These events are defined in Section 4.1 and Section 6.2,
respectively, of [RFC6455].
This document uses the Argumented Backus-Naur Form (ABNF) notation of This document uses the Argumented Backus-Naur Form (ABNF) notation of
[RFC5234]. The DIGIT (decimal 0-9) rule is included by reference, as [RFC5234]. The DIGIT (decimal 0-9) rule is included by reference, as
defined in the Appendix B.1 of [RFC5234]. defined in the Appendix B.1 of [RFC5234].
3. WebSocket Per-message Compression Extension 3. Complementary Terminology
This document defines some terms about WebSocket and WebSocket
Extension mechanism that are underspecified or not defined at all in
RFC6455. This terminology is effective only in this document and any
other documents that refer to this section.
Non-control message means a message consists of non-control frames.
Message payload (or payload of a message) means concatenation of the
payload data portion of all frames consisting the message.
Extension in use next to extension X means the extension listed next
to X in the "Sec-WebSocket-Extensions" header in the server's opening
handshake. Such an extension is applied to outgoing data from the
application right after X on sender side but applied right before X
to incoming data from the underlying transport.
4. WebSocket Per-message Compression Extension
WebSocket Per-message Compression Extensions (PMCEs) are extensions WebSocket Per-message Compression Extensions (PMCEs) are extensions
to the WebSocket Protocol enabling compression feature. PMCEs are to the WebSocket Protocol enabling compression functionality. PMCEs
built based on Section 9 of [RFC6455]. PMCEs are individually are built based on Section 9 of [RFC6455]. PMCEs are individually
defined for various compression algorithms, and are registered in the defined for each compression algorithm to be implemented, and are
WebSocket Extension Name Registry created in Section 11.4 of registered in the WebSocket Extension Name Registry created in
[RFC6455]. Each PMCE refers to this framework and defines the Section 11.4 of [RFC6455]. Each PMCE refers to this framework and
followings: defines the following:
o The content to put in the "Sec-WebSocket-Extensions" header. The o The content to put in the "Sec-WebSocket-Extensions" header. The
content includes the extension name of the PMCE and any applicable content includes the extension name of the PMCE and any applicable
extension parameters. extension parameters.
o How to interpret extension parameters exchanged during the opening o How to interpret extension parameters exchanged during the opening
handshake handshake
o How to transform the payload data portion. o How to transform the payload of a message.
One such extension is defined in Section 6 of this document and is One such extension is defined in Section 8 of this document and is
registered in Section 8. Other PMCEs may be defined in other registered in Section 10. Other PMCEs may be defined in other
documents. documents.
Section 4 describes basic extension negotiation process. Section 5 Section 5 describes the basic extension negotiation process.
describes how to apply the compression algorithm with negotiated Section 6 describes how to apply the compression algorithm with
parameters to the contents of WebSocket messages. negotiated parameters to the contents of WebSocket messages.
4. Extension Negotiation 5. Extension Negotiation
To offer use of a PMCE, a client includes a To offer use of a PMCE, a client includes a
"Sec-WebSocket-Extensions" header element with the extension name of "Sec-WebSocket-Extensions" header element with the extension name of
the PMCE in the "Sec-WebSocket-Extensions" header in the client's the PMCE in the "Sec-WebSocket-Extensions" header in the client's
opening handshake of the WebSocket connection. Extension parameters opening handshake of the WebSocket connection. Extension parameters
in the element represent the PMCE offer in detail. For example, a in the element represent the PMCE offer in detail. For example, a
client lists preferred configuration parameter values for the client lists preferred configuration parameter values for the
compression algorithm of the PMCE. A client offers multiple PMCE compression algorithm of the PMCE. A client offers multiple PMCE
choices to the server by including multiple elements in the choices to the server by including multiple elements in the
"Sec-WebSocket-Extensions" header, one for each PMCE offered. The "Sec-WebSocket-Extensions" header, one for each PMCE offered. The
skipping to change at page 6, line 28 skipping to change at page 7, line 28
parameters. parameters.
To accept use of an offered PMCE, a server includes a To accept use of an offered PMCE, a server includes a
"Sec-WebSocket-Extensions" header element with the extension name of "Sec-WebSocket-Extensions" header element with the extension name of
the PMCE in the "Sec-WebSocket-Extensions" header in the server's the PMCE in the "Sec-WebSocket-Extensions" header in the server's
opening handshake of the WebSocket connection. Extension parameters opening handshake of the WebSocket connection. Extension parameters
in the element represent the configuration parameters of the PMCE to in the element represent the configuration parameters of the PMCE to
use in detail. We call these extension parameters and their values use in detail. We call these extension parameters and their values
"agreed parameters". The element MUST represent a PMCE that is fully "agreed parameters". The element MUST represent a PMCE that is fully
supported by the server. The contents of the element doesn't need to supported by the server. The contents of the element doesn't need to
exactly the same as one of the received offers. For example, an be exactly the same as one of the received offers. For example, an
offer with an extension parameter "X" indicating availability of the offer with an extension parameter "X" indicating availability of the
feature X may be accepted with an element without the extension feature X may be accepted with an element without the extension
parameter meaning that the server declined use of the feature. parameter meaning that the server declined use of the feature.
A server MUST NOT accept a PMCE offer together with any extension if A server MUST NOT accept a PMCE offer together with another extension
the PMCE will conflict with the extension on use of the RSV1 bit. A if the PMCE will conflict with the extension on use of the RSV1 bit.
client received a response accepting a PMCE offer together with such A client that receives a response accepting a PMCE offer together
an extension MUST _Fail the WebSocket Connection_. with such an extension MUST _Fail the WebSocket Connection_.
A server MUST NOT accept a PMCE offer together with any extension if A server MUST NOT accept a PMCE offer together with another extension
the PMCE will be applied to output of the extension and any of the if the PMCE will be applied to output of the extension and any of the
following conditions is met about the extension: following conditions applies to the extension:
o The extension requires boundary of fragments to be preserved o The extension requires boundary of fragments to be preserved
between output from the extension at the sender and input to the between output from the extension at the sender and input to the
extension at the receiver. extension at the receiver.
o The extension uses the "Extension data" field or any of the o The extension uses the "Extension data" field or any of the
reserved bits on the WebSocket header as per-frame attribute. reserved bits on the WebSocket header as per-frame attribute.
A client received a response accepting a PMCE offer together with A client receiving a response accepting a PMCE offer together with
such an extension MUST _Fail the WebSocket Connection_. such an extension MUST _Fail the WebSocket Connection_.
A server declines all offered PMCEs by not including any element with A server declines all offered PMCEs by not including any element with
PMCE names. If a server responds with no PMCE element in the PMCE names. If a server responds with no PMCE element in the
"Sec-WebSocket-Extensions" header, both endpoints proceed without "Sec-WebSocket-Extensions" header, both endpoints proceed without
Per-message Compression once _the WebSocket Connection is Per-message Compression once _the WebSocket Connection is
established_. established_.
If a server gives an invalid response, such as accepting a PMCE that If a server gives an invalid response, such as accepting a PMCE that
the client did not offer, the client MUST _Fail the WebSocket the client did not offer, the client MUST _Fail the WebSocket
Connection_. Connection_.
If a server responds with a valid PMCE element in the If a server responds with a valid PMCE element in the
"Sec-WebSocket-Extensions" header and _the WebSocket Connection is "Sec-WebSocket-Extensions" header and _the WebSocket Connection is
established_, both endpoints MUST use the algorithm described in established_, both endpoints MUST use the algorithm described in
Section 5 to exchange messages, using the payload data transformation Section 6 to exchange messages, using the message payload
(compressing and decompressing) procedure of the PMCE returned by the transformation (compressing and decompressing) procedure of the PMCE
server. returned by the server.
4.1. Negotiation Examples 5.1. Negotiation Examples
The followings are example values for the "Sec-WebSocket-Extensions" The followings are example values for the "Sec-WebSocket-Extensions"
header offering PMCEs. permessage-foo and permessage-bar in the header offering PMCEs. permessage-foo and permessage-bar in the
examples are hypothetical extension names of PMCEs for compression examples are hypothetical extension names of PMCEs for compression
algorithm foo and bar. algorithm foo and bar.
o Offer the permessage-foo. o Offer the permessage-foo.
permessage-foo permessage-foo
skipping to change at page 8, line 5 skipping to change at page 9, line 5
a fallback plan. a fallback plan.
permessage-foo, permessage-bar permessage-foo, permessage-bar
o Offer the permessage-foo with a parameter use_y which enables a o Offer the permessage-foo with a parameter use_y which enables a
feature y as first choice, and the permessage-foo without the feature y as first choice, and the permessage-foo without the
use_y parameter as a fallback plan. use_y parameter as a fallback plan.
permessage-foo; use_y, permessage-foo permessage-foo; use_y, permessage-foo
5. Framing 6. Framing
PMCEs operate only on non-control messages. PMCEs operate only on PMCEs operate only on non-control messages.
the payload data portion and the "Per-message Compressed" bit.
This document allocates the RSV1 bit of the WebSocket header for This document allocates the RSV1 bit of the WebSocket header for
PMCEs, and calls the bit the "Per-message Compressed" bit. On a PMCEs, and calls the bit the "Per-message Compressed" bit. On a
WebSocket connection where a PMCE is in use, this bit indicates WebSocket connection where a PMCE is in use, this bit indicates
whether a message is compressed or not. whether a message is compressed or not.
A message with the "Per-message Compressed" bit set on the first A message with the "Per-message Compressed" bit set on the first
fragment of the message is called "compressed message". Frames of a fragment of the message is called a "compressed message". Frames of
compressed message have compressed data in the payload data portion. a compressed message have compressed data in the payload data
An endpoint received a compressed message decompresses the portion. An endpoint receiving a compressed message decompresses the
concatenation of the compressed data of the frames of the message by concatenation of the compressed data of the frames of the message by
following the decompressing procedure specified by the PMCE in use. following the decompression procedure specified by the PMCE in use.
The endpoint uses the bytes corresponding to the application data The endpoint uses the bytes corresponding to the application data
portion in this decompressed data for the _A WebSocket Message Has portion in this decompressed data for the _A WebSocket Message Has
Been Received_ event instead of the received data as-is. Been Received_ event instead of the received data as-is.
A message with the "Per-message Compressed" bit unset on the first A message with the "Per-message Compressed" bit unset on the first
fragment of the message is called "uncompressed message". Frames of fragment of the message is called an "uncompressed message". Frames
an uncompressed message have uncompressed original data as-is in the of an uncompressed message have uncompressed original data as-is in
payload data portion. An endpoint received an uncompressed message the payload data portion. An endpoint received an uncompressed
uses the concatenation of the application data portion of the frames message uses the concatenation of the application data portion of the
of the message as-is for the _A WebSocket Message Has Been Received_ frames of the message as-is for the _A WebSocket Message Has Been
event. Received_ event.
5.1. Compression 6.1. Compression
An endpoint MUST use the following algorithm to send a message in the An endpoint MUST use the following algorithm to send a message in the
form of a compressed message. form of a compressed message.
1. Compress the payload data portion of the original message by 1. Compress the message payload of the original message by following
following the compression procedure of the PMCE. The original the compression procedure of the PMCE. The original message may
message may input from application layer or output of another be input from the application layer or output of another
WebSocket extension depending on what extensions are negotiated. WebSocket extension depending on what extensions were negotiated.
2. If this PMCE is the last extension to process outgoing messages, 2. If this PMCE is the last extension to process outgoing messages,
build frame(s) by putting the compressed data instead of the build frame(s) by using the compressed data instead of the
original data for the payload data portion, set the "Per-message original data for the message payload, and setting the
Compressed" bit of the first frame, and send the frame(s). "Per-message Compressed" bit of the first frame, then send the
Otherwise, pass the transformed payload data and modified header frame(s) as described in Section 6.1 of RFC6455. Otherwise, pass
values including "Per-message Compressed" bit value set to 1 to the transformed message payload and modified header values
the next extension. including "Per-message Compressed" bit value set to 1 to the
extension next to the PMCE. If the extension expects frames as
input, build a frame for the message and pass it.
An endpoint MUST use the following algorithm to send a message in the An endpoint MUST use the following algorithm to send a message in the
form of an uncompressed message. If this PMCE is the last extension form of an uncompressed message. If this PMCE is the last extension
to process outgoing messages, build frame(s) by putting the original to process outgoing messages, build frame(s) by using the original
data for payload data portion as-is, unset the "Per-message data for the payload data portion as-is and unsetting the
Compressed" bit of the first frame, and send the frame(s). "Per-message Compressed" bit of the first frame, then send the
Otherwise, pass the payload data and header values to the next frame(s) as described in Section 6.1 of RFC6455. Otherwise, pass the
extension as-is. message payload and header values to the extension next to the PMCE
as-is. If the extension expects frames as input, build a frame for
the message and pass it.
An endpoint MUST NOT set the "Per-message Compressed" bit of control An endpoint MUST NOT set the "Per-message Compressed" bit of control
frames and non-first fragments of a data message. An endpoint frames and non-first fragments of a data message. An endpoint
received such a frame MUST _Fail the WebSocket Connection_. received such a frame MUST _Fail the WebSocket Connection_.
PMCEs don't change the opcode field. The opcode of the first frame PMCEs don't change the opcode field. The opcode of the first frame
of a compress message indicates the opcode of the original message. of a compress message indicates the opcode of the original message.
The payload data portion in frames generated by a PMCE is not subject The payload data portion in frames generated by a PMCE is not subject
to the constraints for the original data type. For example, the to the constraints for the original data type. For example, the
concatenation of the data corresponding to the application data concatenation of the data corresponding to the application data
portion of frames of a compressed text message may be not valid portion of frames of a compressed text message is not required to be
UTF-8. At the receiver, the payload data portion after decompression valid UTF-8. At the receiver, the payload data portion after
is subject to the constraints for the original data type again. decompression is subject to the constraints for the original data
type again.
5.2. Decompression 6.2. Decompression
An endpoint MUST use the following algorithm to receive a message in An endpoint MUST use the following algorithm to receive a message in
the form of a compressed message. the form of a compressed message.
1. Concatenate the payload data portion of the received frames of 1. Concatenate the payload data portion of the received frames of
the compressed message. The received frames may direct input the compressed message. The received frames may direct input
from underlying transport or output of another WebSocket from underlying transport or output of another WebSocket
extension depending on what extensions are negotiated. extension depending on what extensions were negotiated.
2. Decompress the concatenation by following the decompression 2. Decompress the concatenation by following the decompression
procedure of the PMCE. procedure of the PMCE.
3. If this is the last extension to process incoming messages, 3. If this is the last extension to process incoming messages,
deliver the _A WebSocket Message Has Been Received_ event to the deliver the _A WebSocket Message Has Been Received_ event to the
application layer with the decompressed payload data and header application layer with the decompressed message payload and
values including the "Per-message Compressed" bit unset to 0. header values including the "Per-message Compressed" bit unset to
Otherwise, pass the decompressed payload data and header values 0. Otherwise, pass the decompressed message payload and header
including the "Per-message Compressed" bit unset to 0 to the next values including the "Per-message Compressed" bit unset to 0 to
extension. the extension next to the PMCE. If the extension expects frames
as input, build a frame for the message and pass it.
An endpoint MUST use the following algorithm to receive a message in An endpoint MUST use the following algorithm to receive a message in
the form of an uncompressed message. If this PMCE is the last the form of an uncompressed message. If this PMCE is the last
extension to process incoming messages, deliver the _A WebSocket extension to process incoming messages, deliver the _A WebSocket
Message Has Been Received_ event to the application layer with the Message Has Been Received_ event to the application layer with the
received payload data and header values as-is. Otherwise, pass the received message payload and header values as-is. Otherwise, pass
payload data and header values to the next extension as-is. the message payload and header values to the extension next to the
PMCE as-is. If the extension expects frames as input, build a frame
for the message and pass it.
6. permessage-deflate extension 7. Intermediaries
When an intermediary proxies a WebSocket connection, the intermediary
MAY add, change or remove Per-message Compression on the messages.
Such a change must not be made if the new combination of extensions
after the change doesn't conform to the constraints of the
extensions. The elements in the "Sec-WebSocket-Extensions" for the
PMCE in the opening handshakes with the connected client and server
must be altered by the intermediary accordingly to match the new
combination of extensions.
8. permessage-deflate extension
This section specifies a specific PMCE called "permessage-deflate". This section specifies a specific PMCE called "permessage-deflate".
It compresses the payload data portion of messages using the DEFLATE It compresses the payload of a message using the DEFLATE algorithm
[RFC1951] and the byte boundary aligning method introduced in [RFC1951] and the byte boundary aligning method introduced in
[RFC1979]. [RFC1979].
This section uses the term "byte" with the same meaning as RFC1951,
i.e. 8 bits stored or transmitted as a unit (same as an octet).
The registered extension name for this extension is The registered extension name for this extension is
"permessage-deflate". "permessage-deflate".
For an offer for this extension, the following 3 extension parameters For an offer for this extension, the following 3 extension parameters
are defined. are defined.
o "s2c_no_context_takeover" o "s2c_no_context_takeover"
o "s2c_max_window_bits" o "s2c_max_window_bits"
skipping to change at page 11, line 12 skipping to change at page 14, line 15
o The response has any extension parameter not defined for use in a o The response has any extension parameter not defined for use in a
response. response.
o The response has any extension parameter with an invalid value. o The response has any extension parameter with an invalid value.
o The response has multiple extension parameters with the same name. o The response has multiple extension parameters with the same name.
o The client doesn't support the configuration the response o The client doesn't support the configuration the response
represents. represents.
6.1. Method Parameters The term "LZ77 sliding window" used in this section means the buffer
storing recently processed input. The LZ77 algorithm searches the
buffer for match with the next input.
6.1.1. Context Takeover Control 8.1. Method Parameters
8.1.1. Context Takeover Control
A client MAY attach the "s2c_no_context_takeover" extension A client MAY attach the "s2c_no_context_takeover" extension
parameter. The "s2c_no_context_takeover" extension parameter has no parameter. The "s2c_no_context_takeover" extension parameter has no
value. Using this extension parameter, a client can disallow the value. Using this extension parameter, a client can prevent the peer
peer server to use the same LZ77 sliding window to build frames of server from using the same LZ77 sliding window it used to build
the last sent message to build frames of the next message to send. frames of the last sent message to build frames of the next message.
If the peer server doesn't use the same LZ77 sliding window to When the peer server doesn't use the same LZ77 sliding window to
compress two or more messages, the client can reduce the amount of compress multiple messages, the client doesn't need to reserve memory
memory for the LZ77 sliding window to decompress received messages. to retain the LZ77 sliding window in between messages. A server
A server accepts an offer with this extension parameter by including accepts an offer with this extension parameter by including the
the "s2c_no_context_takeover" extension parameter in the response. A "s2c_no_context_takeover" extension parameter in the response. A
server accepted an offer with this extension parameter MUST empty its server which accepted an offer with this extension parameter MUST
LZ77 sliding window to compress messages to send each time the server start the compression of each message with an empty LZ77 sliding
builds a new message. window.
It is RECOMMENDED to make a server be able to accept the It is RECOMMENDED that servers implement the
"s2c_no_context_takeover" parameter. "s2c_no_context_takeover" parameter.
A server MAY attach the "c2s_no_context_takeover" extension A server MAY attach the "c2s_no_context_takeover" extension
parameter. The "c2s_no_context_takeover" extension parameter has no parameter. The "c2s_no_context_takeover" extension parameter has no
value. Using this extension parameter, a server can disallow the value. Using this extension parameter, a server can prevent the peer
peer client to use the LZ77 sliding window used to build frames of client from using the same LZ77 sliding window it used to build
the last sent message to build frames for the next message to send. frames of the last sent message to build frames for the next message.
If the peer client doesn't use the same LZ77 sliding window to This can reduce the amount of memory that the server has to reserve
compress two or more messages, the server can reduce the amount of for the connection, in the same way the "s2c_no_context_takeover"
memory for the LZ77 sliding window to decompress received messages. extension does for the client. A client that received this parameter
A client that received this parameter MUST empty its LZ77 sliding MUST start the compression of each message with an empty LZ77 sliding
window to compress messages to send each time the client builds a new window.
message.
It is RECOMMENDED to make a client be able to accept the It is RECOMMENDED that clients implement the
"c2s_no_context_takeover" parameter. "c2s_no_context_takeover" parameter.
6.1.2. Limiting the LZ77 sliding window size 8.1.2. Limiting the LZ77 sliding window size
A client MAY attach the "s2c_max_window_bits" extension parameter to A client MAY attach the "s2c_max_window_bits" extension parameter to
limit the LZ77 sliding window size that the server uses to build limit the LZ77 sliding window size that the server uses to compress
messages. This extension parameter MUST have a decimal integer value messages. This extension parameter MUST have a decimal integer value
in the range between 8 to 15 indicating the base-2 logarithm of the without leading zeroes between 8 to 15 inclusive indicating the
LZ77 sliding window size. base-2 logarithm of the LZ77 sliding window size.
s2c_max_window_bits = 1*DIGIT s2c_max_window_bits = 1*DIGIT
A server declines an offer with this extension parameter if the A server will decline an offer with this extension parameter if the
server doesn't support the extension parameter. A server accepts an server doesn't support the extension parameter. A server accepts an
offer with this extension parameter by including the extension offer with this extension parameter by including the extension
parameter with the same value as the offer in the response. If a parameter with the same value as the offer in the response. If a
server accepts an offer with this extension parameter, the server server accepts an offer with this extension parameter, the server
MUST NOT use LZ77 sliding window size greater than the size specified MUST NOT use LZ77 sliding window size greater than the size specified
by the extension parameter to compress messages by the extension parameter to compress messages.
A client MAY attach the "c2s_max_window_bits" extension parameter if A client MAY attach the "c2s_max_window_bits" extension parameter if
the client can adjust LZ77 sliding window size based on the the client can adjust LZ77 sliding window size based on the
"c2s_max_window_bits" sent by the server. This parameter has no "c2s_max_window_bits" sent by the server. This parameter has no
value. value.
If a server received and accepts an offer with the If a server receives an offer with the "c2s_max_window_bits"
"c2s_max_window_bits" extension parameter, the server MAY include the extension parameter, the server MAY include the "c2s_max_window_bits"
"c2s_max_window_bits" parameter in the response to the offer to limit parameter in the response to the offer to limit the LZ77 sliding
the LZ77 sliding window size that the client uses to build messages. window size that the client uses to build messages. If a server
If a server received and accepts an offer without the received and accepts an offer without the "c2s_max_window_bits"
"c2s_max_window_bits" extension parameter, the server MUST NOT extension parameter, the server MUST NOT include the
include the "c2s_max_window_bits" extension parameter in the response "c2s_max_window_bits" extension parameter in the response to the
to the offer. The "c2s_max_window_bits" extension parameter in the offer. The "c2s_max_window_bits" extension parameter in the server's
server's opening handshake MUST have a decimal integer value in the opening handshake MUST have a decimal integer value without leading
range between 8 to 15 indicating the base-2 logarithm of the LZ77 zeroes between 8 to 15 inclusive indicating the base-2 logarithm of
sliding window size. the LZ77 sliding window size.
c2s_max_window_bits = 1*DIGIT c2s_max_window_bits = 1*DIGIT
If a client received the "c2s_max_window_bits" extension parameter, If a client received the "c2s_max_window_bits" extension parameter,
the client MUST NOT use LZ77 sliding window size greater than the the client MUST NOT use an LZ77 sliding window size greater than the
size specified by the extension parameter to build messages. size specified by the extension parameter to build messages.
6.1.3. Example 8.1.3. Example
The simplest "Sec-WebSocket-Extensions" header in a client's opening The simplest "Sec-WebSocket-Extensions" header in a client's opening
handshake to offer use of the permessage-deflate is the following: handshake to offer use of the permessage-deflate is the following:
Sec-WebSocket-Extensions: permessage-deflate Sec-WebSocket-Extensions: permessage-deflate
Since the "c2s_max_window_bits" extension parameter is not specified, Since the "c2s_max_window_bits" extension parameter is not specified,
the server may not accept the offer with the "c2s_max_window_bits" the server may not accept the offer with the "c2s_max_window_bits"
extension parameter. The simplest "Sec-WebSocket-Extensions" header extension parameter. The simplest "Sec-WebSocket-Extensions" header
in a server's opening handshake to accept use of the permessage- in a server's opening handshake to accept use of the permessage-
skipping to change at page 13, line 15 skipping to change at page 16, line 21
The following offer sent by a client is asking the server to use the The following offer sent by a client is asking the server to use the
LZ77 sliding window size of 1,024 bytes or less and declaring that LZ77 sliding window size of 1,024 bytes or less and declaring that
the client can accept the "c2s_max_window_bits" extension parameter. the client can accept the "c2s_max_window_bits" extension parameter.
Sec-WebSocket-Extensions: Sec-WebSocket-Extensions:
permessage-deflate; permessage-deflate;
c2s_max_window_bits; s2c_max_window_bits=10 c2s_max_window_bits; s2c_max_window_bits=10
This offer might be rejected by the server because the server doesn't This offer might be rejected by the server because the server doesn't
support the "s2c_max_window_bits" extension parameter. This is fine support the "s2c_max_window_bits" extension parameter. This is fine
if the "s2c_max_window_bits" is mandatory for the client, but if the if the client cannot support a larger sliding window size, but if the
client want to fallback to the "permessage-deflate" without the client wants to fallback to the "permessage-deflate" without the
"s2c_max_window_bits", the client should offer the fallback option in "s2c_max_window_bits" option, the client should offer the fallback
addition like this: option explicitly like this:
Sec-WebSocket-Extensions: Sec-WebSocket-Extensions:
permessage-deflate; permessage-deflate;
c2s_max_window_bits; s2c_max_window_bits=10, c2s_max_window_bits; s2c_max_window_bits=10,
permessage-deflate; permessage-deflate;
c2s_max_window_bits c2s_max_window_bits
This example offers two configurations so that the server can accept This example offers two configurations so that the server can accept
permessage-deflate by picking supported one from them. To accept the permessage-deflate by picking a supported one. To accept the first
first option, the server sends back this for example: option, the server might send back, for example:
Sec-WebSocket-Extensions: Sec-WebSocket-Extensions:
permessage-deflate; s2c_max_window_bits=10 permessage-deflate; s2c_max_window_bits=10
And to accept the second option, the server sends back this for And to accept the second option, the server might send back, for
example: example:
Sec-WebSocket-Extensions: permessage-deflate Sec-WebSocket-Extensions: permessage-deflate
6.2. Payload Data Transformation 8.2. Message Payload Transformation
6.2.1. Compression 8.2.1. Compression
An endpoint uses the following algorithm to compress a message. An endpoint uses the following algorithm to compress a message.
1. Compress all the octets of the payload data portion of the 1. Compress all the octets of the payload of the message using
message using the DEFLATE. DEFLATE.
2. If the resulting data does not end with an empty DEFLATE block 2. If the resulting data does not end with an empty DEFLATE block
with no compression (the "BTYPE" bit is set to 0), append an with no compression (the "BTYPE" bits is set to 00), append an
empty DEFLATE block with no compression to the tail end. empty DEFLATE block with no compression to the tail end.
3. Remove 4 octets (that are 0x00 0x00 0xff 0xff) from the tail end. 3. Remove 4 octets (that are 0x00 0x00 0xff 0xff) from the tail end.
After this step, the last octet of the compressed data contains After this step, the last octet of the compressed data contains
(possibly part of) the DEFLATE header bits with the "BTYPE" bit (possibly part of) the DEFLATE header bits with the "BTYPE" bits
set to 0. set to 00.
In using the DEFLATE in the first step above: In using DEFLATE in the first step above:
o An endpoints MAY use multiple DEFLATE blocks to compress one o An endpoint MAY use multiple DEFLATE blocks to compress one
message. message.
o An endpoints MAY use DEFLATE blocks of any type. o An endpoint MAY use DEFLATE blocks of any type.
o An endpoints MAY use both DEFLATE blocks with the "BFINAL" bit set o An endpoint MAY use both DEFLATE blocks with the "BFINAL" bit set
to 0 and DEFLATE blocks with the "BFINAL" bit set to 1. to 0 and DEFLATE blocks with the "BFINAL" bit set to 1.
o When any DEFLATE block with the "BFINAL" bit set to 1 doesn't end o When any DEFLATE block with the "BFINAL" bit set to 1 doesn't end
at byte boundary, an endpoint adds minimal padding bits of 0 to at byte boundary, an endpoint adds minimal padding bits of 0 to
make it end at byte boundary. The next DEFLATE block follows the make it end at byte boundary. The next DEFLATE block follows the
padded data if any. padded data if any.
An endpoint MUST NOT use an LZ77 sliding window longer than 32,768 An endpoint MUST NOT use an LZ77 sliding window longer than 32,768
bytes to compress messages to send. bytes to compress messages to send.
If the "agreed parameters" contain the "c2s_no_context_takeover" If the "agreed parameters" contain the "c2s_no_context_takeover"
extension parameter, the client MUST empty its LZ77 sliding window to extension parameter, the client MUST start compressing each new
compress messages to send each time the client compresses a new message with an empty LZ77 sliding window. Otherwise, the client MAY
message to send. Otherwise, the client MAY take over the LZ77 take over the LZ77 sliding window used to build the last compressed
sliding window used to build the last compressed message. message.
If the "agreed parameters" contain the "s2c_no_context_takeover" If the "agreed parameters" contain the "s2c_no_context_takeover"
extension parameter, the server MUST empty its LZ77 sliding window to extension parameter, the server MUST start compressing each new
compress messages to send each time the server compresses a new message with an empty LZ77 sliding window. Otherwise, the server MAY
message to send. Otherwise, the server MAY take over the LZ77 take over the LZ77 sliding window used to build the last compressed
sliding window used to build the last compressed message. message.
If the "agreed parameters" contain the "c2s_max_window_bits" If the "agreed parameters" contain the "c2s_max_window_bits"
extension parameter with a value of w, the client MUST NOT use an extension parameter with a value of w, the client MUST NOT use an
LZ77 sliding window longer than w-th power of 2 bytes to compress LZ77 sliding window longer than the w-th power of 2 bytes to compress
messages to send. messages to send.
If the "agreed parameters" contain the "s2c_max_window_bits" If the "agreed parameters" contain the "s2c_max_window_bits"
extension parameter with a value of w, the server MUST NOT use an extension parameter with a value of w, the server MUST NOT use an
LZ77 sliding window longer than w-th power of 2 bytes to compress LZ77 sliding window longer than the w-th power of 2 bytes to compress
messages to send. messages to send.
6.2.2. Decompression 8.2.2. Decompression
An endpoint uses the following algorithm to decompress a message. An endpoint uses the following algorithm to decompress a message.
1. Append 4 octets of 0x00 0x00 0xff 0xff to the tail end of the 1. Append 4 octets of 0x00 0x00 0xff 0xff to the tail end of the
payload data portion of the message. payload of the message.
2. Decompress the resulting data using the DEFLATE. 2. Decompress the resulting data using DEFLATE.
If the "agreed parameters" contain the "s2c_no_context_takeover" If the "agreed parameters" contain the "s2c_no_context_takeover"
extension parameter, the client MAY empty its LZ77 sliding window to extension parameter, the client MAY start decompressing each new
decompress received messages each time the client decompresses a new message with an empty LZ77 sliding window. Otherwise, the client
received message. Otherwise, the client MUST take over the LZ77 MUST take over the LZ77 sliding window used to process the last
sliding window used to process the last compressed message. compressed message.
If the "agreed parameters" contain the "c2s_no_context_takeover" If the "agreed parameters" contain the "c2s_no_context_takeover"
extension parameter, the server MAY empty its LZ77 sliding window to extension parameter, the server MAY start decompressing each new
decompress received messages each time the server decompresses a new message with an empty LZ77 sliding window. Otherwise, the server
received message. Otherwise, the server MUST take over the LZ77 MUST take over the LZ77 sliding window used to process the last
sliding window used to process the last compressed message. compressed message.
If the "agreed parameters" contain the "s2c_max_window_bits" If the "agreed parameters" contain the "s2c_max_window_bits"
extension parameter with a value of w, the client MAY reduce the size extension parameter with a value of w, the client MAY reduce the size
of its LZ77 sliding window to decompress received messages down to of its LZ77 sliding window to decompress received messages down to
the w-th power of 2 bytes. Otherwise, the client MUST use a 32,768 the w-th power of 2 bytes. Otherwise, the client MUST use a 32,768
byte LZ77 sliding window to decompress received messages. byte LZ77 sliding window to decompress received messages.
If the "agreed parameters" contain the "c2s_max_window_bits" If the "agreed parameters" contain the "c2s_max_window_bits"
extension parameter with a value of w, the server MAY reduce the size extension parameter with a value of w, the server MAY reduce the size
of its LZ77 sliding window to decompress received messages down to of its LZ77 sliding window to decompress received messages down to
the w-th power of 2 bytes. Otherwise, the server MUST use a 32,768 the w-th power of 2 bytes. Otherwise, the server MUST use a 32,768
byte LZ77 sliding window to decompress received messages. byte LZ77 sliding window to decompress received messages.
6.2.3. Examples 8.2.3. Examples
This section introduces examples of how the permessage-deflate This section introduces examples of how the permessage-deflate
transforms messages. transforms messages.
6.2.3.1. A message compressed using 1 compressed DEFLATE block 8.2.3.1. A message compressed using 1 compressed DEFLATE block
Suppose that an endpoint sends a text message "Hello". If the Suppose that an endpoint sends a text message "Hello". If the
endpoint uses 1 compressed DEFLATE block (compressed with fixed endpoint uses 1 compressed DEFLATE block (compressed with fixed
Huffman code and the "BFINAL" bit is not set) to compress the Huffman code and the "BFINAL" bit is not set) to compress the
message, the endpoint obtains the compressed data to put in the message, the endpoint obtains the compressed data to use for the
payload data portion as follows. message payload as follows.
The endpoint compresses "Hello" into 1 compressed DEFLATE block and The endpoint compresses "Hello" into 1 compressed DEFLATE block and
flushes the resulting data into a byte array using an empty DEFLATE flushes the resulting data into a byte array using an empty DEFLATE
block with no compression: block with no compression:
0xf2 0x48 0xcd 0xc9 0xc9 0x07 0x00 0x00 0x00 0xff 0xff 0xf2 0x48 0xcd 0xc9 0xc9 0x07 0x00 0x00 0x00 0xff 0xff
By stripping 0x00 0x00 0xff 0xff from the tail end, the endpoint gets By stripping 0x00 0x00 0xff 0xff from the tail end, the endpoint gets
the data to put in the payload data portion: the data to use for the message payload:
0xf2 0x48 0xcd 0xc9 0xc9 0x07 0x00 0xf2 0x48 0xcd 0xc9 0xc9 0x07 0x00
Suppose that the endpoint sends this compressed message without Suppose that the endpoint sends this compressed message without
fragmentation. The endpoint builds one frame by putting the whole fragmentation. The endpoint builds one frame by putting the whole
compressed data in the payload data portion of the frame: compressed data in the payload data portion of the frame:
0xc1 0x07 0xf2 0x48 0xcd 0xc9 0xc9 0x07 0x00 0xc1 0x07 0xf2 0x48 0xcd 0xc9 0xc9 0x07 0x00
The first 2 octets (0xc1 0x07) are the WebSocket frame header (FIN=1, The first 2 octets (0xc1 0x07) are the WebSocket frame header (FIN=1,
skipping to change at page 16, line 45 skipping to change at page 19, line 48
fragments are 3 and 4 octet, the first frame is: fragments are 3 and 4 octet, the first frame is:
0x41 0x03 0xf2 0x48 0xcd 0x41 0x03 0xf2 0x48 0xcd
and the second frame is: and the second frame is:
0x80 0x04 0xc9 0xc9 0x07 0x00 0x80 0x04 0xc9 0xc9 0x07 0x00
Note that the RSV1 bit is set only on the first frame. Note that the RSV1 bit is set only on the first frame.
6.2.3.2. Sharing LZ77 Sliding Window 8.2.3.2. Sharing LZ77 Sliding Window
Suppose that a client has sent a message "Hello" as a compressed Suppose that a client has sent a message "Hello" as a compressed
message and will send the same message "Hello" again as a compressed message and will send the same message "Hello" again as a compressed
message. message.
0xf2 0x48 0xcd 0xc9 0xc9 0x07 0x00 0xf2 0x48 0xcd 0xc9 0xc9 0x07 0x00
This is the payload of the first message the client has sent. If the This is the payload of the first message the client has sent. If the
"agreed parameters" contain the "c2s_no_context_takeover" extension "agreed parameters" contain the "c2s_no_context_takeover" extension
parameter, the client compresses the payload data portion of the next parameter, the client compresses the payload of the next message into
message into the same bytes (if the client uses the same "BTYPE" the same bytes (if the client uses the same "BTYPE" value and
value and "BFINAL" value). So, the payload will be: "BFINAL" value). So, the payload of the second message will be:
0xf2 0x48 0xcd 0xc9 0xc9 0x07 0x00 0xf2 0x48 0xcd 0xc9 0xc9 0x07 0x00
If the "agreed parameters" contain the "c2s_no_context_takeover" If the "agreed parameters" did not contain the
extension parameter, the client can compress the payload data portion "c2s_no_context_takeover" extension parameter, the client can
of the next message into shorter bytes utilizing the history in the compress the payload of the next message into shorter bytes by
LZ77 sliding window. So, the payload will be: referencing the history in the LZ77 sliding window. So, the payload
of the second message will be:
0xf2 0x00 0x11 0x00 0x00 0xf2 0x00 0x11 0x00 0x00
Note that even if any uncompressed message (any message with the RSV1 Note that even if some uncompressed messages (with the RSV1 bit
bit unset) is inserted between the two "Hello" messages, such a unset) are inserted between the two "Hello" messages, they will make
message doesn't make any change on the LZ77 sliding window. no difference to the LZ77 sliding window.
6.2.3.3. Using a DEFLATE Block with No Compression 8.2.3.3. Using a DEFLATE Block with No Compression
0xc1 0x0b 0x00 0x05 0x00 0xfa 0xff 0x48 0x65 0x6c 0x6c 0x6f 0x00 0xc1 0x0b 0x00 0x05 0x00 0xfa 0xff 0x48 0x65 0x6c 0x6c 0x6f 0x00
This is a frame consisting a text message "Hello" compressed using a This is a frame constituting a text message "Hello" compressed using
DEFLATE block with no compression. The first 2 octets (0xc1 0x0b) a DEFLATE block with no compression. The first 2 octets (0xc1 0x0b)
are the WebSocket frame header (FIN=1, RSV1=1, RSV2=0, RSV3=0, are the WebSocket frame header (FIN=1, RSV1=1, RSV2=0, RSV3=0,
opcode=text, MASK=0, Payload length=7). Note that the RSV1 bit is opcode=text, MASK=0, Payload length=7). Note that the RSV1 bit is
set for this message (only on the first fragment if the message is set for this message (only on the first fragment if the message is
fragmented) because the RSV1 bit is set when the DEFLATE is applied fragmented) because the RSV1 bit is set when DEFLATE is applied to
to the message and it includes the case only DEFLATE blocks with no the message, including the case when only DEFLATE blocks with no
compression are used. The third to 13th octet consists a payload compression are used. The third to 13th octet consists a payload
containing "Hello" compressed using a DEFLATE block with no data containing "Hello" compressed using a DEFLATE block with no
compression. compression.
6.2.3.4. Using a DEFLATE Block with BFINAL Set to 1 8.2.3.4. Using a DEFLATE Block with BFINAL Set to 1
On platform where the flush method using an empty DEFLATE block with On platform where the flush method using an empty DEFLATE block with
no compression is not avaiable, implementors can choose to flush data no compression is not avaiable, implementors can choose to flush data
using DEFLATE blocks with "BFINAL" set to 1. using DEFLATE blocks with "BFINAL" set to 1.
0xf3 0x48 0xcd 0xc9 0xc9 0x07 0x00 0x00 0xf3 0x48 0xcd 0xc9 0xc9 0x07 0x00 0x00
This is a payload of a message containing "Hello" compressed using a This is a payload of a message containing "Hello" compressed using a
DEFLATE block with "BFINAL" set to 1. The first 7 octet consist a DEFLATE block with "BFINAL" set to 1. The first 7 octets constitute
DEFLATE block with "BFINAL" set to 1 and "BTYPE" set to 1 containing a DEFLATE block with "BFINAL" set to 1 and "BTYPE" set to 01
"Hello". The last 1 octet (0x00) contains the header bits with containing "Hello". The last 1 octet (0x00) contains the header bits
"BFINAL" set to 0 and "BTYPE" set to 0, and 7 padding bits of 0. with "BFINAL" set to 0 and "BTYPE" set to 00, and 5 padding bits of
0. This octet is necessary to allow the payload to be decompressed
This octet is necessary to allow the payload to be decompressed in in the same manner as messages flushed using DEFLATE blocks with
the same manner as messages flushed using DEFLATE blocks with BFINAL BFINAL unset.
unset.
6.2.3.5. Two DEFLATE Blocks in 1 Message 8.2.3.5. Two DEFLATE Blocks in 1 Message
Two or more DEFLATE blocks may be used in 1 message. Two or more DEFLATE blocks may be used in 1 message.
0xf2 0x48 0x05 0x00 0x00 0x00 0xff 0xff 0xca 0xc9 0xc9 0x07 0x00 0xf2 0x48 0x05 0x00 0x00 0x00 0xff 0xff 0xca 0xc9 0xc9 0x07 0x00
The first 3 octets (0xf2 0x48 0x05) and the least significant two The first 3 octets (0xf2 0x48 0x05) and the least significant two
bits of the 4th octet (0x00) consist one DEFLATE block with "BFINAL" bits of the 4th octet (0x00) constitute one DEFLATE block with
set to 0 and "BTYPE" set to 1 containing "He";. The rest of the 4th "BFINAL" set to 0 and "BTYPE" set to 01 containing "He". The rest of
octet contains the header bits with "BFINAL" set to 0 and "BTYPE" set the 4th octet contains the header bits with "BFINAL" set to 0 and
to 0, and the 3 padding bits of 0. Together with the following 4 "BTYPE" set to 00, and the 3 padding bits of 0. Together with the
octets (0x00 0x00 0xff 0xff), the header bits consist an empty following 4 octets (0x00 0x00 0xff 0xff), the header bits constitute
DEFLATE block with no compression. A DEFLATE block containing "llo" an empty DEFLATE block with no compression. A DEFLATE block
follows the empty DEFLATE block. containing "llo" follows the empty DEFLATE block.
6.3. Intermediaries 8.3. Implementation Notes
When an intermediary forwards messages, the intermediary MAY add, On most common software development platforms, their DEFLATE
change or remove Per-message Compression on the messages. The compression library provides a method to align compressed data to
elements in the "Sec-WebSocket-Extensions" for the PMCE in the byte boundaries using an empty DEFLATE block with no compression.
opening handshakes with the connected client and server must be For example, Zlib [Zlib] does this when "Z_SYNC_FLUSH" is passed to
altered by the intermediary accordingly to match the new framing. the deflate function.
6.4. Implementation Notes To obtain a useful compression ratio, an LZ77 sliding window size of
1,024 or more is RECOMMENDED.
On most common software development platforms, their DEFLATE On the direction where context takeover is disallowed, an endpoint
compression library provide a method to align compressed data to byte can easily figure out whether a certain message will be shorter if
boundaries using an empty DEFLATE block with no compression. For compressed or not.. Otherwise, it's not easy to know whether future
example, Zlib [Zlib] does this when "Z_SYNC_FLUSH" is passed to the messages will benefit from having a certain message compressed.
deflate function. Implementor may employ some heuristics to determine this.
To attain sufficient compression ratio, the LZ77 sliding window size 8.4. Intermediaries
of 1,024 or more is RECOMMENDED.
7. Security Considerations When an intermediary forwards a message, the intermediary MAY change
compression on the messages as far as the resulting sequence of
messages conform to the constraints based on the "agreed parameters".
For example, an intermediary may decompress a received message, unset
the "Per-message Compressed" bit and forward it to the other peer.
Since such a compression change may affect the LZ77 sliding window,
the intermediary may need to parse and transform the following
messages, too.
9. Security Considerations
There is a known exploit for combination of a secure transport There is a known exploit for combination of a secure transport
protocol and a dictionary based compression [CRIME]. Implementors protocol and history-based compression [CRIME]. Implementors should
should give attention to this point when integrating this extension give attention to this point when integrating this extension with
with other extensions or protocols. other extensions or protocols.
8. IANA Considerations 10. IANA Considerations
8.1. Registration of the "permessage-deflate" WebSocket Extension Name 10.1. Registration of the "permessage-deflate" WebSocket Extension Name
This section describes a WebSocket extension name registration in the This section describes a WebSocket extension name registration in the
WebSocket Extension Name Registry [RFC6455]. WebSocket Extension Name Registry [RFC6455].
Extension Identifier Extension Identifier
permessage-deflate permessage-deflate
Extension Common Name Extension Common Name
WebSocket Per-message Deflate WebSocket Per-message Deflate
Extension Definition Extension Definition
This document. This document.
Known Incompatible Extensions Known Incompatible Extensions
None None
The "permessage-deflate" extension name is used in the The "permessage-deflate" extension name is used in the
"Sec-WebSocket-Extensions" header in the WebSocket opening handshake "Sec-WebSocket-Extensions" header in the WebSocket opening handshake
to negotiate use of the permessage-deflate extension. to negotiate use of the permessage-deflate extension.
8.2. Registration of the "Per-message Compressed" WebSocket Framing 10.2. Registration of the "Per-message Compressed" WebSocket Framing
Header Bit Header Bit
This section describes a WebSocket framing header bit registration in This section describes a WebSocket framing header bit registration in
the WebSocket Framing Header Bits Registry [RFC6455]. the WebSocket Framing Header Bits Registry [RFC6455].
Header Bit Header Bit
RSV1 RSV1
Common Name Common Name
Per-message Compressed Per-message Compressed
Meaning Meaning
The message is compressed or not. The message is compressed or not.
Reference Reference
Section 5 of this document. Section 6 of this document.
The "Per-message Compressed" framing header bit is used on the first The "Per-message Compressed" framing header bit is used on the first
fragment of non-control messages to indicate whether the payload data fragment of non-control messages to indicate whether the payload of
portion of the message is compressed by the PMCE or not. the message is compressed by the PMCE or not.
9. Acknowledgements 11. Acknowledgements
Special thanks to Patrick McManus who wrote up the initial Special thanks to Patrick McManus who wrote up the initial
specification of a DEFLATE-based compression extension for the specification of a DEFLATE-based compression extension for the
WebSocket Protocol to which I referred to write this specification. WebSocket Protocol to which I referred to write this specification.
Thank you to the following people who participated in discussions on Thank you to the following people who participated in discussions on
the HyBi WG and contributed ideas and/or provided detailed reviews the HyBi WG and contributed ideas and/or provided detailed reviews
(the list is likely to be incomplete): Alexey Melnikov, Arman (the list is likely to be incomplete): Adam Rice, Alexey Melnikov,
Djusupov, Bjoern Hoehrmann, Brian McKelvey, Dario Crivelli, Greg Arman Djusupov, Bjoern Hoehrmann, Brian McKelvey, Dario Crivelli,
Wilkins, Inaki Baz Castillo, Jamie Lokier, Joakim Erdfelt, John A. Greg Wilkins, Inaki Baz Castillo, Jamie Lokier, Joakim Erdfelt, John
Tamplin, Julian Reschke, Kenichi Ishibashi, Mark Nottingham, Peter A. Tamplin, Julian Reschke, Kenichi Ishibashi, Mark Nottingham, Peter
Thorson, Roberto Peon and Simone Bordet. Note that people listed Thorson, Roberto Peon and Simone Bordet. Note that people listed
above didn't necessarily endorse the end result of this work. above didn't necessarily endorse the end result of this work.
10. References 12. References
10.1. Normative References 12.1. Normative References
[RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax
Specifications: ABNF", STD 68, RFC 5234, January 2008. Specifications: ABNF", STD 68, RFC 5234, January 2008.
[RFC6455] Fette, I. and A. Melnikov, "The WebSocket Protocol", [RFC6455] Fette, I. and A. Melnikov, "The WebSocket Protocol",
RFC 6455, December 2011. RFC 6455, December 2011.
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
Requirement Levels", BCP 14, RFC 2119, March 1997. Requirement Levels", BCP 14, RFC 2119, March 1997.
[LZ77] Ziv, J. and A. Lempel, "A Universal Algorithm for [LZ77] Ziv, J. and A. Lempel, "A Universal Algorithm for
Sequential Data Compression", IEEE Transactions on Sequential Data Compression", IEEE Transactions on
Information Theory, Vol. 23, No. 3, pp. 337-343. Information Theory, Vol. 23, No. 3, pp. 337-343.
10.2. Informative References 12.2. Informative References
[RFC1951] Deutsch, P., "DEFLATE Compressed Data Format Specification [RFC1951] Deutsch, P., "DEFLATE Compressed Data Format Specification
version 1.3", RFC 1951, May 1996. version 1.3", RFC 1951, May 1996.
[RFC1979] Woods, J., "PPP Deflate Protocol", RFC 1979, August 1996. [RFC1979] Woods, J., "PPP Deflate Protocol", RFC 1979, August 1996.
[Zlib] Gailly, J. and M. Adler, "Zlib", <http://zlib.net/>. [Zlib] Gailly, J. and M. Adler, "Zlib", <http://zlib.net/>.
[CRIME] Rizzo, J. and T. Duong, "The CRIME attack", Ekoparty 2012, [CRIME] Rizzo, J. and T. Duong, "The CRIME attack", Ekoparty 2012,
September 2012. September 2012.
 End of changes. 106 change blocks. 
271 lines changed or deleted 325 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/