draft-ietf-hybi-permessage-compression-28.txt   rfc7692.txt 
HyBi Working Group T. Yoshino Internet Engineering Task Force (IETF) T. Yoshino
Internet-Draft Google, Inc. Request for Comments: 7692 Google, Inc.
Intended status: Standards Track August 24, 2015 Category: Standards Track December 2015
Expires: February 25, 2016 ISSN: 2070-1721
Compression Extensions for WebSocket Compression Extensions for WebSocket
draft-ietf-hybi-permessage-compression-28
Abstract Abstract
This document defines a framework for creating WebSocket extensions This document defines 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 WebSocket data messages on a per-message basis using parameters of WebSocket data messages on a per-message basis using parameters
negotiated during the opening handshake. This framework provides a negotiated during the opening handshake. This framework provides a
general method for applying a compression algorithm to the contents general method for applying a compression algorithm to the contents
of WebSocket messages. Each compression algorithm has to be defined of WebSocket messages. Each compression algorithm has to be defined
in a document defining the extension by specifying parameter in a document defining the extension by specifying the parameter
negotiation and payload transformation algorithm in detail. This negotiation and the payload transformation algorithm in detail. This
document also specifies one specific compression extension using the document also specifies one specific compression extension using the
DEFLATE algorithm. DEFLATE algorithm.
Please send feedback to the hybi@ietf.org mailing list. Status of This Memo
Status of this Memo
This Internet-Draft is submitted to IETF in full conformance with the
provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering This is an Internet Standards Track document.
Task Force (IETF). Note that other groups may also distribute
working documents as Internet-Drafts. The list of current Internet-
Drafts is at http://datatracker.ietf.org/drafts/current.
Internet-Drafts are draft documents valid for a maximum of six months This document is a product of the Internet Engineering Task Force
and may be updated, replaced, or obsoleted by other documents at any (IETF). It represents the consensus of the IETF community. It has
time. It is inappropriate to use Internet-Drafts as reference received public review and has been approved for publication by the
material or to cite them other than as "work in progress." Internet Engineering Steering Group (IESG). Further information on
Internet Standards is available in Section 2 of RFC 5741.
This Internet-Draft will expire on February 25, 2016. Information about the current status of this document, any errata,
and how to provide feedback on it may be obtained at
http://www.rfc-editor.org/info/rfc7692.
Copyright Notice Copyright Notice
Copyright (c) 2015 IETF Trust and the persons identified as the Copyright (c) 2015 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 ........................3
3. Complementary Terminology . . . . . . . . . . . . . . . . . . 5 3. Complementary Terminology .......................................4
4. WebSocket Per-message Compression Extension . . . . . . . . . 6 4. WebSocket Per-Message Compression Extension .....................5
5. Extension Negotiation . . . . . . . . . . . . . . . . . . . . 7 5. Extension Negotiation ...........................................5
5.1. General Negotiation Flow . . . . . . . . . . . . . . . . . 9 5.1. General Negotiation Flow ...................................9
5.2. Negotiation Examples . . . . . . . . . . . . . . . . . . . 10 5.2. Negotiation Examples .......................................9
6. Framing . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 6. Framing ........................................................10
6.1. Compression . . . . . . . . . . . . . . . . . . . . . . . 12 6.1. Compression ...............................................10
6.2. Decompression . . . . . . . . . . . . . . . . . . . . . . 13 6.2. Decompression .............................................12
7. The permessage-deflate extension . . . . . . . . . . . . . . . 15 7. The "permessage-deflate" Extension .............................12
7.1. Extension Parameters . . . . . . . . . . . . . . . . . . . 16 7.1. Extension Parameters ......................................14
7.1.1. Context Takeover Control . . . . . . . . . . . . . . . 16 7.1.1. Context Takeover Control ...........................14
7.1.2. Limiting the LZ77 sliding window size . . . . . . . . 18 7.1.2. Limiting the LZ77 Sliding Window Size ..............16
7.1.3. Examples . . . . . . . . . . . . . . . . . . . . . . . 20 7.1.3. Examples ...........................................18
7.2. Message Payload Transformation . . . . . . . . . . . . . . 21 7.2. Message Payload Transformation ............................19
7.2.1. Compression . . . . . . . . . . . . . . . . . . . . . 21 7.2.1. Compression ........................................19
7.2.2. Decompression . . . . . . . . . . . . . . . . . . . . 22 7.2.2. Decompression ......................................21
7.2.3. Examples . . . . . . . . . . . . . . . . . . . . . . . 23 7.2.3. Examples ...........................................22
7.3. Implementation Notes . . . . . . . . . . . . . . . . . . . 27 7.3. Implementation Notes ......................................25
8. Security Considerations . . . . . . . . . . . . . . . . . . . 28 8. Security Considerations ........................................25
9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 29 9. IANA Considerations ............................................26
9.1. Registration of the "permessage-deflate" WebSocket 9.1. Registration of the "permessage-deflate" WebSocket
Extension Name . . . . . . . . . . . . . . . . . . . . . . 29 Extension Name ............................................26
9.2. Registration of the "Per-message Compressed" WebSocket 9.2. Registration of the "Per-Message Compressed"
Framing Header Bit . . . . . . . . . . . . . . . . . . . . 29 WebSocket Framing Header Bit ..............................26
10. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 30 10. References ....................................................27
11. References . . . . . . . . . . . . . . . . . . . . . . . . . . 31 10.1. Normative References .....................................27
11.1. Normative References . . . . . . . . . . . . . . . . . . . 31 10.2. Informative References ...................................27
11.2. Informative References . . . . . . . . . . . . . . . . . . 31 Acknowledgements ..................................................28
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 32 Author's Address ..................................................28
1. Introduction 1. Introduction
This document specifies a framework for adding compression This document specifies a framework for adding compression
functionality to the WebSocket Protocol [RFC6455]. The framework functionality to the WebSocket Protocol [RFC6455]. The framework
specifies how to define WebSocket Per-message Compression Extensions specifies how to define WebSocket Per-Message Compression Extensions
(PMCEs) for a compression algorithm based on the extension concept of (PMCEs) for a compression algorithm based on the extension concept of
the WebSocket Protocol specified in Section 9 of [RFC6455]. A the WebSocket Protocol specified in Section 9 of [RFC6455]. A
WebSocket client and a peer WebSocket server negotiate the use of a WebSocket client and a peer WebSocket server negotiate the use of a
PMCE and determine the parameters required to configure the PMCE and determine the parameters required to configure the
compression algorithm during the WebSocket opening handshake. The compression algorithm during the WebSocket opening handshake. The
client and server can then exchange data messages whose frames client and server can then exchange data messages whose frames
contain compressed data in the payload data portion. contain compressed data in the payload data portion.
This framework only specifies a general method for applying a This framework only specifies a general method for applying a
compression algorithm to the contents of WebSocket messages. Each compression algorithm to the contents of WebSocket messages. Each
individual PMCE has to be specified in a document describing in individual PMCE has to be specified in a document describing in
detail how to negotiate the configuration parameters for the specific detail how to negotiate the configuration parameters for the specific
compression algorithm used by that PMCE and how to transform compression algorithm used by that PMCE and how to transform
(compress and decompress) data in the payload data portion. (compress and decompress) data in the payload data portion.
A WebSocket client may offer multiple PMCEs during the WebSocket A WebSocket client may offer multiple PMCEs during the WebSocket
opening handshake. A peer WebSocket server receiving the offer may opening handshake. A peer WebSocket server receiving the offer may
choose to accept the preferred PMCE or decline all of them. PMCEs choose to accept the preferred PMCE or decline all of them. PMCEs
use the RSV1 bit of the WebSocket frame header to indicate whether a use the RSV1 bit of the WebSocket frame header to indicate whether a
message is compressed or not, so that an endpoint can choose not to message is compressed or not so that an endpoint can choose not to
compress messages with incompressible contents. compress messages with 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 DEFLATE algorithm is widely available on [RFC1951] algorithm. The DEFLATE algorithm is widely available on
various platforms and its overhead is small. The extension name of various platforms, and its overhead is small. The extension name of
this PMCE is "permessage-deflate". To align the end of compressed this PMCE is "permessage-deflate". To align the end of compressed
data to an octet boundary, this extension uses the algorithm data to an octet boundary, this extension uses the algorithm
described in Section 2.1 of [RFC1979]. Endpoints can take over the described in Section 2.1 of [RFC1979]. Endpoints can take over the
LZ77 sliding window [LZ77] used to build frames for previous messages LZ77 sliding window [LZ77] used to build frames for previous messages
to achieve a better compression ratio. For resource-limited devices, to achieve a better compression ratio. For resource-limited devices,
this extension provides parameters to limit memory usage for this extension provides parameters to limit memory usage for
compression context. compression context.
2. Conformance Requirements and Terminology 2. Conformance Requirements and Terminology
skipping to change at page 4, line 28 skipping to change at page 4, line 17
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_. These events are defined in Section 4.1 and Section 6.2, Received_. These events are defined in Sections 4.1 and 6.2,
respectively, of [RFC6455]. respectively, of [RFC6455].
This document uses the Augmented Backus-Naur Form (ABNF) notation of This document uses the Augmented 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. Complementary Terminology 3. Complementary Terminology
This document defines some terms about WebSocket and WebSocket This document defines some terms about WebSocket and WebSocket
Extension mechanisms that are underspecified or not defined at all in extension mechanisms that are underspecified or not defined at all in
[RFC6455]. [RFC6455].
"A data message" means a message consisting of Data Frames as defined data message - a message consisting of data frames as defined in
in Section 5.6 of [RFC6455]. Section 5.6 of [RFC6455].
"A message payload (or payload of a message)" means the concatenation message payload (or payload of a message) - the concatenation of the
of the payload data portion of all Data Frames (see Section 6.2 of payload data portion of all data frames (see Section 6.2 of
[RFC6455]) representing a single message. [RFC6455]) representing a single message.
"The next extension in use after extension X" means the next next extension in use after extension X - the next extension listed
extension listed after X in the "Sec-WebSocket-Extensions" header in after X in the "Sec-WebSocket-Extensions" header in the server's
the server's opening handshake as defined in Section 9.1 of opening handshake as defined in Section 9.1 of [RFC6455]. Such an
[RFC6455]. Such an extension is applied to outgoing data from the extension is applied to outgoing data from the application right
application right after X on the sender side, but applied right after X on the sender side but is applied right before X to incoming
before X to incoming data from the underlying transport. data from the underlying transport.
"An extension in use preceding extension X" means the extension extension in use preceding extension X - the extension listed right
listed right before X in the "Sec-WebSocket-Extensions" header in the before X in the "Sec-WebSocket-Extensions" header in the server's
server's opening handshake. Such an extension is applied to outgoing opening handshake. Such an extension is applied to outgoing data
data from the application right before X on the sender side, but from the application right before X on the sender side but is applied
applied right after X to incoming data from the underlying transport. right after X to incoming data from the underlying transport.
"An extension negotiation offer" means each element in the extension negotiation offer - each element in the "Sec-WebSocket-
"Sec-WebSocket-Extensions" header in the client's opening handshake. Extensions" header in the client's opening handshake.
"An extension negotiation response" means each element in the extension negotiation response - each element in the "Sec-WebSocket-
"Sec-WebSocket-Extensions" header in the server's opening handshake. Extensions" header in the server's opening handshake.
"A corresponding extension negotiation response for an extension corresponding extension negotiation response for an extension
negotiation offer" means an extension negotiation response that a negotiation offer - an extension negotiation response that a server
server sends back to the peer client containing the same extension sends back to the peer client containing the same extension name as
name as the offer and meeting the requirements represented by the the offer and meeting the requirements represented by the offer.
offer.
"Accepting an extension negotiation offer" means including a Accepting an extension negotiation offer - including a corresponding
corresponding extension negotiation response for the offer in the extension negotiation response for the offer in the "Sec-WebSocket-
"Sec-WebSocket-Extensions" header in the server's opening handshake. Extensions" header in the server's opening handshake.
"Declining an extension negotiation offer" means not including a Declining an extension negotiation offer - not including a
corresponding extension negotiation response for the offer in the corresponding extension negotiation response for the offer in the
"Sec-WebSocket-Extensions" header in the server's opening handshake. "Sec-WebSocket-Extensions" header in the server's opening handshake.
4. WebSocket Per-message Compression Extension 4. WebSocket Per-Message Compression Extension
WebSocket Per-message Compression Extensions (PMCEs) are extensions WebSocket PMCEs are extensions to the WebSocket Protocol enabling
to the WebSocket Protocol enabling compression functionality. PMCEs compression functionality. PMCEs are built based on the extension
are built based on the extension concept of the WebSocket Protocol concept of the WebSocket Protocol specified in Section 9 of
specified in Section 9 of [RFC6455]. PMCEs are individually defined [RFC6455]. PMCEs are individually defined for each compression
for each compression algorithm to be implemented, and are registered algorithm to be implemented and are registered in the "WebSocket
in the WebSocket Extension Name Registry created in Section 11.4 of Extension Name Registry" created in Section 11.4 of [RFC6455]. Each
[RFC6455]. Each PMCE referring to this framework MUST define the PMCE referring to this framework MUST define the following:
following:
o The extension name of the PMCE and any applicable extension o The extension name of the PMCE and any applicable extension
parameters that MUST be included in the "Sec-WebSocket-Extensions" parameters that MUST be included in the "Sec-WebSocket-Extensions"
header during the extension negotiation offer/response. header during the extension negotiation offer/response.
o How to interpret the extension parameters exchanged during the o How to interpret the extension parameters exchanged during the
opening handshake. opening handshake.
o How to transform the payload of a message. o How to transform the payload of a message.
skipping to change at page 7, line 50 skipping to change at page 6, line 44
A hint in a PMCE negotiation offer provides information about the A hint in a PMCE negotiation offer provides information about the
client's behavior that the server may either safely ignore or refer client's behavior that the server may either safely ignore or refer
to when the server decides its behavior. For example, suppose that a to when the server decides its behavior. For example, suppose that a
client sends data compressed with the DEFLATE algorithm to a server. client sends data compressed with the DEFLATE algorithm to a server.
The client must keep the original bytes of data that it recently The client must keep the original bytes of data that it recently
compressed and sent to the server. The server must keep the result compressed and sent to the server. The server must keep the result
of decompressing the bytes of data that it recently received from the of decompressing the bytes of data that it recently received from the
client. The LZ77 window size of the server must not be less than the client. The LZ77 window size of the server must not be less than the
LZ77 window size of the client. In a PMCE negotiation offer, the LZ77 window size of the client. In a PMCE negotiation offer, the
client MAY inform the maximum LZ77 window size the client can afford client MAY inform the server of the maximum LZ77 window size the
so that the server can choose to use an LZ77 window size that is not client can afford so that the server can choose to use an LZ77 window
greater than the maximum size of the client. This information is an size that is not greater than the maximum size of the client. This
example of a hint in a PMCE negotiation offer. It's waste of memory information is an example of a hint in a PMCE negotiation offer.
to use an LZ77 window size greater than the LZ77 window size the It's waste of memory to use an LZ77 window size greater than the LZ77
client actually uses. Using the hint, the server can avoid the waste window size the client actually uses. Using the hint, the server can
of memory. Since the hint itself doesn't specify the constraints on avoid the waste of memory. Since the hint itself doesn't specify the
the endpoints, the server must use the "agreed parameters" (defined constraints on the endpoints, the server must use the "agreed
below) to explicitly ask the client not to use an LZ77 window size parameters" (defined below) to explicitly ask the client not to use
greater than the LZ77 window size of the server. an LZ77 window size greater than the LZ77 window size of the server.
To accept the use of an offered PMCE, a server MUST include the To accept the use of an offered PMCE, a server MUST include the
extension name of the PMCE in the "Sec-WebSocket-Extensions" header extension name of the PMCE in the "Sec-WebSocket-Extensions" header
field of its opening handshake of the WebSocket connection. field of its opening handshake of the WebSocket connection.
Extension parameters represent the detailed configuration parameters Extension parameters represent the detailed configuration parameters
of the PMCE to use. These extension parameters and their values are for the PMCE to use. These extension parameters and their values are
called "agreed parameters". The element MUST represent a PMCE that called "agreed parameters". The element MUST represent a PMCE that
is fully supported by the server. The contents of the element don't is fully supported by the server. The contents of the element don't
need to be exactly the same as those of the received extension need to be exactly the same as those of the received extension
negotiation offers. For example, suppose that a server received a negotiation offers. For example, suppose that a server received a
PMCE extension negotiation offer with an extension parameter "X" PMCE extension negotiation offer with an extension parameter "X"
indicating that the client can enable an optional feature named X. indicating that the client can enable an optional feature named X.
The server may accept the PMCE offer with an element without the The server may accept the PMCE offer with an element without the
extension parameter "X" meaning that the server chose not to enable extension parameter "X", meaning that the server chose not to enable
the feature X. In this case, the offer contains the extension the feature X. In this case, the offer contains the extension
parameter "X" but the "agreed parameters" don't contain the extension parameter "X", but the "agreed parameters" don't contain the
parameter "X". extension parameter "X".
"Agreed parameters" must represent how the requests and hints in the "Agreed parameters" must represent how the requests and hints in the
client's extension negotiation offer have been handled in addition to client's extension negotiation offer have been handled in addition to
the server's requests and hints on the client's behavior, so that the the server's requests and hints on the client's behavior, so that the
client can configure its behavior without identifying exactly which client can configure its behavior without identifying exactly which
PMCE extension negotiation offer has been accepted. PMCE extension negotiation offer has been accepted.
For example, if a client sends an extension negotiation offer that For example, if a client sends an extension negotiation offer that
includes a parameter "enable_compression" and another without this includes a parameter "enable_compression" and another without this
parameter, the server accepts the former and informs the client by parameter, the server accepts the former and informs the client by
sending back an element that includes parameter(s) acknowledging sending back an element that includes parameter(s) acknowledging
"enable_compression". The name of the acknowledging parameter "enable_compression". The name of the acknowledging parameter
doesn't need to be exactly the same as the offer. For example, two doesn't need to be exactly the same as the offer. For example, two
parameters "enable_strong_compression" and "enable_weak_compression" parameters, "enable_strong_compression" and
may be defined as acknowledging parameters for "enable_compression". "enable_weak_compression", may be defined as acknowledging parameters
for "enable_compression".
Compression features can be applied differently for each direction. Compression features can be applied differently for each direction.
For such features, the acknowledging parameter and the parameter in For such features, the acknowledging parameter and the parameter in
the reverse direction must be chosen to distinguish them. For the reverse direction must be chosen to distinguish them. For
example, in order to make parameters distinguishable, a "server_" example, in order to make parameters distinguishable, a "server_"
prefix can be added to parameters affecting data sent from a server prefix can be added to parameters affecting data sent from a server,
and a "client_" prefix can be added to parameters affecting data sent and a "client_" prefix can be added to parameters affecting data sent
from a client. from a client.
A server MUST NOT accept a PMCE extension negotiation offer together A server MUST NOT accept a PMCE extension negotiation offer together
with another extension if the PMCE will conflict with the extension with another extension if the PMCE will conflict with the extension
on their use of the RSV1 bit. A client that received a response on their use of the RSV1 bit. A client that received a response
accepting a PMCE extension negotiation offer together with such an accepting a PMCE extension negotiation offer together with such an
extension MUST _Fail the WebSocket Connection_. extension MUST _Fail the WebSocket Connection_.
A server MUST NOT accept a PMCE extension negotiation offer together A server MUST NOT accept a PMCE extension negotiation offer together
skipping to change at page 9, line 30 skipping to change at page 8, line 30
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 a per-frame attribute. reserved bits on the WebSocket header as a per-frame attribute.
A client that receives a response accepting a PMCE extension A client that receives a response accepting a PMCE extension
negotiation offer together with such an extension MUST _Fail the negotiation offer together with such an extension MUST _Fail the
WebSocket Connection_. WebSocket Connection_.
A server declining all offered PMCEs MUST NOT include any element A server declining all offered PMCEs MUST NOT include any element
with PMCE names. If a server responds with no PMCE element in the with 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-
"Sec-WebSocket-Extensions" header and _the WebSocket Connection is Extensions" header and _the WebSocket Connection is established_,
established_, both endpoints MUST use the algorithm described in both endpoints MUST use the algorithm described in Section 6 and the
Section 6 and the message payload transformation (compressing and message payload transformation (compressing and decompressing)
decompressing) procedure of the PMCE configured with the "agreed procedure of the PMCE configured with the "agreed parameters"
parameters" returned by the server to exchange messages. returned by the server to exchange messages.
5.1. General Negotiation Flow 5.1. General Negotiation Flow
This section describes a general negotiation flow. How to handle This section describes a general negotiation flow. How to handle
parameters in detail must be specified in the document specifying the parameters in detail must be specified in the document specifying the
PMCE. PMCE.
A client makes an offer including parameters identifying the A client makes an offer including parameters identifying the
following: following:
skipping to change at page 10, line 22 skipping to change at page 9, line 31
parameters. If the server can and wants to proceed with this PMCE parameters. If the server can and wants to proceed with this PMCE
enabled, the server responds to the client with parameters enabled, the server responds to the client with parameters
identifying the following: identifying the following:
o Requests about how the client compresses data o Requests about how the client compresses data
o How the server will compress data o How the server will compress data
Based on these parameters received from the server, the client Based on these parameters received from the server, the client
determines its behavior and if it can and wants to proceed with this determines its behavior and if it can and wants to proceed with this
PMCE enabled. Otherwise, the client starts closing handshake with PMCE enabled. Otherwise, the client starts the closing handshake
close code 1010. with close code 1010.
5.2. Negotiation Examples 5.2. Negotiation Examples
The following are example values for the "Sec-WebSocket-Extensions" The following 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 the
algorithm foo and bar. compression algorithm foo and bar.
o Offer the permessage-foo. o Offer the permessage-foo.
permessage-foo permessage-foo
o Offer the permessage-foo with a parameter x with a value of 10. o Offer the permessage-foo with a parameter x with a value of 10.
permessage-foo; x=10 permessage-foo; x=10
The value may be quoted. The value may be quoted.
permessage-foo; x="10" permessage-foo; x="10"
o Offer the permessage-foo as first choice and the permessage-bar as o Offer the permessage-foo as first choice and the permessage-bar as
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
6. Framing 6. Framing
PMCEs operate only on data messages. PMCEs operate only on data messages.
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 a "compressed message". Frames of fragment of the message is called a "compressed message". Frames of
a compressed message have compressed data in the payload data a compressed message have compressed data in the payload data
portion. An endpoint receiving 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 decompression 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 an "uncompressed message". Frames fragment of the message is called an "uncompressed message". Frames
of an uncompressed message have uncompressed original data as-is in of an uncompressed message have uncompressed original data as is in
the payload data portion. An endpoint receiving an uncompressed the payload data portion. An endpoint receiving an uncompressed
message uses the concatenation of the application data portion of the message uses the concatenation of the application data portion of the
frames of the message as-is for the _A WebSocket Message Has Been frames of the message as is for the _A WebSocket Message Has Been
Received_ event. Received_ event.
6.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 message payload of the original message by following 1. Compress the message payload of the original message by following
the compression procedure of the PMCE. The original message may the compression procedure of the PMCE. The original message may
be input from the application layer or output of another be input from the application layer or output of another
WebSocket extension depending on which extensions were WebSocket extension, depending on which extensions were
negotiated. negotiated.
2. Process the compressed data as follows: 2. Process the compressed data as follows:
* If this PMCE is the last extension to process of outgoing * If this PMCE is the last extension to process outgoing
messages, build frame(s) by using the compressed data instead messages, build frame(s) using the compressed data instead of
of the original data for the message payload, and set the the original data for the message payload, set the "Per-
"Per-message Compressed" bit of the first frame, then send the Message Compressed" bit of the first frame, and then send the
frame(s) as described in Section 6.1 of RFC6455. frame(s) as described in Section 6.1 of [RFC6455].
* Otherwise, pass the transformed message payload and modified * Otherwise, pass the transformed message payload and modified
header values including the "Per-message Compressed" bit value header values, including the "Per-Message Compressed" bit
set to 1 to the next extension after the PMCE. If the value set to 1, to the next extension after the PMCE. If the
extension expects frames for input, build a frame for the extension expects frames for input, build a frame for the
message and pass it. 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. form of an uncompressed message.
1. Process the original data as follows: 1. Process the original data as follows:
* If this PMCE is the last extension to process of outgoing * If this PMCE is the last extension to process outgoing
messages, build frame(s) by using the original data for the messages, build frame(s) using the original data for the
payload data portion as-is and unset the "Per-message payload data portion as is, unset the "Per-Message Compressed"
Compressed" bit of the first frame, then send the frame(s) as bit of the first frame, and then send the frame(s) as
described in Section 6.1 of RFC6455. described in Section 6.1 of [RFC6455].
* Otherwise, pass the message payload and header values to the * Otherwise, pass the message payload and header values to the
next extension after the PMCE as-is. If the extension expects next extension after the PMCE as is. If the extension expects
frames for input, build a frame for the message and pass it. frames for 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
receiving such a frame MUST _Fail the WebSocket Connection_. receiving such a frame MUST _Fail the WebSocket Connection_.
PMCEs do not change the opcode field. The opcode of the first frame PMCEs do not change the opcode field. The opcode of the first frame
of a compressed message indicates the opcode of the original message. of a compressed 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 output data corresponding to the application concatenation of the output data corresponding to the application
data portion of frames of a compressed text message is not required data portion of frames of a compressed text message is not required
skipping to change at page 13, line 46 skipping to change at page 12, line 13
type again. type again.
6.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 be direct input the compressed message. The received frames may be direct input
from the underlying transport or output of another WebSocket from the underlying transport or output of another WebSocket
extension depending on which extensions were negotiated. extension, depending on which 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. Process the decompressed message as follows: 3. Process the decompressed message as follows:
* If this is the last extension to process incoming messages, * If this is the last extension to process incoming messages,
deliver the _A WebSocket Message Has Been Received_ event to deliver the _A WebSocket Message Has Been Received_ event to
the application layer with the decompressed message payload the application layer with the decompressed message payload
and header values including the "Per-message Compressed" bit and header values, including the "Per-Message Compressed" bit
unset to 0. unset to 0.
* Otherwise, pass the decompressed message payload and header * Otherwise, pass the decompressed message payload and header
values including the "Per-message Compressed" bit unset to 0 values, including the "Per-Message Compressed" bit unset to 0,
to the extension preceding the PMCE. If the extension expects to the extension preceding the PMCE. If the extension expects
frames for input, build a frame for the message and pass it. frames for 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. the form of an uncompressed message.
1. Process the received message as follows: 1. Process the received message as follows:
* If this PMCE is the last extension to process incoming * If this PMCE is the last extension to process incoming
messages, deliver the _A WebSocket Message Has Been Received_ messages, deliver the _A WebSocket Message Has Been Received_
event to the application layer with the received message event to the application layer with the received message
payload and header values as-is. payload and header values as is.
* Otherwise, pass the message payload and header values to the * Otherwise, pass the message payload and header values to the
extension preceding the PMCE as-is. If the extension expects extension preceding the PMCE as is. If the extension expects
frames for input, build a frame for the message and pass it. frames for input, build a frame for the message and pass it.
7. The permessage-deflate extension 7. The "permessage-deflate" Extension
This section defines a specific PMCE called "permessage-deflate". It This section defines a specific PMCE called "permessage-deflate". It
compresses the payload of a message using the DEFLATE algorithm compresses the payload of a message using the DEFLATE algorithm
[RFC1951] and uses the byte boundary alignment method introduced in [RFC1951] and uses the byte boundary alignment method introduced in
[RFC1979]. [RFC1979].
This section uses the term "byte" with the same meaning as RFC1951, This section uses the term "byte" with the same meaning as used in
i.e. 8 bits stored or transmitted as a unit (same as an octet). [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-
"permessage-deflate". deflate".
Four extension parameters are defined for "permessage-deflate" to Four extension parameters are defined for "permessage-deflate" to
help endpoints manage per-connection resource usage. help endpoints manage per-connection resource usage.
o "server_no_context_takeover" o "server_no_context_takeover"
o "client_no_context_takeover" o "client_no_context_takeover"
o "server_max_window_bits" o "server_max_window_bits"
skipping to change at page 16, line 29 skipping to change at page 14, line 22
with the same name. with the same name.
o The client does not support the configuration that the response o The client does not support the configuration that the response
represents. represents.
The term "LZ77 sliding window" [LZ77] used in this section means the The term "LZ77 sliding window" [LZ77] used in this section means the
buffer used by the DEFLATE algorithm to store recently processed buffer used by the DEFLATE algorithm to store recently processed
input. The DEFLATE compression algorithm searches the buffer for a input. The DEFLATE compression algorithm searches the buffer for a
match with the following input. match with the following input.
The term "use context take over" used in this section means that the The term "use context takeover" used in this section means that the
same LZ77 sliding window used by the endpoint to build frames of the same LZ77 sliding window used by the endpoint to build frames of the
previous sent message is reused to build frames of the next message previous sent message is reused to build frames of the next message
to be sent. to be sent.
7.1. Extension Parameters 7.1. Extension Parameters
7.1.1. Context Takeover Control 7.1.1. Context Takeover Control
7.1.1.1. The server_no_context_takeover extension parameter 7.1.1.1. The "server_no_context_takeover" Extension Parameter
A client MAY include the "server_no_context_takeover" extension A client MAY include the "server_no_context_takeover" extension
parameter in an extension negotiation offer. This extension parameter in an extension negotiation offer. This extension
parameter has no value. By including this extension parameter in an parameter has no value. By including this extension parameter in an
extension negotiation offer, a client prevents the peer server from extension negotiation offer, a client prevents the peer server from
using context take over. If the peer server doesn't use context take using context takeover. If the peer server doesn't use context
over, the client doesn't need to reserve memory to retain the LZ77 takeover, the client doesn't need to reserve memory to retain the
sliding window between messages. LZ77 sliding window between messages.
Absence of this extension parameter in an extension negotiation offer Absence of this extension parameter in an extension negotiation offer
indicates that the client can decompress a message which the server indicates that the client can decompress a message that the server
built using context take over. built using context takeover.
A server accepts an extension negotiation offer that includes the A server accepts an extension negotiation offer that includes the
"server_no_context_takeover" extension parameter by including the "server_no_context_takeover" extension parameter by including the
"server_no_context_takeover" extension parameter in the corresponding "server_no_context_takeover" extension parameter in the corresponding
extension negotiation response to send back to the client. The extension negotiation response to send back to the client. The
"server_no_context_takeover" extension parameter in an extension "server_no_context_takeover" extension parameter in an extension
negotiation response has no value. negotiation response has no value.
It is RECOMMENDED that a server supports the It is RECOMMENDED that a server supports the
"server_no_context_takeover" extension parameter in an extension "server_no_context_takeover" extension parameter in an extension
negotiation offer. negotiation offer.
A server MAY include the "server_no_context_takeover" extension A server MAY include the "server_no_context_takeover" extension
parameter in an extension negotiation response even if the extension parameter in an extension negotiation response even if the extension
negotiation offer being accepted by the extension negotiation negotiation offer being accepted by the extension negotiation
response didn't include the "server_no_context_takeover" extension response didn't include the "server_no_context_takeover" extension
parameter. parameter.
7.1.1.2. The client_no_context_takeover extension parameter 7.1.1.2. The "client_no_context_takeover" Extension Parameter
A client MAY include the "client_no_context_takeover" extension A client MAY include the "client_no_context_takeover" extension
parameter in an extension negotiation offer. This extension parameter in an extension negotiation offer. This extension
parameter has no value. By including this extension parameter in an parameter has no value. By including this extension parameter in an
extension negotiation offer, a client informs the peer server of a extension negotiation offer, a client informs the peer server of a
hint that even if the server doesn't include the hint that even if the server doesn't include the
"client_no_context_takeover" extension parameter in the corresponding "client_no_context_takeover" extension parameter in the corresponding
extension negotiation response to the offer, the client is not going extension negotiation response to the offer, the client is not going
to use context take over. to use context takeover.
A server MAY include the "client_no_context_takeover" extension A server MAY include the "client_no_context_takeover" extension
parameter in an extension negotiation response. If the received parameter in an extension negotiation response. If the received
extension negotiation offer includes the "client_no_context_takeover" extension negotiation offer includes the "client_no_context_takeover"
extension parameter, the server may either ignore the parameter or extension parameter, the server may either ignore the parameter or
use the parameter to avoid taking over the LZ77 sliding window use the parameter to avoid taking over the LZ77 sliding window
unnecessarily by including the "client_no_context_takeover" extension unnecessarily by including the "client_no_context_takeover" extension
parameter in the corresponding extension negotiation response to the parameter in the corresponding extension negotiation response to the
offer. The "client_no_context_takeover" extension parameter in an offer. The "client_no_context_takeover" extension parameter in an
extension negotiation response has no value. By including the extension negotiation response has no value. By including the
"client_no_context_takeover" extension parameter in an extension "client_no_context_takeover" extension parameter in an extension
negotiation response, a server prevents the peer client from using negotiation response, a server prevents the peer client from using
context take over. This reduces the amount of memory that the server context takeover. This reduces the amount of memory that the server
has to reserve for the connection. has to reserve for the connection.
Absence of this extension parameter in an extension negotiation Absence of this extension parameter in an extension negotiation
response indicates that the server can decompress messages built by response indicates that the server can decompress messages built by
the client using context take over. the client using context takeover.
A client MUST support the "client_no_context_takeover" extension A client MUST support the "client_no_context_takeover" extension
parameter in an extension negotiation response. parameter in an extension negotiation response.
7.1.2. Limiting the LZ77 sliding window size 7.1.2. Limiting the LZ77 Sliding Window Size
7.1.2.1. The server_max_window_bits extension parameter 7.1.2.1. The "server_max_window_bits" Extension Parameter
A client MAY include the "server_max_window_bits" extension parameter A client MAY include the "server_max_window_bits" extension parameter
in an extension negotiation offer. This parameter has a decimal in an extension negotiation offer. This parameter has a decimal
integer value without leading zeroes between 8 to 15 inclusive integer value without leading zeroes between 8 to 15, inclusive,
indicating the base-2 logarithm of the LZ77 sliding window size and indicating the base-2 logarithm of the LZ77 sliding window size, and
MUST conform to the ABNF below. MUST conform to the ABNF below.
server_max_window_bits = 1*DIGIT server-max-window-bits = 1*DIGIT
By including this parameter in an extension negotiation offer, a By including this parameter in an extension negotiation offer, a
client limits the LZ77 sliding window size that the server will use client limits the LZ77 sliding window size that the server will use
to compress messages. If the peer server uses a small LZ77 sliding to compress messages. If the peer server uses a small LZ77 sliding
window to compress messages, the client can reduce the memory needed window to compress messages, the client can reduce the memory needed
for the LZ77 sliding window. for the LZ77 sliding window.
A server declines an extension negotiation offer with this parameter A server declines an extension negotiation offer with this parameter
if the server doesn't support it. if the server doesn't support it.
Absence of this parameter in an extension negotiation offer indicates Absence of this parameter in an extension negotiation offer indicates
that the client can receive messages compressed using an LZ77 sliding that the client can receive messages compressed using an LZ77 sliding
window of up to 32,768 bytes. window of up to 32,768 bytes.
A server accepts an extension negotiation offer with this parameter A server accepts an extension negotiation offer with this parameter
by including the "server_max_window_bits" extension parameter in the by including the "server_max_window_bits" extension parameter in the
extension negotiation response to send back to the client with the extension negotiation response to send back to the client with the
same or smaller value as the offer. The "server_max_window_bits" same or smaller value as the offer. The "server_max_window_bits"
extension parameter in an extension negotiation response has a extension parameter in an extension negotiation response has a
decimal integer value without leading zeroes between 8 to 15 decimal integer value without leading zeroes between 8 to 15,
inclusive indicating the base-2 logarithm of the LZ77 sliding window inclusive, indicating the base-2 logarithm of the LZ77 sliding window
size and MUST conform to the ABNF below. size, and MUST conform to the ABNF below.
server_max_window_bits = 1*DIGIT server-max-window-bits = 1*DIGIT
A server MAY include the "server_max_window_bits" extension parameter A server MAY include the "server_max_window_bits" extension parameter
in an extension negotiation response even if the extension in an extension negotiation response even if the extension
negotiation offer being accepted by the response didn't include the negotiation offer being accepted by the response didn't include the
"server_max_window_bits" extension parameter. "server_max_window_bits" extension parameter.
7.1.2.2. The client_max_window_bits extension parameter 7.1.2.2. The "client_max_window_bits" Extension Parameter
A client MAY include the "client_max_window_bits" extension parameter A client MAY include the "client_max_window_bits" extension parameter
in an extension negotiation offer. This parameter has no value or a in an extension negotiation offer. This parameter has no value or a
decimal integer value without leading zeroes between 8 to 15 decimal integer value without leading zeroes between 8 to 15
inclusive indicating the base-2 logarithm of the LZ77 sliding window inclusive indicating the base-2 logarithm of the LZ77 sliding window
size. If a value is specified for this parameter, the value MUST size. If a value is specified for this parameter, the value MUST
conform to the ABNF below. conform to the ABNF below.
client_max_window_bits = 1*DIGIT client-max-window-bits = 1*DIGIT
By including this parameter in an offer, a client informs the peer By including this parameter in an offer, a client informs the peer
server that the client supports the "client_max_window_bits" server that the client supports the "client_max_window_bits"
extension parameter in an extension negotiation response, and extension parameter in an extension negotiation response and,
optionally a hint by attaching a value to the parameter. If the optionally, a hint by attaching a value to the parameter. If the
"client_max_window_bits" extension parameter in an extension "client_max_window_bits" extension parameter in an extension
negotiation offer has a value, the parameter also informs the peer negotiation offer has a value, the parameter also informs the peer
server of a hint that even if the server doesn't include the server of a hint that even if the server doesn't include the
"client_max_window_bits" extension parameter in the corresponding "client_max_window_bits" extension parameter in the corresponding
extension negotiation response with a value greater than the one in extension negotiation response with a value greater than the one in
the extension negotiation offer or the server doesn't include the the extension negotiation offer or if the server doesn't include the
extension parameter at all, the client is not going to use an LZ77 extension parameter at all, the client is not going to use an LZ77
sliding window size greater than the size specified by the value in sliding window size greater than the size specified by the value in
the extension negotiation offer to compress messages. the extension negotiation offer to compress messages.
If a received extension negotiation offer has the If a received extension negotiation offer has the
"client_max_window_bits" extension parameter, the server MAY include "client_max_window_bits" extension parameter, the server MAY include
the "client_max_window_bits" extension parameter in the corresponding the "client_max_window_bits" extension parameter in the corresponding
extension negotiation response to the offer. If the extension negotiation response to the offer. If the
"client_max_window_bits" extension parameter in a received extension "client_max_window_bits" extension parameter in a received extension
negotiation offer has a value, the server may either ignore this negotiation offer has a value, the server may either ignore this
value or use this value to avoid allocating an unnecessarily big LZ77 value or use this value to avoid allocating an unnecessarily big LZ77
sliding window by including the "client_max_window_bits" extension sliding window by including the "client_max_window_bits" extension
parameter in the corresponding extension negotiation response to the parameter in the corresponding extension negotiation response to the
offer with a value equal to or smaller than the received value. The offer with a value equal to or smaller than the received value. The
"client_max_window_bits" extension parameter in an extension "client_max_window_bits" extension parameter in an extension
negotiation response has a decimal integer value without leading negotiation response has a decimal integer value without leading
zeroes between 8 to 15 inclusive indicating the base-2 logarithm of zeroes between 8 to 15 inclusive indicating the base-2 logarithm of
the LZ77 sliding window size and MUST conform to the ABNF below. the LZ77 sliding window size and MUST conform to the ABNF below.
client_max_window_bits = 1*DIGIT client-max-window-bits = 1*DIGIT
By including this extension parameter in an extension negotiation By including this extension parameter in an extension negotiation
response, a server limits the LZ77 sliding window size that the response, a server limits the LZ77 sliding window size that the
client uses to compress messages. This reduces the amount of memory client uses to compress messages. This reduces the amount of memory
for the decompression context that the server has to reserve for the for the decompression context that the server has to reserve for the
connection. connection.
If a received extension negotiation offer doesn't have the If a received extension negotiation offer doesn't have the
"client_max_window_bits" extension parameter, the corresponding "client_max_window_bits" extension parameter, the corresponding
extension negotiation response to the offer MUST NOT include the extension negotiation response to the offer MUST NOT include the
"client_max_window_bits" extension parameter. "client_max_window_bits" extension parameter.
Absence of this extension parameter in an extension negotiation Absence of this extension parameter in an extension negotiation
response indicates that the server can receive messages compressed response indicates that the server can receive messages compressed
using an LZ77 sliding window of up to 32,768 bytes. using an LZ77 sliding window of up to 32,768 bytes.
7.1.3. Examples 7.1.3. Examples
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 extension looks like handshake to offer use of the "permessage-deflate" extension looks
this: like this:
Sec-WebSocket-Extensions: permessage-deflate Sec-WebSocket-Extensions: permessage-deflate
Since the "client_max_window_bits" extension parameter is not Since the "client_max_window_bits" extension parameter is not
included in this extension negotiation offer, the server must not included in this extension negotiation offer, the server must not
accept the offer with an extension negotiation response that includes accept the offer with an extension negotiation response that includes
the "client_max_window_bits" extension parameter. The simplest the "client_max_window_bits" extension parameter. The simplest "Sec-
"Sec-WebSocket-Extensions" header in a server's opening handshake to WebSocket-Extensions" header in a server's opening handshake to
accept use of the permessage-deflate extension is the same: accept use of the "permessage-deflate" extension is the same:
Sec-WebSocket-Extensions: permessage-deflate Sec-WebSocket-Extensions: permessage-deflate
The following extension negotiation offer sent by a client is asking The following extension negotiation offer sent by a client is asking
the server to use an LZ77 sliding window with a size of 1,024 bytes the server to use an LZ77 sliding window with a size of 1,024 bytes
or less and declaring that the client supports the or less and declaring that the client supports the
"client_max_window_bits" extension parameter in an extension "client_max_window_bits" extension parameter in an extension
negotiation response. negotiation response.
Sec-WebSocket-Extensions: Sec-WebSocket-Extensions:
skipping to change at page 20, line 48 skipping to change at page 19, line 5
window but wants to fall back to the "permessage-deflate" without the window but wants to fall back to the "permessage-deflate" without the
"server_max_window_bits" extension parameter, the client can make an "server_max_window_bits" extension parameter, the client can make an
offer with the fallback option like this: offer with the fallback option like this:
Sec-WebSocket-Extensions: Sec-WebSocket-Extensions:
permessage-deflate; permessage-deflate;
client_max_window_bits; server_max_window_bits=10, client_max_window_bits; server_max_window_bits=10,
permessage-deflate; permessage-deflate;
client_max_window_bits client_max_window_bits
The server can accept permessage-deflate by picking any supported one The server can accept "permessage-deflate" by picking any supported
from the listed offers. To accept the first option, for example, the one from the listed offers. To accept the first option, for example,
server may send back a response as follows: the server may send back a response as follows:
Sec-WebSocket-Extensions: Sec-WebSocket-Extensions:
permessage-deflate; server_max_window_bits=10 permessage-deflate; server_max_window_bits=10
To accept the second option, for example, the server may send back a To accept the second option, for example, the server may send back a
response as follows: response as follows:
Sec-WebSocket-Extensions: permessage-deflate Sec-WebSocket-Extensions: permessage-deflate
7.2. Message Payload Transformation 7.2. Message Payload Transformation
skipping to change at page 23, line 24 skipping to change at page 21, line 36
the server MUST decompress each new message using the LZ77 sliding the server MUST decompress each new message using the LZ77 sliding
window used to process the last compressed message if the "agreed window used to process the last compressed message if the "agreed
parameters" don't contain the "client_no_context_takeover" extension parameters" don't contain the "client_no_context_takeover" extension
parameter. The client-to-server "client_no_context_takeover" parameter. The client-to-server "client_no_context_takeover"
extension parameter is just a hint for the server to build an extension parameter is just a hint for the server to build an
extension negotiation response. extension negotiation response.
If the "agreed parameters" contain the "server_max_window_bits" If the "agreed parameters" contain the "server_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
byte LZ77 sliding window to decompress received messages. 32,768-byte LZ77 sliding window to decompress received messages.
If the "agreed parameters" contain the "client_max_window_bits" If the "agreed parameters" contain the "client_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
byte LZ77 sliding window to decompress received messages. Note that 32,768-byte LZ77 sliding window to decompress received messages.
even if the client has included in its offer the Note that even if the client has included in its offer the
"client_max_window_bits" extension parameter with a value smaller "client_max_window_bits" extension parameter with a value smaller
than one in the "agreed parameters", the client MUST use an LZ77 than one in the "agreed parameters", the client MUST use an LZ77
sliding window of a size that conforms the "agreed parameters" to sliding window of a size that conforms the "agreed parameters" to
compress messages to send. The client-to-server compress messages to send. The client-to-server
"client_max_window_bits" extension parameter is just a hint for the "client_max_window_bits" extension parameter is just a hint for the
server to build an extension negotiation response. server to build an extension negotiation response.
7.2.3. Examples 7.2.3. Examples
This section introduces examples of how the permessage-deflate This section introduces examples of how the "permessage-deflate"
extension transforms messages. extension transforms messages.
7.2.3.1. A message compressed using 1 compressed DEFLATE block 7.2.3.1. A Message Compressed Using One 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 one compressed DEFLATE block (compressed with fixed
Huffman code and the "BFINAL" bit not set) to compress the message, Huffman code and the "BFINAL" bit not set) to compress the message,
the endpoint obtains the compressed data to use for the message the endpoint obtains the compressed data to use for the message
payload as follows. payload as follows.
The endpoint compresses "Hello" into 1 compressed DEFLATE block and The endpoint compresses "Hello" into one 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 use for the message payload: 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 all of the
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,
RSV1=1, RSV2=0, RSV3=0, opcode=text, MASK=0, Payload length=7). The RSV1=1, RSV2=0, RSV3=0, opcode=text, MASK=0, Payload length=7). The
following figure shows what value is set in each field of the following figure shows what value is set in each field of the
WebSocket frame header. WebSocket frame header.
0 1 0 1
skipping to change at page 24, line 41 skipping to change at page 23, line 8
|I|S|S|S| |A| | |I|S|S|S| |A| |
|N|V|V|V| |S| | |N|V|V|V| |S| |
| |1|2|3| |K| | | |1|2|3| |K| |
+-+-+-+-+-------+-+-------------+ +-+-+-+-+-------+-+-------------+
|1|1|0|0| 1 |0| 7 | |1|1|0|0| 1 |0| 7 |
+-+-+-+-+-------+-+-------------+ +-+-+-+-+-------+-+-------------+
Suppose that the endpoint sends the compressed message with Suppose that the endpoint sends the compressed message with
fragmentation. The endpoint splits the compressed data into fragmentation. The endpoint splits the compressed data into
fragments and builds frames for each fragment. For example, if the fragments and builds frames for each fragment. For example, if the
fragments are 3 and 4 octet, the first frame is: fragments are 3 and 4 octets, 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.
7.2.3.2. Sharing LZ77 Sliding Window 7.2.3.2. Sharing LZ77 Sliding Window
skipping to change at page 25, line 24 skipping to change at page 23, line 37
sent. If the "agreed parameters" contain the sent. If the "agreed parameters" contain the
"client_no_context_takeover" extension parameter, the client "client_no_context_takeover" extension parameter, the client
compresses the payload of the next message into the same bytes (if compresses the payload of the next message into the same bytes (if
the client uses the same "BTYPE" value and "BFINAL" value). So, the the client uses the same "BTYPE" value and "BFINAL" value). So, the
payload of the second message will be: 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" did not contain the If the "agreed parameters" did not contain the
"client_no_context_takeover" extension parameter, the client can "client_no_context_takeover" extension parameter, the client can
compress the payload of the next message into less bytes by compress the payload of the next message into fewer bytes by
referencing the history in the LZ77 sliding window. So, the payload referencing the history in the LZ77 sliding window. So, the payload
of the second message will be: of the second message will be:
0xf2 0x00 0x11 0x00 0x00 0xf2 0x00 0x11 0x00 0x00
So, 2 bytes are saved in total. So, 2 bytes are saved in total.
Note that even if some uncompressed messages (with the RSV1 bit Note that even if some uncompressed messages (with the RSV1 bit
unset) are inserted between the two "Hello" messages, they don't unset) are inserted between the two "Hello" messages, they don't
affect the LZ77 sliding window. affect the LZ77 sliding window.
7.2.3.3. Using a DEFLATE Block with No Compression 7.2.3.3. Using a DEFLATE Block with No Compression
A DEFLATE block with no compression may be used.
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 constituting a text message "Hello" built using a This is a frame constituting a text message "Hello" built using a
DEFLATE block with no compression. The first 2 octets (0xc1 0x0b) 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 DEFLATE is applied to fragmented) because the RSV1 bit is set when DEFLATE is applied to
the message, including the case when only DEFLATE blocks with no the message, including the case when only DEFLATE blocks with no
compression are used. The 3rd to 13th octets consist the payload compression are used. The 3rd to 13th octets consist of the payload
data containing "Hello" compressed using a DEFLATE block with no data containing "Hello" compressed using a DEFLATE block with no
compression. compression.
7.2.3.4. Using a DEFLATE Block with BFINAL Set to 1 7.2.3.4. Using a DEFLATE Block with "BFINAL" Set to 1
On platforms on which the flush method using an empty DEFLATE block On platforms on which the flush method using an empty DEFLATE block
with no compression is not available, implementors can choose to with no compression is not available, implementors can choose to
flush data using DEFLATE blocks with "BFINAL" set to 1. flush data 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 the payload of a message containing "Hello" compressed using This is the payload of a message containing "Hello" compressed using
a DEFLATE block with "BFINAL" set to 1. The first 7 octets a DEFLATE block with "BFINAL" set to 1. The first 7 octets
constitute a DEFLATE block with "BFINAL" set to 1 and "BTYPE" set to constitute a DEFLATE block with "BFINAL" set to 1 and "BTYPE" set to
01 containing "Hello". The last 1 octet (0x00) contains the header 01 containing "Hello". The last 1 octet (0x00) contains the header
bits with "BFINAL" set to 0 and "BTYPE" set to 00, and 5 padding bits bits 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 of 0. This octet is necessary to allow the payload to be
decompressed in the same manner as messages flushed using DEFLATE decompressed in the same manner as messages flushed using DEFLATE
blocks with BFINAL unset. blocks with "BFINAL" unset.
7.2.3.5. Two DEFLATE Blocks in 1 Message 7.2.3.5. Two DEFLATE Blocks in One Message
Two or more DEFLATE blocks may be used in 1 message. Two or more DEFLATE blocks may be used in one 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) constitute one DEFLATE block with bits of the 4th octet (0x00) constitute one DEFLATE block with
"BFINAL" set to 0 and "BTYPE" set to 01 containing "He". The rest of "BFINAL" set to 0 and "BTYPE" set to 01 containing "He". The rest of
the 4th octet contains the header bits with "BFINAL" set to 0 and the 4th octet contains the header bits with "BFINAL" set to 0 and
"BTYPE" set to 00, and the 3 padding bits of 0. Together with the "BTYPE" set to 00, and the 3 padding bits of 0. Together with the
following 4 octets (0x00 0x00 0xff 0xff), the header bits constitute following 4 octets (0x00 0x00 0xff 0xff), the header bits constitute
an empty DEFLATE block with no compression. A DEFLATE block an empty DEFLATE block with no compression. A DEFLATE block
containing "llo" follows the empty DEFLATE block. containing "llo" follows the empty DEFLATE block.
7.2.3.6. Generating an Empty Fragment 7.2.3.6. Generating an Empty Fragment
Suppose that an endpoint is sending data of unknown size. The Suppose that an endpoint is sending data of unknown size. The
endpoint may encounter the end of data signal from the data source endpoint may encounter the end-of-data signal from the data source
when its buffer for uncompressed data is empty. In such a case, the when its buffer for uncompressed data is empty. In such a case, the
endpoint just needs to send the last fragment with FIN bit set to 1 endpoint just needs to send the last fragment with the FIN bit set to
and payload set to DEFLATE block(s) which contains 0 bytes of data. 1 and the payload set to the DEFLATE block(s), which contains 0 bytes
If the compression library being used doesn't generate any data when of data. If the compression library being used doesn't generate any
its buffer is empty, an empty uncompressed DEFLATE block can be built data when its buffer is empty, an empty uncompressed DEFLATE block
and used for this purpose as follows: can be built and used for this purpose as follows:
0x00 0x00
The only octet 0x00 contains the header bits with "BFINAL" set to 0 The single octet 0x00 contains the header bits with "BFINAL" set to 0
and "BTYPE" set to 00, and 5 padding bits of 0. and "BTYPE" set to 00, and 5 padding bits of 0.
7.3. Implementation Notes 7.3. Implementation Notes
On most common software development platforms, the DEFLATE On most common software development platforms, the DEFLATE
compression library provides a method for aligning compressed data to compression library provides a method for aligning compressed data to
byte boundaries using an empty DEFLATE block with no compression. byte boundaries using an empty DEFLATE block with no compression.
For example, Zlib [Zlib] does this when "Z_SYNC_FLUSH" is passed to For example, zlib [zlib] does this when "Z_SYNC_FLUSH" is passed to
the deflate function. the deflate function.
Some platforms may provide only methods to output and process Some platforms may only provide methods to output and process
compressed data with a ZLIB header and an Adler-32 checksum. On such compressed data with a zlib header and an Adler-32 checksum. On such
platforms, developers need to write stub code to remove and platforms, developers need to write stub code to remove and
complement them by themselves. complement the zlib and Adler-32 checksum by themselves.
To obtain a useful compression ratio, an LZ77 sliding window size of To obtain a useful compression ratio, an LZ77 sliding window size of
1,024 or more is RECOMMENDED. 1,024 or more is RECOMMENDED.
If a side disallows context takeover, its endpoint can easily figure If a side disallows context takeover, its endpoint can easily figure
out whether a certain message will be shorter if compressed or not. out whether or not a certain message will be shorter if compressed.
Otherwise, it's not easy to know whether future messages will benefit Otherwise, it's not easy to know whether future messages will benefit
from having a certain message compressed. Implementors may employ from having a certain message compressed. Implementors may employ
some heuristics to determine this. some heuristics to determine this.
8. Security Considerations 8. Security Considerations
There is a known exploit when history-based compression is combined There is a known exploit when history-based compression is combined
with a secure transport [CRIME]. Implementors should pay attention with a secure transport [CRIME]. Implementors should pay attention
to this point when integrating this extension with other extensions to this point when integrating this extension with other extensions
or protocols. or protocols.
9. IANA Considerations 9. IANA Considerations
9.1. Registration of the "permessage-deflate" WebSocket Extension Name 9.1. Registration of the "permessage-deflate" WebSocket Extension Name
This section describes a WebSocket extension name registration in the IANA has registered the following WebSocket extension name in the
WebSocket Extension Name Registry [RFC6455]. "WebSocket Extension Name Registry" defined in [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-
"Sec-WebSocket-Extensions" header in the WebSocket opening handshake WebSocket-Extensions" header in the WebSocket opening handshake to
to negotiate use of the permessage-deflate extension. negotiate use of the "permessage-deflate" extension.
9.2. Registration of the "Per-message Compressed" WebSocket Framing 9.2. Registration of the "Per-Message Compressed" WebSocket Framing
Header Bit Header Bit
This section describes a WebSocket framing header bit registration in IANA has registered the following WebSocket framing header bit in the
the WebSocket Framing Header Bits Registry [RFC6455]. "WebSocket Framing Header Bits Registry" defined in [RFC6455].
Value Value
RSV1 RSV1
Description Description
The message is compressed or not. RSV1 is set for compressed The "Per-Message Compressed" bit, which indicates whether or not
messages and unset for uncompressed messages. the message is compressed. RSV1 is set for compressed messages
and unset for uncompressed messages.
Reference Reference
Section 6 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 data messages to indicate whether the payload of the fragment of data messages to indicate whether the payload of the
message is compressed by the PMCE or not. message is compressed by the PMCE or not.
10. Acknowledgements 10. References
Special thanks to Patrick McManus who wrote up the initial
specification of a DEFLATE-based compression extension for the
WebSocket Protocol to which I referred to write this specification.
Thanks to the following people who participated in discussions on the 10.1. Normative References
HyBi WG and contributed ideas and/or provided detailed reviews (the
list is likely to be incomplete): Adam Rice, Alexander Philippou,
Alexey Melnikov, Arman Djusupov, Bjoern Hoehrmann, Brian McKelvey,
Dario Crivelli, Greg Wilkins, Inaki Baz Castillo, Jamie Lokier,
Joakim Erdfelt, John A. Tamplin, Julian Reschke, Kenichi Ishibashi,
Mark Nottingham, Peter Thorson, Roberto Peon, Salvatore Loreto,
Simone Bordet, Tobias Oberstein and Yutaka Hirano. Note that people
listed above didn't necessarily endorse the end result of this work.
11. References [CRIME] Rizzo, J. and T. Duong, "The CRIME attack", EKOparty
Security Conference, September 2012.
11.1. Normative References [LZ77] Ziv, J. and A. Lempel, "A Universal Algorithm for
Sequential Data Compression", IEEE Transactions on
Information Theory, Vol. 23, No. 3, pp. 337-343,
DOI 10.1109/TIT.1977.1055714, May 1977,
<https://www.cs.duke.edu/courses/spring03/cps296.5/papers/
ziv_lempel_1977_universal_algorithm.pdf>.
[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, DOI 10.17487/RFC1951, May 1996,
<http://www.rfc-editor.org/info/rfc1951>.
[RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
Specifications: ABNF", STD 68, RFC 5234, January 2008. Requirement Levels", BCP 14, RFC 2119,
DOI 10.17487/RFC2119, March 1997,
<http://www.rfc-editor.org/info/rfc2119>.
[RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax
Specifications: ABNF", STD 68, RFC 5234,
DOI 10.17487/RFC5234, January 2008,
<http://www.rfc-editor.org/info/rfc5234>.
[RFC6455] Fette, I. and A. Melnikov, "The WebSocket Protocol", [RFC6455] Fette, I. and A. Melnikov, "The WebSocket Protocol",
RFC 6455, December 2011. RFC 6455, DOI 10.17487/RFC6455, December 2011,
<http://www.rfc-editor.org/info/rfc6455>.
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 10.2. Informative References
Requirement Levels", BCP 14, RFC 2119, March 1997.
[LZ77] Ziv, J. and A. Lempel, "A Universal Algorithm for [RFC1979] Woods, J., "PPP Deflate Protocol", RFC 1979,
Sequential Data Compression", IEEE Transactions on DOI 10.17487/RFC1979, August 1996,
Information Theory, Vol. 23, No. 3, pp. 337-343. <http://www.rfc-editor.org/info/rfc1979>.
[CRIME] Rizzo, J. and T. Duong, "The CRIME attack", Ekoparty 2012, [zlib] Gailly, J. and M. Adler, "zlib", <http://www.zlib.net/>.
September 2012.
11.2. Informative References Acknowledgements
[RFC1979] Woods, J., "PPP Deflate Protocol", RFC 1979, August 1996. Special thanks to Patrick McManus who wrote up the initial
specification of a DEFLATE-based compression extension for the
WebSocket Protocol, which I referred to when writing this
specification.
[Zlib] Gailly, J. and M. Adler, "Zlib", <http://zlib.net/>. Thanks to the following people who participated in discussions on the
HyBi WG and contributed ideas and/or provided detailed reviews (the
list is likely incomplete): Adam Rice, Alexander Philippou, Alexey
Melnikov, Arman Djusupov, Bjoern Hoehrmann, Brian McKelvey, Dario
Crivelli, Greg Wilkins, Inaki Baz Castillo, Jamie Lokier, Joakim
Erdfelt, John A. Tamplin, Julian Reschke, Kenichi Ishibashi, Mark
Nottingham, Peter Thorson, Roberto Peon, Salvatore Loreto, Simone
Bordet, Tobias Oberstein, and Yutaka Hirano. Note that the people
listed above didn't necessarily endorse the end result of this work.
Author's Address Author's Address
Takeshi Yoshino Takeshi Yoshino
Google, Inc. Google, Inc.
Email: tyoshino@google.com Email: tyoshino@google.com
 End of changes. 118 change blocks. 
262 lines changed or deleted 271 lines changed or added

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