idnits 2.17.1 draft-ietf-hybi-permessage-compression-00.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (August 21, 2012) is 4265 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) ** Obsolete normative reference: RFC 5226 (Obsoleted by RFC 8126) -- Possible downref: Non-RFC (?) normative reference: ref. 'LZ77' Summary: 1 error (**), 0 flaws (~~), 1 warning (==), 2 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 HyBi Working Group T. Yoshino 3 Internet-Draft Google, Inc. 4 Intended status: Standards Track August 21, 2012 5 Expires: February 22, 2013 7 WebSocket Per-message Compression 8 draft-ietf-hybi-permessage-compression-00 10 Abstract 12 This specification defines a WebSocket extension that adds 13 compression functionality to the WebSocket Protocol. It compresses 14 the payload of non-control WebSocket messages using specified 15 compression algorithm. One reserved bit RSV1 in the WebSocket frame 16 header is allocated to control application of compression for each 17 message. This specification provides one compression method 18 available for the extension using DEFLATE. 20 Please send feedback to the hybi@ietf.org mailing list. 22 Status of this Memo 24 This Internet-Draft is submitted to IETF in full conformance with the 25 provisions of BCP 78 and BCP 79. 27 Internet-Drafts are working documents of the Internet Engineering 28 Task Force (IETF). Note that other groups may also distribute 29 working documents as Internet-Drafts. The list of current Internet- 30 Drafts is at http://datatracker.ietf.org/drafts/current. 32 Internet-Drafts are draft documents valid for a maximum of six months 33 and may be updated, replaced, or obsoleted by other documents at any 34 time. It is inappropriate to use Internet-Drafts as reference 35 material or to cite them other than as "work in progress." 37 This Internet-Draft will expire on February 22, 2013. 39 Copyright Notice 41 Copyright (c) 2012 IETF Trust and the persons identified as the 42 document authors. All rights reserved. 44 This document is subject to BCP 78 and the IETF Trust's Legal 45 Provisions Relating to IETF Documents 46 (http://trustee.ietf.org/license-info) in effect on the date of 47 publication of this document. Please review these documents 48 carefully, as they describe your rights and restrictions with respect 49 to this document. Code Components extracted from this document must 50 include Simplified BSD License text as described in Section 4.e of 51 the Trust Legal Provisions and are provided without warranty as 52 described in the Simplified BSD License. 54 Table of Contents 56 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 57 2. Conformance Requirements . . . . . . . . . . . . . . . . . . . 4 58 3. Extension Negotiation . . . . . . . . . . . . . . . . . . . . 5 59 3.1. Negotiation Example . . . . . . . . . . . . . . . . . . . 6 60 4. Framing . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 61 4.1. Sending . . . . . . . . . . . . . . . . . . . . . . . . . 7 62 4.2. Receiving . . . . . . . . . . . . . . . . . . . . . . . . 7 63 5. DEFLATE method . . . . . . . . . . . . . . . . . . . . . . . . 8 64 5.1. Method Parameters . . . . . . . . . . . . . . . . . . . . 8 65 5.2. Application Data Transformation . . . . . . . . . . . . . 9 66 5.2.1. Compression . . . . . . . . . . . . . . . . . . . . . 9 67 5.2.2. Decompression . . . . . . . . . . . . . . . . . . . . 10 68 5.2.3. Examples . . . . . . . . . . . . . . . . . . . . . . . 10 69 5.3. Intermediaries . . . . . . . . . . . . . . . . . . . . . . 11 70 5.4. Implementation Notes . . . . . . . . . . . . . . . . . . . 11 71 6. Security Considerations . . . . . . . . . . . . . . . . . . . 12 72 7. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 13 73 7.1. Registration of the "permessage-compress" WebSocket 74 Extension Name . . . . . . . . . . . . . . . . . . . . . . 13 75 7.2. Registration of the "Per-message Compressed" WebSocket 76 Framing Header Bit . . . . . . . . . . . . . . . . . . . . 13 77 7.3. WebSocket Per-message Compression Method Name Registry . . 14 78 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 15 79 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 16 80 9.1. Normative References . . . . . . . . . . . . . . . . . . . 16 81 9.2. Informative References . . . . . . . . . . . . . . . . . . 16 82 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 17 84 1. Introduction 86 _This section is non-normative._ 88 As well as other communication protocols, the WebSocket Protocol 89 [RFC6455] can benefit from compression technology. This 90 specification defines a WebSocket extension that applies a 91 compression algorithm to octets exchanged over the WebSocket Protocol 92 using its extension framework. This extension negotiates what 93 compression method to use on opening handshake, and then compresses 94 the octets in non-control messages using the method. We can apply 95 this extension to various compression algorithms by specifying how to 96 negotiate parameters and transform payload. A client may offer 97 multiple compression methods on opening handshake, and then the 98 server chooses one from them. This extension uses the RSV1 bit of 99 the WebSocket frame header to indicate whether the message is 100 compressed or not, so that we can choose to skip messages with 101 incompressible contents without applying extra compression. 103 This specification provides one specific compression method "deflate" 104 which is based on DEFLATE [RFC1951] for this extension. We chose 105 DEFLATE since it's widely available as library on various platforms 106 and the overhead it adds for each chunk is small. To align the end 107 of compressed data to octet boundary, this method uses the algorithm 108 described in the Section 2.1 of the PPP Deflate Protocol [RFC1979]. 109 Endpoints can take over the LZ77 sliding window [LZ77] used to build 110 previous messages to get better compression ratio. For resource- 111 limited devices, method parameters to limit the usage of memory for 112 compression context are provided. 114 The simplest "Sec-WebSocket-Extensions" header in the client's 115 opening handshake to request DEFLATE based per-message compression is 116 the following: 118 Sec-WebSocket-Extensions: permessage-compress; method=deflate 120 The simplest header from the server to accept this extension is the 121 same. 123 2. Conformance Requirements 125 Everything in this specification except for sections explicitly 126 marked non-normative is normative. 128 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 129 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 130 document are to be interpreted as described in [RFC2119]. 132 3. Extension Negotiation 134 The registered extension token for this extension is 135 "permessage-compress". 137 To request use of the Per-message Compression Extension, a client 138 MUST include an element with the "permessage-compress" extension 139 token as its extension identifier in the "Sec-WebSocket-Extensions" 140 header in its opening handshake. The element MUST contain exactly 141 one extension parameter named "method". The value of the "method" 142 extension parameter is a list of compression method descriptions, 143 ordered by preference. Each compression method description has a 144 method name and optional method parameters. The grammar of the list 145 is "requested-method-list" defined in the following ABNFs. 147 requested-method-list = 1#method-desc 148 method-desc = method-name *(";" method-param) 149 method-name = token 150 method-param = token ["=" (token | quoted-string)] 152 The list MAY contain multiple method descriptions with the same 153 method name. 155 To accept use of the Per-message Compression Extension, a server MUST 156 choose one compression method description to accept from ones listed 157 by the client, and include an element with the "permessage-compress" 158 extension token in the "Sec-WebSocket-Extensions" header in its 159 opening handshake. The chosen description is called "accepted 160 request". The element MUST contain exactly one extension parameter 161 named "method". The value of the "method" extension parameter MUST 162 be a compression method description. This description is called 163 "method agreement". The method name in the "method agreement" MUST 164 be one of the accepted request. The "method agreement" MUST conform 165 the "accepted request". Its grammar is "method-agreement" defined in 166 the following ABNF. 168 method-agreement = method-desc 170 The value of the "method" parameter MUST be quoted by using 171 "quoted-string" syntax if it doesn't conform to token syntax. 173 If a client doesn't support the method and its configuration 174 specified by the "method agreement", the client MUST _Fail the 175 WebSocket Connection_. Otherwise, both endpoints MUST use the 176 algorithm described in Section 4 to exchange messages. 178 3.1. Negotiation Example 180 _This section is non-normative._ 182 These are "Sec-WebSocket-Extensions" header value examples that 183 negotiate the Per-message Compression Extension. 185 o Request foo method. Since foo matches token syntax, it doesn't 186 need to be quoted. 188 permessage-compress; method=foo 190 o Request foo method with a parameter x with 10 as its value. Since 191 the method parameter value contains a semicolon, it doesn't match 192 token syntax. Quotation is needed. 194 permessage-compress; method="foo; x=10" 196 o Request foo method and bar method. Since the method parameter 197 value contains a comma, it doesn't match token syntax. Quotation 198 is needed. 200 permessage-compress; method="foo, bar" 202 o Request foo method with parameter x with "Hello World" (quotation 203 for clarification) as its value and bar method. Since "Hello 204 World" contains a space, it needs to be quoted. Since quoted 205 "Hello World" contains double quotations and a space, it needs to 206 be quoted again. 208 permessage-compress; method="foo; x=\"Hello World\", bar" 210 4. Framing 212 This section describes how to apply the negotiated compression method 213 to the contents of WebSocket messages. 215 This extension allocates the RSV1 bit of the WebSocket header and 216 names it the "Per-message Compressed" bit. Any extension requiring 217 the use of the RSV1 bit is incompatible with this extension. This 218 bit MAY be set only on the first fragment of a message. This bit 219 indicates whether the compression method is applied to the message or 220 not. Messages with the "Per-message Compressed" bit set (on its 221 first fragment) are called "compressed messages". They have 222 compressed data in their payload. Messages with the bit unset are 223 called "uncompressed messages". They have uncompressed data in their 224 payload. 226 This extension MUST NOT be used after any extension for which frame 227 boundary needs to be preserved. This extension MUST NOT be used 228 after any extension that uses "Extension data" field or any of the 229 reserved bits on the WebSocket header as per-frame attribute. 231 This extension operates only on data frames. 233 4.1. Sending 235 To send a compressed message, an endpoint MUST use the following 236 algorithm. 238 1. Compress the payload of the message using the compression method. 240 2. Build frame(s) for the message by putting the resulting octets 241 instead of the original octets. 243 3. Set the "Per-message Compressed" bit of the first fragment to 1. 245 To send an uncompressed message, an endpoint MUST set the 246 "Per-message Compressed" bit of the first fragment of the message to 247 0. The payload of the message MUST be sent as-is without applying 248 the compression method. 250 4.2. Receiving 252 To receive a compressed message, an endpoint MUST decompress its 253 payload. 255 An endpoint MUST receive an uncompressed message as-is without 256 decompression. 258 5. DEFLATE method 260 This section defines a method named "deflate" for this extension that 261 compresses the payload of messages using DEFLATE [RFC1951] and byte 262 boundary alignment method introduced in [RFC1979]. 264 5.1. Method Parameters 266 An endpoint MAY include one or more method parameters in the method 267 description as defined below. 269 Maximum LZ77 sliding window size 271 A client MAY attach the "s2c_max_window_bits" method parameter to 272 limit the LZ77 sliding window size that the server uses to build 273 messages. If the "accepted request" has this method parameter, 274 the server MUST NOT use LZ77 sliding window size greater than the 275 size specified by this parameter to build messages. If the 276 "accepted request" has this method parameter, the server MUST 277 attach this method parameter with the same value as one of the 278 "accepted request". 280 A server MAY attach the "c2s_max_window_bits" method parameter to 281 limit the LZ77 sliding window size that the client uses to build 282 messages. A client that received this parameter MUST NOT use LZ77 283 sliding window size greater than the size specified by this 284 parameter to build messages. 286 These parameters MUST have an integer value in the range between 8 287 to 15 indicating the base-2 logarithm of the LZ77 sliding window 288 size. 290 Disallow compression context takeover 292 A client MAY attach the "s2c_no_context_takeover" method parameter 293 to disallow the server to take over the LZ77 sliding window used 294 to build previous messages. If the "accepted request" has this 295 method parameter, the server MUST reset its LZ77 sliding window 296 for sending to empty for each message. If the "accepted request" 297 has this method parameter, the server MUST attach this method 298 parameter. 300 A server MAY attach the "c2s_no_context_takeover" method parameter 301 to disallow the client to take over the LZ77 sliding window used 302 to build previous messages. A client that received this parameter 303 MUST reset its LZ77 sliding window for sending to empty for each 304 message. 306 These parameters have no value. 308 A server MUST ignore any method parameter other than 309 "s2c_max_window_bits" and "s2c_no_context_takeover" in the received 310 "deflate" method description. 312 A client MUST _Fail the WebSocket Connection_ if there is any method 313 parameter other than the "s2c_max_window_bits", 314 "c2s_max_window_bits", "s2c_no_context_takeover" and 315 "c2s_no_context_takeover" in the received "deflate" method 316 description. A client MUST _Fail the WebSocket Connection_ if it 317 doesn't support the method and its configuration specified by the 318 received "deflate" method description. 320 5.2. Application Data Transformation 322 5.2.1. Compression 324 An endpoint MUST use the following algorithm to compress a message. 326 1. Compress all the octets of the payload of the message using 327 DEFLATE. Multiple blocks MAY be used. Any type of block MAY be 328 used. Both block with "BFINAL" set to 0 and 1 MAY be used. 330 2. If the resulting data does not end with an empty block with no 331 compression ("BTYPE" set to 0), append an empty block with no 332 compression to the tail. 334 3. Remove 4 octets (that are 0x00 0x00 0xff 0xff) from the tail. 336 An endpoint MUST NOT use an LZ77 sliding window greater than 32,768 337 bytes to build messages to send. 339 If the "method agreement" has the "s2c_max_window_bits" method 340 parameter and its value is w, the server MUST NOT use an LZ77 sliding 341 window greater than w-th power of 2 bytes to build messages to send. 342 If the "method agreement" has the "c2s_max_window_bits" method 343 parameter and its value is w, the client MUST NOT use an LZ77 sliding 344 window greater than w-th power of 2 bytes to build messages to send. 346 If the "method agreement" has the "s2c_no_context_takeover" method 347 parameter, the server MUST reset its LZ77 sliding window for sending 348 to empty for each message. Otherwise, the server MAY take over the 349 LZ77 sliding window used to build the last compressed message. If 350 the "method agreement" has the "c2s_no_context_takeover" method 351 parameter, the client MUST reset its LZ77 sliding window for sending 352 to empty for each message. Otherwise, the client MAY take over the 353 LZ77 sliding window used to build the last compressed message. 355 5.2.2. Decompression 357 An endpoint MUST use the following algorithm to decompress a message. 359 1. Append 4 octets of 0x00 0x00 0xff 0xff to the tail of the payload 360 of the message. 362 2. Decompress the resulting octets using DEFLATE. 364 If the "method agreement" has the "s2c_max_window_bits" method 365 parameter and its value is w, the client MAY reduce the size of the 366 LZ77 sliding window to decompress received messages down to the w-th 367 power of 2 bytes. Otherwise, the client MUST use a 32,768 byte LZ77 368 sliding window to decompress received messages. If the "method 369 agreement" has the "c2s_max_window_bits" method parameter and its 370 value is w, the server MAY reduce the size of the LZ77 sliding window 371 to decompress received messages down to the w-th power of 2 bytes. 372 Otherwise, the server MUST use a 32,768 byte LZ77 sliding window to 373 decompress received messages. 375 If the "method agreement" has the "s2c_no_context_takeover" method 376 parameter, the client MAY reset its LZ77 sliding window for receiving 377 to empty for each message. Otherwise, the client MUST take over the 378 LZ77 sliding window used to parse the last compressed message. If 379 the "method agreement" has the "c2s_no_context_takeover" method 380 parameter, the server MAY reset its LZ77 sliding window for receiving 381 to empty for each message. Otherwise, the server MUST take over the 382 LZ77 sliding window used to parse the last compressed message. 384 5.2.3. Examples 386 _This section is non-normative._ 388 These are examples of resulting data after applying the algorithm 389 above. 391 o "Hello" in one compressed block 393 * 0xf2 0x48 0xcd 0xc9 0xc9 0x07 0x00 395 "Hello" in one compressed block in the next frame 397 * 0xf2 0x00 0x11 0x00 0x00 399 o "Hello" in one block with no compression 401 * 0x00 0x05 0x00 0xfa 0xff 0x48 0x65 0x6c 0x6c 0x6f 0x00 403 o "Hello" in one block with "BFINAL" set to 1 405 * 0xf3 0x48 0xcd 0xc9 0xc9 0x07 0x00 0x00 407 o "He" and "llo" in separate blocks 409 * 0xf2 0x48 0x05 0x00 0x00 0x00 0xff 0xff 0xca 0xc9 0xc9 0x07 410 0x00 412 5.3. Intermediaries 414 When intermediaries forward messages, they MAY decompress and/or 415 compress the messages according to the constraints negotiated during 416 the opening handshake of the connection(s). 418 5.4. Implementation Notes 420 _This section is non-normative._ 422 On most common software development platforms, the operation of 423 aligning compressed data to byte boundaries using an empty block with 424 no compression is available as a library. For example, Zlib [Zlib] 425 does this when "Z_SYNC_FLUSH" is passed to deflate function. 427 To get sufficient compression ratio, LZ77 sliding window size of 428 1,024 or more is recommended. 430 6. Security Considerations 432 There are no security concerns for now. 434 7. IANA Considerations 436 7.1. Registration of the "permessage-compress" WebSocket Extension Name 438 This section describes a WebSocket extension name registration in the 439 WebSocket Extension Name Registry [RFC6455]. 441 Extension Identifier 442 permessage-compress 444 Extension Common Name 445 WebSocket Per-message Compression 447 Extension Definition 448 This document. 450 Known Incompatible Extensions 451 None 453 The "permessage-compress" token is used in the 454 "Sec-WebSocket-Extensions" header in the WebSocket opening handshake 455 to negotiate use of the Per-message Compression Extension. 457 7.2. Registration of the "Per-message Compressed" WebSocket Framing 458 Header Bit 460 This section describes a WebSocket framing header bit registration in 461 the WebSocket Framing Header Bits Registry [RFC6455]. 463 Header Bit 464 RSV1 466 Common Name 467 Per-message Compressed 469 Meaning 470 The message is compressed or not. 472 Reference 473 Section 4 of this document. 475 The "Per-message Compressed" framing header bit is used on the first 476 fragment of non-control messages to indicate whether the payload of 477 the message is compressed by the Per-message Compression Extension or 478 not. 480 7.3. WebSocket Per-message Compression Method Name Registry 482 This specification creates a new IANA registry for names of 483 compression methods to be used with the WebSocket Per-message 484 Compression Extension in accordance with the principles set out in 485 [RFC5226]. 487 As part of this registry, IANA maintains the following information: 489 Method Identifier 490 The identifier of the method, as will be used in the method 491 description as defined Section 3 of this specification. The value 492 must conform to the method-name ABNF as defined in Section 3 of 493 this specification. 495 Method Common Name 496 The name of the method, as the method is generally referred to. 498 Method Definition 499 A reference to the document in which the method being used with 500 this extension is defined. 502 WebSocket Per-message Compression method names are to be subject to 503 the "First Come First Served" IANA registration policy [RFC5226]. 505 IANA has added initial values to the registry as follows. 507 +------------+-------------+---------------+ 508 | Identifier | Common Name | Definition | 509 +------------+-------------+---------------+ 510 | deflate | DEFLATE | This document | 511 +------------+-------------+---------------+ 513 8. Acknowledgements 515 Special thanks to Patrick McManus who wrote up the initial 516 specification of DEFLATE based compression extension for the 517 WebSocket Protocol to which I referred to write this specification. 519 9. References 521 9.1. Normative References 523 [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an 524 IANA Considerations Section in RFCs", BCP 26, RFC 5226, 525 May 2008. 527 [RFC6455] Fette, I. and A. Melnikov, "The WebSocket Protocol", 528 RFC 6455, December 2011. 530 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 531 Requirement Levels", BCP 14, RFC 2119, March 1997. 533 [LZ77] Ziv, J. and A. Lempel, "A Universal Algorithm for 534 Sequential Data Compression", IEEE Transactions on 535 Information Theory, Vol. 23, No. 3, pp. 337-343. 537 9.2. Informative References 539 [RFC1951] Deutsch, P., "DEFLATE Compressed Data Format Specification 540 version 1.3", RFC 1951, May 1996. 542 [RFC1979] Woods, J., "PPP Deflate Protocol", RFC 1979, August 1996. 544 [Zlib] Gailly, J. and M. Adler, "Zlib", . 546 Author's Address 548 Takeshi Yoshino 549 Google, Inc. 551 Email: tyoshino@google.com