1
2
3
4
5
6
7Internet Engineering Task Force (IETF) I. Fette
8Request for Comments: 6455 Google, Inc.
9Category: Standards Track A. Melnikov
10ISSN: 2070-1721 Isode Ltd.
11 December 2011
12
13
14 The WebSocket Protocol
15
16Abstract
17
18 The WebSocket Protocol enables two-way communication between a client
19 running untrusted code in a controlled environment to a remote host
20 that has opted-in to communications from that code. The security
21 model used for this is the origin-based security model commonly used
22 by web browsers. The protocol consists of an opening handshake
23 followed by basic message framing, layered over TCP. The goal of
24 this technology is to provide a mechanism for browser-based
25 applications that need two-way communication with servers that does
26 not rely on opening multiple HTTP connections (e.g., using
27 XMLHttpRequest or <iframe>s and long polling).
28
29Status of This Memo
30
31 This is an Internet Standards Track document.
32
33 This document is a product of the Internet Engineering Task Force
34 (IETF). It represents the consensus of the IETF community. It has
35 received public review and has been approved for publication by the
36 Internet Engineering Steering Group (IESG). Further information on
37 Internet Standards is available in Section 2 of RFC 5741.
38
39 Information about the current status of this document, any errata,
40 and how to provide feedback on it may be obtained at
41 http://www.rfc-editor.org/info/rfc6455.
42
43Copyright Notice
44
45 Copyright (c) 2011 IETF Trust and the persons identified as the
46 document authors. All rights reserved.
47
48 This document is subject to BCP 78 and the IETF Trust's Legal
49 Provisions Relating to IETF Documents
50 (http://trustee.ietf.org/license-info) in effect on the date of
51 publication of this document. Please review these documents
52 carefully, as they describe your rights and restrictions with respect
53 to this document. Code Components extracted from this document must
54
55
56
57
58Fette & Melnikov Standards Track [Page 1]
59
60RFC 6455 The WebSocket Protocol December 2011
61
62
63 include Simplified BSD License text as described in Section 4.e of
64 the Trust Legal Provisions and are provided without warranty as
65 described in the Simplified BSD License.
66
67Table of Contents
68
69 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 4
70 1.1. Background . . . . . . . . . . . . . . . . . . . . . . . . 4
71 1.2. Protocol Overview . . . . . . . . . . . . . . . . . . . . 5
72 1.3. Opening Handshake . . . . . . . . . . . . . . . . . . . . 6
73 1.4. Closing Handshake . . . . . . . . . . . . . . . . . . . . 9
74 1.5. Design Philosophy . . . . . . . . . . . . . . . . . . . . 9
75 1.6. Security Model . . . . . . . . . . . . . . . . . . . . . . 10
76 1.7. Relationship to TCP and HTTP . . . . . . . . . . . . . . . 11
77 1.8. Establishing a Connection . . . . . . . . . . . . . . . . 11
78 1.9. Subprotocols Using the WebSocket Protocol . . . . . . . . 12
79 2. Conformance Requirements . . . . . . . . . . . . . . . . . . . 12
80 2.1. Terminology and Other Conventions . . . . . . . . . . . . 13
81 3. WebSocket URIs . . . . . . . . . . . . . . . . . . . . . . . . 14
82 4. Opening Handshake . . . . . . . . . . . . . . . . . . . . . . 14
83 4.1. Client Requirements . . . . . . . . . . . . . . . . . . . 14
84 4.2. Server-Side Requirements . . . . . . . . . . . . . . . . . 20
85 4.2.1. Reading the Client's Opening Handshake . . . . . . . . 21
86 4.2.2. Sending the Server's Opening Handshake . . . . . . . . 22
87 4.3. Collected ABNF for New Header Fields Used in Handshake . . 25
88 4.4. Supporting Multiple Versions of WebSocket Protocol . . . . 26
89 5. Data Framing . . . . . . . . . . . . . . . . . . . . . . . . . 27
90 5.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . . 27
91 5.2. Base Framing Protocol . . . . . . . . . . . . . . . . . . 28
92 5.3. Client-to-Server Masking . . . . . . . . . . . . . . . . . 32
93 5.4. Fragmentation . . . . . . . . . . . . . . . . . . . . . . 33
94 5.5. Control Frames . . . . . . . . . . . . . . . . . . . . . . 36
95 5.5.1. Close . . . . . . . . . . . . . . . . . . . . . . . . 36
96 5.5.2. Ping . . . . . . . . . . . . . . . . . . . . . . . . . 37
97 5.5.3. Pong . . . . . . . . . . . . . . . . . . . . . . . . . 37
98 5.6. Data Frames . . . . . . . . . . . . . . . . . . . . . . . 38
99 5.7. Examples . . . . . . . . . . . . . . . . . . . . . . . . . 38
100 5.8. Extensibility . . . . . . . . . . . . . . . . . . . . . . 39
101 6. Sending and Receiving Data . . . . . . . . . . . . . . . . . . 39
102 6.1. Sending Data . . . . . . . . . . . . . . . . . . . . . . . 39
103 6.2. Receiving Data . . . . . . . . . . . . . . . . . . . . . . 40
104 7. Closing the Connection . . . . . . . . . . . . . . . . . . . . 41
105 7.1. Definitions . . . . . . . . . . . . . . . . . . . . . . . 41
106 7.1.1. Close the WebSocket Connection . . . . . . . . . . . . 41
107 7.1.2. Start the WebSocket Closing Handshake . . . . . . . . 42
108 7.1.3. The WebSocket Closing Handshake is Started . . . . . . 42
109 7.1.4. The WebSocket Connection is Closed . . . . . . . . . . 42
110 7.1.5. The WebSocket Connection Close Code . . . . . . . . . 42
111
112
113
114Fette & Melnikov Standards Track [Page 2]
115
116RFC 6455 The WebSocket Protocol December 2011
117
118
119 7.1.6. The WebSocket Connection Close Reason . . . . . . . . 43
120 7.1.7. Fail the WebSocket Connection . . . . . . . . . . . . 43
121 7.2. Abnormal Closures . . . . . . . . . . . . . . . . . . . . 44
122 7.2.1. Client-Initiated Closure . . . . . . . . . . . . . . . 44
123 7.2.2. Server-Initiated Closure . . . . . . . . . . . . . . . 44
124 7.2.3. Recovering from Abnormal Closure . . . . . . . . . . . 44
125 7.3. Normal Closure of Connections . . . . . . . . . . . . . . 45
126 7.4. Status Codes . . . . . . . . . . . . . . . . . . . . . . . 45
127 7.4.1. Defined Status Codes . . . . . . . . . . . . . . . . . 45
128 7.4.2. Reserved Status Code Ranges . . . . . . . . . . . . . 47
129 8. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 48
130 8.1. Handling Errors in UTF-8-Encoded Data . . . . . . . . . . 48
131 9. Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . 48
132 9.1. Negotiating Extensions . . . . . . . . . . . . . . . . . . 48
133 9.2. Known Extensions . . . . . . . . . . . . . . . . . . . . . 50
134 10. Security Considerations . . . . . . . . . . . . . . . . . . . 50
135 10.1. Non-Browser Clients . . . . . . . . . . . . . . . . . . . 50
136 10.2. Origin Considerations . . . . . . . . . . . . . . . . . . 50
137 10.3. Attacks On Infrastructure (Masking) . . . . . . . . . . . 51
138 10.4. Implementation-Specific Limits . . . . . . . . . . . . . . 52
139 10.5. WebSocket Client Authentication . . . . . . . . . . . . . 53
140 10.6. Connection Confidentiality and Integrity . . . . . . . . . 53
141 10.7. Handling of Invalid Data . . . . . . . . . . . . . . . . . 53
142 10.8. Use of SHA-1 by the WebSocket Handshake . . . . . . . . . 54
143 11. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 54
144 11.1. Registration of New URI Schemes . . . . . . . . . . . . . 54
145 11.1.1. Registration of "ws" Scheme . . . . . . . . . . . . . 54
146 11.1.2. Registration of "wss" Scheme . . . . . . . . . . . . . 55
147 11.2. Registration of the "WebSocket" HTTP Upgrade Keyword . . . 56
148 11.3. Registration of New HTTP Header Fields . . . . . . . . . . 57
149 11.3.1. Sec-WebSocket-Key . . . . . . . . . . . . . . . . . . 57
150 11.3.2. Sec-WebSocket-Extensions . . . . . . . . . . . . . . . 58
151 11.3.3. Sec-WebSocket-Accept . . . . . . . . . . . . . . . . . 58
152 11.3.4. Sec-WebSocket-Protocol . . . . . . . . . . . . . . . . 59
153 11.3.5. Sec-WebSocket-Version . . . . . . . . . . . . . . . . 60
154 11.4. WebSocket Extension Name Registry . . . . . . . . . . . . 61
155 11.5. WebSocket Subprotocol Name Registry . . . . . . . . . . . 61
156 11.6. WebSocket Version Number Registry . . . . . . . . . . . . 62
157 11.7. WebSocket Close Code Number Registry . . . . . . . . . . . 64
158 11.8. WebSocket Opcode Registry . . . . . . . . . . . . . . . . 65
159 11.9. WebSocket Framing Header Bits Registry . . . . . . . . . . 66
160 12. Using the WebSocket Protocol from Other Specifications . . . . 66
161 13. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 67
162 14. References . . . . . . . . . . . . . . . . . . . . . . . . . . 68
163 14.1. Normative References . . . . . . . . . . . . . . . . . . . 68
164 14.2. Informative References . . . . . . . . . . . . . . . . . . 69
165
166
167
168
169
170Fette & Melnikov Standards Track [Page 3]
171
172RFC 6455 The WebSocket Protocol December 2011
173
174
1751. Introduction
176
1771.1. Background
178
179 _This section is non-normative._
180
181 Historically, creating web applications that need bidirectional
182 communication between a client and a server (e.g., instant messaging
183 and gaming applications) has required an abuse of HTTP to poll the
184 server for updates while sending upstream notifications as distinct
185 HTTP calls [RFC6202].
186
187 This results in a variety of problems:
188
189 o The server is forced to use a number of different underlying TCP
190 connections for each client: one for sending information to the
191 client and a new one for each incoming message.
192
193 o The wire protocol has a high overhead, with each client-to-server
194 message having an HTTP header.
195
196 o The client-side script is forced to maintain a mapping from the
197 outgoing connections to the incoming connection to track replies.
198
199 A simpler solution would be to use a single TCP connection for
200 traffic in both directions. This is what the WebSocket Protocol
201 provides. Combined with the WebSocket API [WSAPI], it provides an
202 alternative to HTTP polling for two-way communication from a web page
203 to a remote server.
204
205 The same technique can be used for a variety of web applications:
206 games, stock tickers, multiuser applications with simultaneous
207 editing, user interfaces exposing server-side services in real time,
208 etc.
209
210 The WebSocket Protocol is designed to supersede existing
211 bidirectional communication technologies that use HTTP as a transport
212 layer to benefit from existing infrastructure (proxies, filtering,
213 authentication). Such technologies were implemented as trade-offs
214 between efficiency and reliability because HTTP was not initially
215 meant to be used for bidirectional communication (see [RFC6202] for
216 further discussion). The WebSocket Protocol attempts to address the
217 goals of existing bidirectional HTTP technologies in the context of
218 the existing HTTP infrastructure; as such, it is designed to work
219 over HTTP ports 80 and 443 as well as to support HTTP proxies and
220 intermediaries, even if this implies some complexity specific to the
221 current environment. However, the design does not limit WebSocket to
222 HTTP, and future implementations could use a simpler handshake over a
223
224
225
226Fette & Melnikov Standards Track [Page 4]
227
228RFC 6455 The WebSocket Protocol December 2011
229
230
231 dedicated port without reinventing the entire protocol. This last
232 point is important because the traffic patterns of interactive
233 messaging do not closely match standard HTTP traffic and can induce
234 unusual loads on some components.
235
2361.2. Protocol Overview
237
238 _This section is non-normative._
239
240 The protocol has two parts: a handshake and the data transfer.
241
242 The handshake from the client looks as follows:
243
244 GET /chat HTTP/1.1
245 Host: server.example.com
246 Upgrade: websocket
247 Connection: Upgrade
248 Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
249 Origin: http://example.com
250 Sec-WebSocket-Protocol: chat, superchat
251 Sec-WebSocket-Version: 13
252
253 The handshake from the server looks as follows:
254
255 HTTP/1.1 101 Switching Protocols
256 Upgrade: websocket
257 Connection: Upgrade
258 Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
259 Sec-WebSocket-Protocol: chat
260
261 The leading line from the client follows the Request-Line format.
262 The leading line from the server follows the Status-Line format. The
263 Request-Line and Status-Line productions are defined in [RFC2616].
264
265 An unordered set of header fields comes after the leading line in
266 both cases. The meaning of these header fields is specified in
267 Section 4 of this document. Additional header fields may also be
268 present, such as cookies [RFC6265]. The format and parsing of
269 headers is as defined in [RFC2616].
270
271 Once the client and server have both sent their handshakes, and if
272 the handshake was successful, then the data transfer part starts.
273 This is a two-way communication channel where each side can,
274 independently from the other, send data at will.
275
276 After a successful handshake, clients and servers transfer data back
277 and forth in conceptual units referred to in this specification as
278 "messages". On the wire, a message is composed of one or more
279
280
281
282Fette & Melnikov Standards Track [Page 5]
283
284RFC 6455 The WebSocket Protocol December 2011
285
286
287 frames. The WebSocket message does not necessarily correspond to a
288 particular network layer framing, as a fragmented message may be
289 coalesced or split by an intermediary.
290
291 A frame has an associated type. Each frame belonging to the same
292 message contains the same type of data. Broadly speaking, there are
293 types for textual data (which is interpreted as UTF-8 [RFC3629]
294 text), binary data (whose interpretation is left up to the
295 application), and control frames (which are not intended to carry
296 data for the application but instead for protocol-level signaling,
297 such as to signal that the connection should be closed). This
298 version of the protocol defines six frame types and leaves ten
299 reserved for future use.
300
3011.3. Opening Handshake
302
303 _This section is non-normative._
304
305 The opening handshake is intended to be compatible with HTTP-based
306 server-side software and intermediaries, so that a single port can be
307 used by both HTTP clients talking to that server and WebSocket
308 clients talking to that server. To this end, the WebSocket client's
309 handshake is an HTTP Upgrade request:
310
311 GET /chat HTTP/1.1
312 Host: server.example.com
313 Upgrade: websocket
314 Connection: Upgrade
315 Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
316 Origin: http://example.com
317 Sec-WebSocket-Protocol: chat, superchat
318 Sec-WebSocket-Version: 13
319
320 In compliance with [RFC2616], header fields in the handshake may be
321 sent by the client in any order, so the order in which different
322 header fields are received is not significant.
323
324 The "Request-URI" of the GET method [RFC2616] is used to identify the
325 endpoint of the WebSocket connection, both to allow multiple domains
326 to be served from one IP address and to allow multiple WebSocket
327 endpoints to be served by a single server.
328
329 The client includes the hostname in the |Host| header field of its
330 handshake as per [RFC2616], so that both the client and the server
331 can verify that they agree on which host is in use.
332
333
334
335
336
337
338Fette & Melnikov Standards Track [Page 6]
339
340RFC 6455 The WebSocket Protocol December 2011
341
342
343 Additional header fields are used to select options in the WebSocket
344 Protocol. Typical options available in this version are the
345 subprotocol selector (|Sec-WebSocket-Protocol|), list of extensions
346 support by the client (|Sec-WebSocket-Extensions|), |Origin| header
347 field, etc. The |Sec-WebSocket-Protocol| request-header field can be
348 used to indicate what subprotocols (application-level protocols
349 layered over the WebSocket Protocol) are acceptable to the client.
350 The server selects one or none of the acceptable protocols and echoes
351 that value in its handshake to indicate that it has selected that
352 protocol.
353
354 Sec-WebSocket-Protocol: chat
355
356 The |Origin| header field [RFC6454] is used to protect against
357 unauthorized cross-origin use of a WebSocket server by scripts using
358 the WebSocket API in a web browser. The server is informed of the
359 script origin generating the WebSocket connection request. If the
360 server does not wish to accept connections from this origin, it can
361 choose to reject the connection by sending an appropriate HTTP error
362 code. This header field is sent by browser clients; for non-browser
363 clients, this header field may be sent if it makes sense in the
364 context of those clients.
365
366 Finally, the server has to prove to the client that it received the
367 client's WebSocket handshake, so that the server doesn't accept
368 connections that are not WebSocket connections. This prevents an
369 attacker from tricking a WebSocket server by sending it carefully
370 crafted packets using XMLHttpRequest [XMLHttpRequest] or a form
371 submission.
372
373 To prove that the handshake was received, the server has to take two
374 pieces of information and combine them to form a response. The first
375 piece of information comes from the |Sec-WebSocket-Key| header field
376 in the client handshake:
377
378 Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
379
380 For this header field, the server has to take the value (as present
381 in the header field, e.g., the base64-encoded [RFC4648] version minus
382 any leading and trailing whitespace) and concatenate this with the
383 Globally Unique Identifier (GUID, [RFC4122]) "258EAFA5-E914-47DA-
384 95CA-C5AB0DC85B11" in string form, which is unlikely to be used by
385 network endpoints that do not understand the WebSocket Protocol. A
386 SHA-1 hash (160 bits) [FIPS.180-3], base64-encoded (see Section 4 of
387 [RFC4648]), of this concatenation is then returned in the server's
388 handshake.
389
390
391
392
393
394Fette & Melnikov Standards Track [Page 7]
395
396RFC 6455 The WebSocket Protocol December 2011
397
398
399 Concretely, if as in the example above, the |Sec-WebSocket-Key|
400 header field had the value "dGhlIHNhbXBsZSBub25jZQ==", the server
401 would concatenate the string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
402 to form the string "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-
403 C5AB0DC85B11". The server would then take the SHA-1 hash of this,
404 giving the value 0xb3 0x7a 0x4f 0x2c 0xc0 0x62 0x4f 0x16 0x90 0xf6
405 0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe 0xc4 0xea. This value is
406 then base64-encoded (see Section 4 of [RFC4648]), to give the value
407 "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=". This value would then be echoed in
408 the |Sec-WebSocket-Accept| header field.
409
410 The handshake from the server is much simpler than the client
411 handshake. The first line is an HTTP Status-Line, with the status
412 code 101:
413
414 HTTP/1.1 101 Switching Protocols
415
416 Any status code other than 101 indicates that the WebSocket handshake
417 has not completed and that the semantics of HTTP still apply. The
418 headers follow the status code.
419
420 The |Connection| and |Upgrade| header fields complete the HTTP
421 Upgrade. The |Sec-WebSocket-Accept| header field indicates whether
422 the server is willing to accept the connection. If present, this
423 header field must include a hash of the client's nonce sent in
424 |Sec-WebSocket-Key| along with a predefined GUID. Any other value
425 must not be interpreted as an acceptance of the connection by the
426 server.
427
428 HTTP/1.1 101 Switching Protocols
429 Upgrade: websocket
430 Connection: Upgrade
431 Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
432
433 These fields are checked by the WebSocket client for scripted pages.
434 If the |Sec-WebSocket-Accept| value does not match the expected
435 value, if the header field is missing, or if the HTTP status code is
436 not 101, the connection will not be established, and WebSocket frames
437 will not be sent.
438
439 Option fields can also be included. In this version of the protocol,
440 the main option field is |Sec-WebSocket-Protocol|, which indicates
441 the subprotocol that the server has selected. WebSocket clients
442 verify that the server included one of the values that was specified
443 in the WebSocket client's handshake. A server that speaks multiple
444 subprotocols has to make sure it selects one based on the client's
445 handshake and specifies it in its handshake.
446
447
448
449
450Fette & Melnikov Standards Track [Page 8]
451
452RFC 6455 The WebSocket Protocol December 2011
453
454
455 Sec-WebSocket-Protocol: chat
456
457 The server can also set cookie-related option fields to _set_
458 cookies, as described in [RFC6265].
459
4601.4. Closing Handshake
461
462 _This section is non-normative._
463
464 The closing handshake is far simpler than the opening handshake.
465
466 Either peer can send a control frame with data containing a specified
467 control sequence to begin the closing handshake (detailed in
468 Section 5.5.1). Upon receiving such a frame, the other peer sends a
469 Close frame in response, if it hasn't already sent one. Upon
470 receiving _that_ control frame, the first peer then closes the
471 connection, safe in the knowledge that no further data is
472 forthcoming.
473
474 After sending a control frame indicating the connection should be
475 closed, a peer does not send any further data; after receiving a
476 control frame indicating the connection should be closed, a peer
477 discards any further data received.
478
479 It is safe for both peers to initiate this handshake simultaneously.
480
481 The closing handshake is intended to complement the TCP closing
482 handshake (FIN/ACK), on the basis that the TCP closing handshake is
483 not always reliable end-to-end, especially in the presence of
484 intercepting proxies and other intermediaries.
485
486 By sending a Close frame and waiting for a Close frame in response,
487 certain cases are avoided where data may be unnecessarily lost. For
488 instance, on some platforms, if a socket is closed with data in the
489 receive queue, a RST packet is sent, which will then cause recv() to
490 fail for the party that received the RST, even if there was data
491 waiting to be read.
492
4931.5. Design Philosophy
494
495 _This section is non-normative._
496
497 The WebSocket Protocol is designed on the principle that there should
498 be minimal framing (the only framing that exists is to make the
499 protocol frame-based instead of stream-based and to support a
500 distinction between Unicode text and binary frames). It is expected
501 that metadata would be layered on top of WebSocket by the application
502
503
504
505
506Fette & Melnikov Standards Track [Page 9]
507
508RFC 6455 The WebSocket Protocol December 2011
509
510
511 layer, in the same way that metadata is layered on top of TCP by the
512 application layer (e.g., HTTP).
513
514 Conceptually, WebSocket is really just a layer on top of TCP that
515 does the following:
516
517 o adds a web origin-based security model for browsers
518
519 o adds an addressing and protocol naming mechanism to support
520 multiple services on one port and multiple host names on one IP
521 address
522
523 o layers a framing mechanism on top of TCP to get back to the IP
524 packet mechanism that TCP is built on, but without length limits
525
526 o includes an additional closing handshake in-band that is designed
527 to work in the presence of proxies and other intermediaries
528
529 Other than that, WebSocket adds nothing. Basically it is intended to
530 be as close to just exposing raw TCP to script as possible given the
531 constraints of the Web. It's also designed in such a way that its
532 servers can share a port with HTTP servers, by having its handshake
533 be a valid HTTP Upgrade request. One could conceptually use other
534 protocols to establish client-server messaging, but the intent of
535 WebSockets is to provide a relatively simple protocol that can
536 coexist with HTTP and deployed HTTP infrastructure (such as proxies)
537 and that is as close to TCP as is safe for use with such
538 infrastructure given security considerations, with targeted additions
539 to simplify usage and keep simple things simple (such as the addition
540 of message semantics).
541
542 The protocol is intended to be extensible; future versions will
543 likely introduce additional concepts such as multiplexing.
544
5451.6. Security Model
546
547 _This section is non-normative._
548
549 The WebSocket Protocol uses the origin model used by web browsers to
550 restrict which web pages can contact a WebSocket server when the
551 WebSocket Protocol is used from a web page. Naturally, when the
552 WebSocket Protocol is used by a dedicated client directly (i.e., not
553 from a web page through a web browser), the origin model is not
554 useful, as the client can provide any arbitrary origin string.
555
556 This protocol is intended to fail to establish a connection with
557 servers of pre-existing protocols like SMTP [RFC5321] and HTTP, while
558 allowing HTTP servers to opt-in to supporting this protocol if
559
560
561
562Fette & Melnikov Standards Track [Page 10]
563
564RFC 6455 The WebSocket Protocol December 2011
565
566
567 desired. This is achieved by having a strict and elaborate handshake
568 and by limiting the data that can be inserted into the connection
569 before the handshake is finished (thus limiting how much the server
570 can be influenced).
571
572 It is similarly intended to fail to establish a connection when data
573 from other protocols, especially HTTP, is sent to a WebSocket server,
574 for example, as might happen if an HTML "form" were submitted to a
575 WebSocket server. This is primarily achieved by requiring that the
576 server prove that it read the handshake, which it can only do if the
577 handshake contains the appropriate parts, which can only be sent by a
578 WebSocket client. In particular, at the time of writing of this
579 specification, fields starting with |Sec-| cannot be set by an
580 attacker from a web browser using only HTML and JavaScript APIs such
581 as XMLHttpRequest [XMLHttpRequest].
582
5831.7. Relationship to TCP and HTTP
584
585 _This section is non-normative._
586
587 The WebSocket Protocol is an independent TCP-based protocol. Its
588 only relationship to HTTP is that its handshake is interpreted by
589 HTTP servers as an Upgrade request.
590
591 By default, the WebSocket Protocol uses port 80 for regular WebSocket
592 connections and port 443 for WebSocket connections tunneled over
593 Transport Layer Security (TLS) [RFC2818].
594
5951.8. Establishing a Connection
596
597 _This section is non-normative._
598
599 When a connection is to be made to a port that is shared by an HTTP
600 server (a situation that is quite likely to occur with traffic to
601 ports 80 and 443), the connection will appear to the HTTP server to
602 be a regular GET request with an Upgrade offer. In relatively simple
603 setups with just one IP address and a single server for all traffic
604 to a single hostname, this might allow a practical way for systems
605 based on the WebSocket Protocol to be deployed. In more elaborate
606 setups (e.g., with load balancers and multiple servers), a dedicated
607 set of hosts for WebSocket connections separate from the HTTP servers
608 is probably easier to manage. At the time of writing of this
609 specification, it should be noted that connections on ports 80 and
610 443 have significantly different success rates, with connections on
611 port 443 being significantly more likely to succeed, though this may
612 change with time.
613
614
615
616
617
618Fette & Melnikov Standards Track [Page 11]
619
620RFC 6455 The WebSocket Protocol December 2011
621
622
6231.9. Subprotocols Using the WebSocket Protocol
624
625 _This section is non-normative._
626
627 The client can request that the server use a specific subprotocol by
628 including the |Sec-WebSocket-Protocol| field in its handshake. If it
629 is specified, the server needs to include the same field and one of
630 the selected subprotocol values in its response for the connection to
631 be established.
632
633 These subprotocol names should be registered as per Section 11.5. To
634 avoid potential collisions, it is recommended to use names that
635 contain the ASCII version of the domain name of the subprotocol's
636 originator. For example, if Example Corporation were to create a
637 Chat subprotocol to be implemented by many servers around the Web,
638 they could name it "chat.example.com". If the Example Organization
639 called their competing subprotocol "chat.example.org", then the two
640 subprotocols could be implemented by servers simultaneously, with the
641 server dynamically selecting which subprotocol to use based on the
642 value sent by the client.
643
644 Subprotocols can be versioned in backward-incompatible ways by
645 changing the subprotocol name, e.g., going from
646 "bookings.example.net" to "v2.bookings.example.net". These
647 subprotocols would be considered completely separate by WebSocket
648 clients. Backward-compatible versioning can be implemented by
649 reusing the same subprotocol string but carefully designing the
650 actual subprotocol to support this kind of extensibility.
651
6522. Conformance Requirements
653
654 All diagrams, examples, and notes in this specification are non-
655 normative, as are all sections explicitly marked non-normative.
656 Everything else in this specification is normative.
657
658 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
659 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
660 document are to be interpreted as described in [RFC2119].
661
662 Requirements phrased in the imperative as part of algorithms (such as
663 "strip any leading space characters" or "return false and abort these
664 steps") are to be interpreted with the meaning of the key word
665 ("MUST", "SHOULD", "MAY", etc.) used in introducing the algorithm.
666
667
668
669
670
671
672
673
674Fette & Melnikov Standards Track [Page 12]
675
676RFC 6455 The WebSocket Protocol December 2011
677
678
679 Conformance requirements phrased as algorithms or specific steps MAY
680 be implemented in any manner, so long as the end result is
681 equivalent. (In particular, the algorithms defined in this
682 specification are intended to be easy to follow and not intended to
683 be performant.)
684
6852.1. Terminology and Other Conventions
686
687 _ASCII_ shall mean the character-encoding scheme defined in
688 [ANSI.X3-4.1986].
689
690 This document makes reference to UTF-8 values and uses UTF-8
691 notational formats as defined in STD 63 [RFC3629].
692
693 Key terms such as named algorithms or definitions are indicated like
694 _this_.
695
696 Names of header fields or variables are indicated like |this|.
697
698 Variable values are indicated like /this/.
699
700 This document references the procedure to _Fail the WebSocket
701 Connection_. This procedure is defined in Section 7.1.7.
702
703 _Converting a string to ASCII lowercase_ means replacing all
704 characters in the range U+0041 to U+005A (i.e., LATIN CAPITAL LETTER
705 A to LATIN CAPITAL LETTER Z) with the corresponding characters in the
706 range U+0061 to U+007A (i.e., LATIN SMALL LETTER A to LATIN SMALL
707 LETTER Z).
708
709 Comparing two strings in an _ASCII case-insensitive_ manner means
710 comparing them exactly, code point for code point, except that the
711 characters in the range U+0041 to U+005A (i.e., LATIN CAPITAL LETTER
712 A to LATIN CAPITAL LETTER Z) and the corresponding characters in the
713 range U+0061 to U+007A (i.e., LATIN SMALL LETTER A to LATIN SMALL
714 LETTER Z) are considered to also match.
715
716 The term "URI" is used in this document as defined in [RFC3986].
717
718 When an implementation is required to _send_ data as part of the
719 WebSocket Protocol, the implementation MAY delay the actual
720 transmission arbitrarily, e.g., buffering data so as to send fewer IP
721 packets.
722
723 Note that this document uses both [RFC5234] and [RFC2616] variants of
724 ABNF in different sections.
725
726
727
728
729
730Fette & Melnikov Standards Track [Page 13]
731
732RFC 6455 The WebSocket Protocol December 2011
733
734
7353. WebSocket URIs
736
737 This specification defines two URI schemes, using the ABNF syntax
738 defined in RFC 5234 [RFC5234], and terminology and ABNF productions
739 defined by the URI specification RFC 3986 [RFC3986].
740
741 ws-URI = "ws:" "//" host [ ":" port ] path [ "?" query ]
742 wss-URI = "wss:" "//" host [ ":" port ] path [ "?" query ]
743
744 host = <host, defined in [RFC3986], Section 3.2.2>
745 port = <port, defined in [RFC3986], Section 3.2.3>
746 path = <path-abempty, defined in [RFC3986], Section 3.3>
747 query = <query, defined in [RFC3986], Section 3.4>
748
749 The port component is OPTIONAL; the default for "ws" is port 80,
750 while the default for "wss" is port 443.
751
752 The URI is called "secure" (and it is said that "the secure flag is
753 set") if the scheme component matches "wss" case-insensitively.
754
755 The "resource-name" (also known as /resource name/ in Section 4.1)
756 can be constructed by concatenating the following:
757
758 o "/" if the path component is empty
759
760 o the path component
761
762 o "?" if the query component is non-empty
763
764 o the query component
765
766 Fragment identifiers are meaningless in the context of WebSocket URIs
767 and MUST NOT be used on these URIs. As with any URI scheme, the
768 character "#", when not indicating the start of a fragment, MUST be
769 escaped as %23.
770
7714. Opening Handshake
772
7734.1. Client Requirements
774
775 To _Establish a WebSocket Connection_, a client opens a connection
776 and sends a handshake as defined in this section. A connection is
777 defined to initially be in a CONNECTING state. A client will need to
778 supply a /host/, /port/, /resource name/, and a /secure/ flag, which
779 are the components of a WebSocket URI as discussed in Section 3,
780 along with a list of /protocols/ and /extensions/ to be used.
781 Additionally, if the client is a web browser, it supplies /origin/.
782
783
784
785
786Fette & Melnikov Standards Track [Page 14]
787
788RFC 6455 The WebSocket Protocol December 2011
789
790
791 Clients running in controlled environments, e.g., browsers on mobile
792 handsets tied to specific carriers, MAY offload the management of the
793 connection to another agent on the network. In such a situation, the
794 client for the purposes of this specification is considered to
795 include both the handset software and any such agents.
796
797 When the client is to _Establish a WebSocket Connection_ given a set
798 of (/host/, /port/, /resource name/, and /secure/ flag), along with a
799 list of /protocols/ and /extensions/ to be used, and an /origin/ in
800 the case of web browsers, it MUST open a connection, send an opening
801 handshake, and read the server's handshake in response. The exact
802 requirements of how the connection should be opened, what should be
803 sent in the opening handshake, and how the server's response should
804 be interpreted are as follows in this section. In the following
805 text, we will use terms from Section 3, such as "/host/" and
806 "/secure/ flag" as defined in that section.
807
808 1. The components of the WebSocket URI passed into this algorithm
809 (/host/, /port/, /resource name/, and /secure/ flag) MUST be
810 valid according to the specification of WebSocket URIs specified
811 in Section 3. If any of the components are invalid, the client
812 MUST _Fail the WebSocket Connection_ and abort these steps.
813
814 2. If the client already has a WebSocket connection to the remote
815 host (IP address) identified by /host/ and port /port/ pair, even
816 if the remote host is known by another name, the client MUST wait
817 until that connection has been established or for that connection
818 to have failed. There MUST be no more than one connection in a
819 CONNECTING state. If multiple connections to the same IP address
820 are attempted simultaneously, the client MUST serialize them so
821 that there is no more than one connection at a time running
822 through the following steps.
823
824 If the client cannot determine the IP address of the remote host
825 (for example, because all communication is being done through a
826 proxy server that performs DNS queries itself), then the client
827 MUST assume for the purposes of this step that each host name
828 refers to a distinct remote host, and instead the client SHOULD
829 limit the total number of simultaneous pending connections to a
830 reasonably low number (e.g., the client might allow simultaneous
831 pending connections to a.example.com and b.example.com, but if
832 thirty simultaneous connections to a single host are requested,
833 that may not be allowed). For example, in a web browser context,
834 the client needs to consider the number of tabs the user has open
835 in setting a limit to the number of simultaneous pending
836 connections.
837
838
839
840
841
842Fette & Melnikov Standards Track [Page 15]
843
844RFC 6455 The WebSocket Protocol December 2011
845
846
847 NOTE: This makes it harder for a script to perform a denial-of-
848 service attack by just opening a large number of WebSocket
849 connections to a remote host. A server can further reduce the
850 load on itself when attacked by pausing before closing the
851 connection, as that will reduce the rate at which the client
852 reconnects.
853
854 NOTE: There is no limit to the number of established WebSocket
855 connections a client can have with a single remote host. Servers
856 can refuse to accept connections from hosts/IP addresses with an
857 excessive number of existing connections or disconnect resource-
858 hogging connections when suffering high load.
859
860 3. _Proxy Usage_: If the client is configured to use a proxy when
861 using the WebSocket Protocol to connect to host /host/ and port
862 /port/, then the client SHOULD connect to that proxy and ask it
863 to open a TCP connection to the host given by /host/ and the port
864 given by /port/.
865
866 EXAMPLE: For example, if the client uses an HTTP proxy for all
867 traffic, then if it was to try to connect to port 80 on server
868 example.com, it might send the following lines to the proxy
869 server:
870
871 CONNECT example.com:80 HTTP/1.1
872 Host: example.com
873
874 If there was a password, the connection might look like:
875
876 CONNECT example.com:80 HTTP/1.1
877 Host: example.com
878 Proxy-authorization: Basic ZWRuYW1vZGU6bm9jYXBlcyE=
879
880 If the client is not configured to use a proxy, then a direct TCP
881 connection SHOULD be opened to the host given by /host/ and the
882 port given by /port/.
883
884 NOTE: Implementations that do not expose explicit UI for
885 selecting a proxy for WebSocket connections separate from other
886 proxies are encouraged to use a SOCKS5 [RFC1928] proxy for
887 WebSocket connections, if available, or failing that, to prefer
888 the proxy configured for HTTPS connections over the proxy
889 configured for HTTP connections.
890
891 For the purpose of proxy autoconfiguration scripts, the URI to
892 pass the function MUST be constructed from /host/, /port/,
893 /resource name/, and the /secure/ flag using the definition of a
894 WebSocket URI as given in Section 3.
895
896
897
898Fette & Melnikov Standards Track [Page 16]
899
900RFC 6455 The WebSocket Protocol December 2011
901
902
903 NOTE: The WebSocket Protocol can be identified in proxy
904 autoconfiguration scripts from the scheme ("ws" for unencrypted
905 connections and "wss" for encrypted connections).
906
907 4. If the connection could not be opened, either because a direct
908 connection failed or because any proxy used returned an error,
909 then the client MUST _Fail the WebSocket Connection_ and abort
910 the connection attempt.
911
912 5. If /secure/ is true, the client MUST perform a TLS handshake over
913 the connection after opening the connection and before sending
914 the handshake data [RFC2818]. If this fails (e.g., the server's
915 certificate could not be verified), then the client MUST _Fail
916 the WebSocket Connection_ and abort the connection. Otherwise,
917 all further communication on this channel MUST run through the
918 encrypted tunnel [RFC5246].
919
920 Clients MUST use the Server Name Indication extension in the TLS
921 handshake [RFC6066].
922
923 Once a connection to the server has been established (including a
924 connection via a proxy or over a TLS-encrypted tunnel), the client
925 MUST send an opening handshake to the server. The handshake consists
926 of an HTTP Upgrade request, along with a list of required and
927 optional header fields. The requirements for this handshake are as
928 follows.
929
930 1. The handshake MUST be a valid HTTP request as specified by
931 [RFC2616].
932
933 2. The method of the request MUST be GET, and the HTTP version MUST
934 be at least 1.1.
935
936 For example, if the WebSocket URI is "ws://example.com/chat",
937 the first line sent should be "GET /chat HTTP/1.1".
938
939 3. The "Request-URI" part of the request MUST match the /resource
940 name/ defined in Section 3 (a relative URI) or be an absolute
941 http/https URI that, when parsed, has a /resource name/, /host/,
942 and /port/ that match the corresponding ws/wss URI.
943
944 4. The request MUST contain a |Host| header field whose value
945 contains /host/ plus optionally ":" followed by /port/ (when not
946 using the default port).
947
948 5. The request MUST contain an |Upgrade| header field whose value
949 MUST include the "websocket" keyword.
950
951
952
953
954Fette & Melnikov Standards Track [Page 17]
955
956RFC 6455 The WebSocket Protocol December 2011
957
958
959 6. The request MUST contain a |Connection| header field whose value
960 MUST include the "Upgrade" token.
961
962 7. The request MUST include a header field with the name
963 |Sec-WebSocket-Key|. The value of this header field MUST be a
964 nonce consisting of a randomly selected 16-byte value that has
965 been base64-encoded (see Section 4 of [RFC4648]). The nonce
966 MUST be selected randomly for each connection.
967
968 NOTE: As an example, if the randomly selected value was the
969 sequence of bytes 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09
970 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10, the value of the header
971 field would be "AQIDBAUGBwgJCgsMDQ4PEC=="
972
973 8. The request MUST include a header field with the name |Origin|
974 [RFC6454] if the request is coming from a browser client. If
975 the connection is from a non-browser client, the request MAY
976 include this header field if the semantics of that client match
977 the use-case described here for browser clients. The value of
978 this header field is the ASCII serialization of origin of the
979 context in which the code establishing the connection is
980 running. See [RFC6454] for the details of how this header field
981 value is constructed.
982
983 As an example, if code downloaded from www.example.com attempts
984 to establish a connection to ww2.example.com, the value of the
985 header field would be "http://www.example.com".
986
987 9. The request MUST include a header field with the name
988 |Sec-WebSocket-Version|. The value of this header field MUST be
989 13.
990
991 NOTE: Although draft versions of this document (-09, -10, -11,
992 and -12) were posted (they were mostly comprised of editorial
993 changes and clarifications and not changes to the wire
994 protocol), values 9, 10, 11, and 12 were not used as valid
995 values for Sec-WebSocket-Version. These values were reserved in
996 the IANA registry but were not and will not be used.
997
998 10. The request MAY include a header field with the name
999 |Sec-WebSocket-Protocol|. If present, this value indicates one
1000 or more comma-separated subprotocol the client wishes to speak,
1001 ordered by preference. The elements that comprise this value
1002 MUST be non-empty strings with characters in the range U+0021 to
1003 U+007E not including separator characters as defined in
1004 [RFC2616] and MUST all be unique strings. The ABNF for the
1005 value of this header field is 1#token, where the definitions of
1006 constructs and rules are as given in [RFC2616].
1007
1008
1009
1010Fette & Melnikov Standards Track [Page 18]
1011
1012RFC 6455 The WebSocket Protocol December 2011
1013
1014
1015 11. The request MAY include a header field with the name
1016 |Sec-WebSocket-Extensions|. If present, this value indicates
1017 the protocol-level extension(s) the client wishes to speak. The
1018 interpretation and format of this header field is described in
1019 Section 9.1.
1020
1021 12. The request MAY include any other header fields, for example,
1022 cookies [RFC6265] and/or authentication-related header fields
1023 such as the |Authorization| header field [RFC2616], which are
1024 processed according to documents that define them.
1025
1026 Once the client's opening handshake has been sent, the client MUST
1027 wait for a response from the server before sending any further data.
1028 The client MUST validate the server's response as follows:
1029
1030 1. If the status code received from the server is not 101, the
1031 client handles the response per HTTP [RFC2616] procedures. In
1032 particular, the client might perform authentication if it
1033 receives a 401 status code; the server might redirect the client
1034 using a 3xx status code (but clients are not required to follow
1035 them), etc. Otherwise, proceed as follows.
1036
1037 2. If the response lacks an |Upgrade| header field or the |Upgrade|
1038 header field contains a value that is not an ASCII case-
1039 insensitive match for the value "websocket", the client MUST
1040 _Fail the WebSocket Connection_.
1041
1042 3. If the response lacks a |Connection| header field or the
1043 |Connection| header field doesn't contain a token that is an
1044 ASCII case-insensitive match for the value "Upgrade", the client
1045 MUST _Fail the WebSocket Connection_.
1046
1047 4. If the response lacks a |Sec-WebSocket-Accept| header field or
1048 the |Sec-WebSocket-Accept| contains a value other than the
1049 base64-encoded SHA-1 of the concatenation of the |Sec-WebSocket-
1050 Key| (as a string, not base64-decoded) with the string "258EAFA5-
1051 E914-47DA-95CA-C5AB0DC85B11" but ignoring any leading and
1052 trailing whitespace, the client MUST _Fail the WebSocket
1053 Connection_.
1054
1055 5. If the response includes a |Sec-WebSocket-Extensions| header
1056 field and this header field indicates the use of an extension
1057 that was not present in the client's handshake (the server has
1058 indicated an extension not requested by the client), the client
1059 MUST _Fail the WebSocket Connection_. (The parsing of this
1060 header field to determine which extensions are requested is
1061 discussed in Section 9.1.)
1062
1063
1064
1065
1066Fette & Melnikov Standards Track [Page 19]
1067
1068RFC 6455 The WebSocket Protocol December 2011
1069
1070
1071 6. If the response includes a |Sec-WebSocket-Protocol| header field
1072 and this header field indicates the use of a subprotocol that was
1073 not present in the client's handshake (the server has indicated a
1074 subprotocol not requested by the client), the client MUST _Fail
1075 the WebSocket Connection_.
1076
1077 If the server's response does not conform to the requirements for the
1078 server's handshake as defined in this section and in Section 4.2.2,
1079 the client MUST _Fail the WebSocket Connection_.
1080
1081 Please note that according to [RFC2616], all header field names in
1082 both HTTP requests and HTTP responses are case-insensitive.
1083
1084 If the server's response is validated as provided for above, it is
1085 said that _The WebSocket Connection is Established_ and that the
1086 WebSocket Connection is in the OPEN state. The _Extensions In Use_
1087 is defined to be a (possibly empty) string, the value of which is
1088 equal to the value of the |Sec-WebSocket-Extensions| header field
1089 supplied by the server's handshake or the null value if that header
1090 field was not present in the server's handshake. The _Subprotocol In
1091 Use_ is defined to be the value of the |Sec-WebSocket-Protocol|
1092 header field in the server's handshake or the null value if that
1093 header field was not present in the server's handshake.
1094 Additionally, if any header fields in the server's handshake indicate
1095 that cookies should be set (as defined by [RFC6265]), these cookies
1096 are referred to as _Cookies Set During the Server's Opening
1097 Handshake_.
1098
10994.2. Server-Side Requirements
1100
1101 Servers MAY offload the management of the connection to other agents
1102 on the network, for example, load balancers and reverse proxies. In
1103 such a situation, the server for the purposes of this specification
1104 is considered to include all parts of the server-side infrastructure
1105 from the first device to terminate the TCP connection all the way to
1106 the server that processes requests and sends responses.
1107
1108 EXAMPLE: A data center might have a server that responds to WebSocket
1109 requests with an appropriate handshake and then passes the connection
1110 to another server to actually process the data frames. For the
1111 purposes of this specification, the "server" is the combination of
1112 both computers.
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122Fette & Melnikov Standards Track [Page 20]
1123
1124RFC 6455 The WebSocket Protocol December 2011
1125
1126
11274.2.1. Reading the Client's Opening Handshake
1128
1129 When a client starts a WebSocket connection, it sends its part of the
1130 opening handshake. The server must parse at least part of this
1131 handshake in order to obtain the necessary information to generate
1132 the server part of the handshake.
1133
1134 The client's opening handshake consists of the following parts. If ../http/webserver.go:450
1135 the server, while reading the handshake, finds that the client did
1136 not send a handshake that matches the description below (note that as
1137 per [RFC2616], the order of the header fields is not important),
1138 including but not limited to any violations of the ABNF grammar
1139 specified for the components of the handshake, the server MUST stop
1140 processing the client's handshake and return an HTTP response with an
1141 appropriate error code (such as 400 Bad Request).
1142
1143 1. An HTTP/1.1 or higher GET request, including a "Request-URI" ../http/webserver.go:519
1144 [RFC2616] that should be interpreted as a /resource name/
1145 defined in Section 3 (or an absolute HTTP/HTTPS URI containing
1146 the /resource name/).
1147
1148 2. A |Host| header field containing the server's authority.
1149
1150 3. An |Upgrade| header field containing the value "websocket",
1151 treated as an ASCII case-insensitive value.
1152
1153 4. A |Connection| header field that includes the token "Upgrade", ../http/webserver.go:526
1154 treated as an ASCII case-insensitive value.
1155
1156 5. A |Sec-WebSocket-Key| header field with a base64-encoded (see ../http/webserver.go:540
1157 Section 4 of [RFC4648]) value that, when decoded, is 16 bytes in
1158 length.
1159
1160 6. A |Sec-WebSocket-Version| header field, with a value of 13. ../http/webserver.go:508
1161
1162 7. Optionally, an |Origin| header field. This header field is sent ../http/webserver.go:549
1163 by all browser clients. A connection attempt lacking this
1164 header field SHOULD NOT be interpreted as coming from a browser
1165 client.
1166
1167 8. Optionally, a |Sec-WebSocket-Protocol| header field, with a list
1168 of values indicating which protocols the client would like to
1169 speak, ordered by preference.
1170
1171 9. Optionally, a |Sec-WebSocket-Extensions| header field, with a
1172 list of values indicating which extensions the client would like
1173 to speak. The interpretation of this header field is discussed
1174 in Section 9.1.
1175
1176
1177
1178Fette & Melnikov Standards Track [Page 21]
1179
1180RFC 6455 The WebSocket Protocol December 2011
1181
1182
1183 10. Optionally, other header fields, such as those used to send
1184 cookies or request authentication to a server. Unknown header
1185 fields are ignored, as per [RFC2616].
1186
11874.2.2. Sending the Server's Opening Handshake
1188
1189 When a client establishes a WebSocket connection to a server, the
1190 server MUST complete the following steps to accept the connection and
1191 send the server's opening handshake.
1192
1193 1. If the connection is happening on an HTTPS (HTTP-over-TLS) port,
1194 perform a TLS handshake over the connection. If this fails
1195 (e.g., the client indicated a host name in the extended client
1196 hello "server_name" extension that the server does not host),
1197 then close the connection; otherwise, all further communication
1198 for the connection (including the server's handshake) MUST run
1199 through the encrypted tunnel [RFC5246].
1200
1201 2. The server can perform additional client authentication, for
1202 example, by returning a 401 status code with the corresponding
1203 |WWW-Authenticate| header field as described in [RFC2616].
1204
1205 3. The server MAY redirect the client using a 3xx status code
1206 [RFC2616]. Note that this step can happen together with, before,
1207 or after the optional authentication step described above.
1208
1209 4. Establish the following information:
1210
1211 /origin/
1212 The |Origin| header field in the client's handshake indicates
1213 the origin of the script establishing the connection. The
1214 origin is serialized to ASCII and converted to lowercase. The
1215 server MAY use this information as part of a determination of
1216 whether to accept the incoming connection. If the server does
1217 not validate the origin, it will accept connections from
1218 anywhere. If the server does not wish to accept this
1219 connection, it MUST return an appropriate HTTP error code
1220 (e.g., 403 Forbidden) and abort the WebSocket handshake
1221 described in this section. For more detail, refer to
1222 Section 10.
1223
1224 /key/
1225 The |Sec-WebSocket-Key| header field in the client's handshake
1226 includes a base64-encoded value that, if decoded, is 16 bytes
1227 in length. This (encoded) value is used in the creation of
1228 the server's handshake to indicate an acceptance of the
1229 connection. It is not necessary for the server to base64-
1230 decode the |Sec-WebSocket-Key| value.
1231
1232
1233
1234Fette & Melnikov Standards Track [Page 22]
1235
1236RFC 6455 The WebSocket Protocol December 2011
1237
1238
1239 /version/
1240 The |Sec-WebSocket-Version| header field in the client's
1241 handshake includes the version of the WebSocket Protocol with
1242 which the client is attempting to communicate. If this
1243 version does not match a version understood by the server, the
1244 server MUST abort the WebSocket handshake described in this
1245 section and instead send an appropriate HTTP error code (such
1246 as 426 Upgrade Required) and a |Sec-WebSocket-Version| header
1247 field indicating the version(s) the server is capable of
1248 understanding.
1249
1250 /resource name/
1251 An identifier for the service provided by the server. If the
1252 server provides multiple services, then the value should be
1253 derived from the resource name given in the client's handshake
1254 in the "Request-URI" [RFC2616] of the GET method. If the
1255 requested service is not available, the server MUST send an
1256 appropriate HTTP error code (such as 404 Not Found) and abort
1257 the WebSocket handshake.
1258
1259 /subprotocol/
1260 Either a single value representing the subprotocol the server
1261 is ready to use or null. The value chosen MUST be derived
1262 from the client's handshake, specifically by selecting one of
1263 the values from the |Sec-WebSocket-Protocol| field that the
1264 server is willing to use for this connection (if any). If the
1265 client's handshake did not contain such a header field or if
1266 the server does not agree to any of the client's requested
1267 subprotocols, the only acceptable value is null. The absence
1268 of such a field is equivalent to the null value (meaning that
1269 if the server does not wish to agree to one of the suggested
1270 subprotocols, it MUST NOT send back a |Sec-WebSocket-Protocol|
1271 header field in its response). The empty string is not the
1272 same as the null value for these purposes and is not a legal
1273 value for this field. The ABNF for the value of this header
1274 field is (token), where the definitions of constructs and
1275 rules are as given in [RFC2616].
1276
1277 /extensions/
1278 A (possibly empty) list representing the protocol-level
1279 extensions the server is ready to use. If the server supports
1280 multiple extensions, then the value MUST be derived from the
1281 client's handshake, specifically by selecting one or more of
1282 the values from the |Sec-WebSocket-Extensions| field. The
1283 absence of such a field is equivalent to the null value. The
1284 empty string is not the same as the null value for these
1285
1286
1287
1288
1289
1290Fette & Melnikov Standards Track [Page 23]
1291
1292RFC 6455 The WebSocket Protocol December 2011
1293
1294
1295 purposes. Extensions not listed by the client MUST NOT be
1296 listed. The method by which these values should be selected
1297 and interpreted is discussed in Section 9.1.
1298
1299 5. If the server chooses to accept the incoming connection, it MUST ../http/webserver.go:773
1300 reply with a valid HTTP response indicating the following.
1301
1302 1. A Status-Line with a 101 response code as per RFC 2616
1303 [RFC2616]. Such a response could look like "HTTP/1.1 101
1304 Switching Protocols".
1305
1306 2. An |Upgrade| header field with value "websocket" as per RFC
1307 2616 [RFC2616].
1308
1309 3. A |Connection| header field with value "Upgrade".
1310
1311 4. A |Sec-WebSocket-Accept| header field. The value of this
1312 header field is constructed by concatenating /key/, defined
1313 above in step 4 in Section 4.2.2, with the string "258EAFA5-
1314 E914-47DA-95CA-C5AB0DC85B11", taking the SHA-1 hash of this
1315 concatenated value to obtain a 20-byte value and base64-
1316 encoding (see Section 4 of [RFC4648]) this 20-byte hash.
1317
1318 The ABNF [RFC2616] of this header field is defined as
1319 follows:
1320
1321 Sec-WebSocket-Accept = base64-value-non-empty
1322 base64-value-non-empty = (1*base64-data [ base64-padding ]) |
1323 base64-padding
1324 base64-data = 4base64-character
1325 base64-padding = (2base64-character "==") |
1326 (3base64-character "=")
1327 base64-character = ALPHA | DIGIT | "+" | "/"
1328
1329 NOTE: As an example, if the value of the |Sec-WebSocket-Key| header
1330 field in the client's handshake were "dGhlIHNhbXBsZSBub25jZQ==", the
1331 server would append the string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
1332 to form the string "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-
1333 C5AB0DC85B11". The server would then take the SHA-1 hash of this
1334 string, giving the value 0xb3 0x7a 0x4f 0x2c 0xc0 0x62 0x4f 0x16 0x90
1335 0xf6 0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe 0xc4 0xea. This value
1336 is then base64-encoded, to give the value
1337 "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", which would be returned in the
1338 |Sec-WebSocket-Accept| header field.
1339
1340 5. Optionally, a |Sec-WebSocket-Protocol| header field, with a ../http/webserver.go:792
1341 value /subprotocol/ as defined in step 4 in Section 4.2.2.
1342
1343
1344
1345
1346Fette & Melnikov Standards Track [Page 24]
1347
1348RFC 6455 The WebSocket Protocol December 2011
1349
1350
1351 6. Optionally, a |Sec-WebSocket-Extensions| header field, with a
1352 value /extensions/ as defined in step 4 in Section 4.2.2. If
1353 multiple extensions are to be used, they can all be listed in
1354 a single |Sec-WebSocket-Extensions| header field or split
1355 between multiple instances of the |Sec-WebSocket-Extensions|
1356 header field.
1357
1358 This completes the server's handshake. If the server finishes these
1359 steps without aborting the WebSocket handshake, the server considers
1360 the WebSocket connection to be established and that the WebSocket
1361 connection is in the OPEN state. At this point, the server may begin
1362 sending (and receiving) data.
1363
13644.3. Collected ABNF for New Header Fields Used in Handshake
1365
1366 This section is using ABNF syntax/rules from Section 2.1 of
1367 [RFC2616], including the "implied *LWS rule".
1368
1369 Note that the following ABNF conventions are used in this section.
1370 Some names of the rules correspond to names of the corresponding
1371 header fields. Such rules express values of the corresponding header
1372 fields, for example, the Sec-WebSocket-Key ABNF rule describes syntax
1373 of the |Sec-WebSocket-Key| header field value. ABNF rules with the
1374 "-Client" suffix in the name are only used in requests sent by the
1375 client to the server; ABNF rules with the "-Server" suffix in the
1376 name are only used in responses sent by the server to the client.
1377 For example, the ABNF rule Sec-WebSocket-Protocol-Client describes
1378 syntax of the |Sec-WebSocket-Protocol| header field value sent by the
1379 client to the server.
1380
1381 The following new header fields can be sent during the handshake from
1382 the client to the server:
1383
1384 Sec-WebSocket-Key = base64-value-non-empty
1385 Sec-WebSocket-Extensions = extension-list
1386 Sec-WebSocket-Protocol-Client = 1#token
1387 Sec-WebSocket-Version-Client = version
1388
1389 base64-value-non-empty = (1*base64-data [ base64-padding ]) |
1390 base64-padding
1391 base64-data = 4base64-character
1392 base64-padding = (2base64-character "==") |
1393 (3base64-character "=")
1394 base64-character = ALPHA | DIGIT | "+" | "/"
1395 extension-list = 1#extension
1396 extension = extension-token *( ";" extension-param )
1397 extension-token = registered-token
1398 registered-token = token
1399
1400
1401
1402Fette & Melnikov Standards Track [Page 25]
1403
1404RFC 6455 The WebSocket Protocol December 2011
1405
1406
1407 extension-param = token [ "=" (token | quoted-string) ]
1408 ; When using the quoted-string syntax variant, the value
1409 ; after quoted-string unescaping MUST conform to the
1410 ; 'token' ABNF.
1411 NZDIGIT = "1" | "2" | "3" | "4" | "5" | "6" |
1412 "7" | "8" | "9"
1413 version = DIGIT | (NZDIGIT DIGIT) |
1414 ("1" DIGIT DIGIT) | ("2" DIGIT DIGIT)
1415 ; Limited to 0-255 range, with no leading zeros
1416
1417 The following new header fields can be sent during the handshake from
1418 the server to the client:
1419
1420 Sec-WebSocket-Extensions = extension-list
1421 Sec-WebSocket-Accept = base64-value-non-empty
1422 Sec-WebSocket-Protocol-Server = token
1423 Sec-WebSocket-Version-Server = 1#version
1424
14254.4. Supporting Multiple Versions of WebSocket Protocol
1426
1427 This section provides some guidance on supporting multiple versions
1428 of the WebSocket Protocol in clients and servers.
1429
1430 Using the WebSocket version advertisement capability (the
1431 |Sec-WebSocket-Version| header field), a client can initially request
1432 the version of the WebSocket Protocol that it prefers (which doesn't
1433 necessarily have to be the latest supported by the client). If the
1434 server supports the requested version and the handshake message is
1435 otherwise valid, the server will accept that version. If the server ../http/webserver.go:512
1436 doesn't support the requested version, it MUST respond with a
1437 |Sec-WebSocket-Version| header field (or multiple
1438 |Sec-WebSocket-Version| header fields) containing all versions it is
1439 willing to use. At this point, if the client supports one of the
1440 advertised versions, it can repeat the WebSocket handshake using a
1441 new version value.
1442
1443 The following example demonstrates version negotiation described
1444 above:
1445
1446 GET /chat HTTP/1.1
1447 Host: server.example.com
1448 Upgrade: websocket
1449 Connection: Upgrade
1450 ...
1451 Sec-WebSocket-Version: 25
1452
1453
1454
1455
1456
1457
1458Fette & Melnikov Standards Track [Page 26]
1459
1460RFC 6455 The WebSocket Protocol December 2011
1461
1462
1463 The response from the server might look as follows:
1464
1465 HTTP/1.1 400 Bad Request
1466 ...
1467 Sec-WebSocket-Version: 13, 8, 7
1468
1469 Note that the last response from the server might also look like:
1470
1471 HTTP/1.1 400 Bad Request
1472 ...
1473 Sec-WebSocket-Version: 13
1474 Sec-WebSocket-Version: 8, 7
1475
1476 The client now repeats the handshake that conforms to version 13:
1477
1478 GET /chat HTTP/1.1
1479 Host: server.example.com
1480 Upgrade: websocket
1481 Connection: Upgrade
1482 ...
1483 Sec-WebSocket-Version: 13
1484
14855. Data Framing
1486
14875.1. Overview
1488
1489 In the WebSocket Protocol, data is transmitted using a sequence of
1490 frames. To avoid confusing network intermediaries (such as
1491 intercepting proxies) and for security reasons that are further
1492 discussed in Section 10.3, a client MUST mask all frames that it
1493 sends to the server (see Section 5.3 for further details). (Note
1494 that masking is done whether or not the WebSocket Protocol is running
1495 over TLS.) The server MUST close the connection upon receiving a
1496 frame that is not masked. In this case, a server MAY send a Close
1497 frame with a status code of 1002 (protocol error) as defined in
1498 Section 7.4.1. A server MUST NOT mask any frames that it sends to
1499 the client. A client MUST close a connection if it detects a masked
1500 frame. In this case, it MAY use the status code 1002 (protocol
1501 error) as defined in Section 7.4.1. (These rules might be relaxed in
1502 a future specification.)
1503
1504 The base framing protocol defines a frame type with an opcode, a
1505 payload length, and designated locations for "Extension data" and
1506 "Application data", which together define the "Payload data".
1507 Certain bits and opcodes are reserved for future expansion of the
1508 protocol.
1509
1510
1511
1512
1513
1514Fette & Melnikov Standards Track [Page 27]
1515
1516RFC 6455 The WebSocket Protocol December 2011
1517
1518
1519 A data frame MAY be transmitted by either the client or the server at
1520 any time after opening handshake completion and before that endpoint
1521 has sent a Close frame (Section 5.5.1).
1522
15235.2. Base Framing Protocol
1524
1525 This wire format for the data transfer part is described by the ABNF
1526 [RFC5234] given in detail in this section. (Note that, unlike in
1527 other sections of this document, the ABNF in this section is
1528 operating on groups of bits. The length of each group of bits is
1529 indicated in a comment. When encoded on the wire, the most
1530 significant bit is the leftmost in the ABNF). A high-level overview
1531 of the framing is given in the following figure. In a case of
1532 conflict between the figure below and the ABNF specified later in
1533 this section, the figure is authoritative.
1534
1535 0 1 2 3
1536 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1537 +-+-+-+-+-------+-+-------------+-------------------------------+
1538 |F|R|R|R| opcode|M| Payload len | Extended payload length |
1539 |I|S|S|S| (4) |A| (7) | (16/64) |
1540 |N|V|V|V| |S| | (if payload len==126/127) |
1541 | |1|2|3| |K| | |
1542 +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
1543 | Extended payload length continued, if payload len == 127 |
1544 + - - - - - - - - - - - - - - - +-------------------------------+
1545 | |Masking-key, if MASK set to 1 |
1546 +-------------------------------+-------------------------------+
1547 | Masking-key (continued) | Payload Data |
1548 +-------------------------------- - - - - - - - - - - - - - - - +
1549 : Payload Data continued ... :
1550 + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
1551 | Payload Data continued ... |
1552 +---------------------------------------------------------------+
1553
1554 FIN: 1 bit
1555
1556 Indicates that this is the final fragment in a message. The first
1557 fragment MAY also be the final fragment.
1558
1559 RSV1, RSV2, RSV3: 1 bit each
1560
1561 MUST be 0 unless an extension is negotiated that defines meanings
1562 for non-zero values. If a nonzero value is received and none of
1563 the negotiated extensions defines the meaning of such a nonzero
1564 value, the receiving endpoint MUST _Fail the WebSocket
1565 Connection_.
1566
1567
1568
1569
1570Fette & Melnikov Standards Track [Page 28]
1571
1572RFC 6455 The WebSocket Protocol December 2011
1573
1574
1575 Opcode: 4 bits
1576
1577 Defines the interpretation of the "Payload data". If an unknown
1578 opcode is received, the receiving endpoint MUST _Fail the
1579 WebSocket Connection_. The following values are defined.
1580
1581 * %x0 denotes a continuation frame
1582
1583 * %x1 denotes a text frame
1584
1585 * %x2 denotes a binary frame
1586
1587 * %x3-7 are reserved for further non-control frames
1588
1589 * %x8 denotes a connection close
1590
1591 * %x9 denotes a ping
1592
1593 * %xA denotes a pong
1594
1595 * %xB-F are reserved for further control frames
1596
1597 Mask: 1 bit
1598
1599 Defines whether the "Payload data" is masked. If set to 1, a
1600 masking key is present in masking-key, and this is used to unmask
1601 the "Payload data" as per Section 5.3. All frames sent from
1602 client to server have this bit set to 1.
1603
1604 Payload length: 7 bits, 7+16 bits, or 7+64 bits
1605
1606 The length of the "Payload data", in bytes: if 0-125, that is the
1607 payload length. If 126, the following 2 bytes interpreted as a
1608 16-bit unsigned integer are the payload length. If 127, the
1609 following 8 bytes interpreted as a 64-bit unsigned integer (the
1610 most significant bit MUST be 0) are the payload length. Multibyte
1611 length quantities are expressed in network byte order. Note that
1612 in all cases, the minimal number of bytes MUST be used to encode
1613 the length, for example, the length of a 124-byte-long string
1614 can't be encoded as the sequence 126, 0, 124. The payload length
1615 is the length of the "Extension data" + the length of the
1616 "Application data". The length of the "Extension data" may be
1617 zero, in which case the payload length is the length of the
1618 "Application data".
1619
1620
1621
1622
1623
1624
1625
1626Fette & Melnikov Standards Track [Page 29]
1627
1628RFC 6455 The WebSocket Protocol December 2011
1629
1630
1631 Masking-key: 0 or 4 bytes
1632
1633 All frames sent from the client to the server are masked by a
1634 32-bit value that is contained within the frame. This field is
1635 present if the mask bit is set to 1 and is absent if the mask bit
1636 is set to 0. See Section 5.3 for further information on client-
1637 to-server masking.
1638
1639 Payload data: (x+y) bytes
1640
1641 The "Payload data" is defined as "Extension data" concatenated
1642 with "Application data".
1643
1644 Extension data: x bytes
1645
1646 The "Extension data" is 0 bytes unless an extension has been
1647 negotiated. Any extension MUST specify the length of the
1648 "Extension data", or how that length may be calculated, and how
1649 the extension use MUST be negotiated during the opening handshake.
1650 If present, the "Extension data" is included in the total payload
1651 length.
1652
1653 Application data: y bytes
1654
1655 Arbitrary "Application data", taking up the remainder of the frame
1656 after any "Extension data". The length of the "Application data"
1657 is equal to the payload length minus the length of the "Extension
1658 data".
1659
1660 The base framing protocol is formally defined by the following ABNF
1661 [RFC5234]. It is important to note that the representation of this
1662 data is binary, not ASCII characters. As such, a field with a length
1663 of 1 bit that takes values %x0 / %x1 is represented as a single bit
1664 whose value is 0 or 1, not a full byte (octet) that stands for the
1665 characters "0" or "1" in the ASCII encoding. A field with a length
1666 of 4 bits with values between %x0-F again is represented by 4 bits,
1667 again NOT by an ASCII character or full byte (octet) with these
1668 values. [RFC5234] does not specify a character encoding: "Rules
1669 resolve into a string of terminal values, sometimes called
1670 characters. In ABNF, a character is merely a non-negative integer.
1671 In certain contexts, a specific mapping (encoding) of values into a
1672 character set (such as ASCII) will be specified." Here, the
1673 specified encoding is a binary encoding where each terminal value is
1674 encoded in the specified number of bits, which varies for each field.
1675
1676
1677
1678
1679
1680
1681
1682Fette & Melnikov Standards Track [Page 30]
1683
1684RFC 6455 The WebSocket Protocol December 2011
1685
1686
1687 ws-frame = frame-fin ; 1 bit in length
1688 frame-rsv1 ; 1 bit in length
1689 frame-rsv2 ; 1 bit in length
1690 frame-rsv3 ; 1 bit in length
1691 frame-opcode ; 4 bits in length
1692 frame-masked ; 1 bit in length
1693 frame-payload-length ; either 7, 7+16,
1694 ; or 7+64 bits in
1695 ; length
1696 [ frame-masking-key ] ; 32 bits in length
1697 frame-payload-data ; n*8 bits in
1698 ; length, where
1699 ; n >= 0
1700
1701 frame-fin = %x0 ; more frames of this message follow
1702 / %x1 ; final frame of this message
1703 ; 1 bit in length
1704
1705 frame-rsv1 = %x0 / %x1
1706 ; 1 bit in length, MUST be 0 unless
1707 ; negotiated otherwise
1708
1709 frame-rsv2 = %x0 / %x1
1710 ; 1 bit in length, MUST be 0 unless
1711 ; negotiated otherwise
1712
1713 frame-rsv3 = %x0 / %x1
1714 ; 1 bit in length, MUST be 0 unless
1715 ; negotiated otherwise
1716
1717 frame-opcode = frame-opcode-non-control /
1718 frame-opcode-control /
1719 frame-opcode-cont
1720
1721 frame-opcode-cont = %x0 ; frame continuation
1722
1723 frame-opcode-non-control= %x1 ; text frame
1724 / %x2 ; binary frame
1725 / %x3-7
1726 ; 4 bits in length,
1727 ; reserved for further non-control frames
1728
1729 frame-opcode-control = %x8 ; connection close
1730 / %x9 ; ping
1731 / %xA ; pong
1732 / %xB-F ; reserved for further control
1733 ; frames
1734 ; 4 bits in length
1735
1736
1737
1738Fette & Melnikov Standards Track [Page 31]
1739
1740RFC 6455 The WebSocket Protocol December 2011
1741
1742
1743 frame-masked = %x0
1744 ; frame is not masked, no frame-masking-key
1745 / %x1
1746 ; frame is masked, frame-masking-key present
1747 ; 1 bit in length
1748
1749 frame-payload-length = ( %x00-7D )
1750 / ( %x7E frame-payload-length-16 )
1751 / ( %x7F frame-payload-length-63 )
1752 ; 7, 7+16, or 7+64 bits in length,
1753 ; respectively
1754
1755 frame-payload-length-16 = %x0000-FFFF ; 16 bits in length
1756
1757 frame-payload-length-63 = %x0000000000000000-7FFFFFFFFFFFFFFF
1758 ; 64 bits in length
1759
1760 frame-masking-key = 4( %x00-FF )
1761 ; present only if frame-masked is 1
1762 ; 32 bits in length
1763
1764 frame-payload-data = (frame-masked-extension-data
1765 frame-masked-application-data)
1766 ; when frame-masked is 1
1767 / (frame-unmasked-extension-data
1768 frame-unmasked-application-data)
1769 ; when frame-masked is 0
1770
1771 frame-masked-extension-data = *( %x00-FF )
1772 ; reserved for future extensibility
1773 ; n*8 bits in length, where n >= 0
1774
1775 frame-masked-application-data = *( %x00-FF )
1776 ; n*8 bits in length, where n >= 0
1777
1778 frame-unmasked-extension-data = *( %x00-FF )
1779 ; reserved for future extensibility
1780 ; n*8 bits in length, where n >= 0
1781
1782 frame-unmasked-application-data = *( %x00-FF )
1783 ; n*8 bits in length, where n >= 0
1784
17855.3. Client-to-Server Masking
1786
1787 A masked frame MUST have the field frame-masked set to 1, as defined
1788 in Section 5.2.
1789
1790
1791
1792
1793
1794Fette & Melnikov Standards Track [Page 32]
1795
1796RFC 6455 The WebSocket Protocol December 2011
1797
1798
1799 The masking key is contained completely within the frame, as defined
1800 in Section 5.2 as frame-masking-key. It is used to mask the "Payload
1801 data" defined in the same section as frame-payload-data, which
1802 includes "Extension data" and "Application data".
1803
1804 The masking key is a 32-bit value chosen at random by the client.
1805 When preparing a masked frame, the client MUST pick a fresh masking
1806 key from the set of allowed 32-bit values. The masking key needs to
1807 be unpredictable; thus, the masking key MUST be derived from a strong
1808 source of entropy, and the masking key for a given frame MUST NOT
1809 make it simple for a server/proxy to predict the masking key for a
1810 subsequent frame. The unpredictability of the masking key is
1811 essential to prevent authors of malicious applications from selecting
1812 the bytes that appear on the wire. RFC 4086 [RFC4086] discusses what
1813 entails a suitable source of entropy for security-sensitive
1814 applications.
1815
1816 The masking does not affect the length of the "Payload data". To
1817 convert masked data into unmasked data, or vice versa, the following
1818 algorithm is applied. The same algorithm applies regardless of the
1819 direction of the translation, e.g., the same steps are applied to
1820 mask the data as to unmask the data.
1821
1822 Octet i of the transformed data ("transformed-octet-i") is the XOR of
1823 octet i of the original data ("original-octet-i") with octet at index
1824 i modulo 4 of the masking key ("masking-key-octet-j"):
1825
1826 j = i MOD 4
1827 transformed-octet-i = original-octet-i XOR masking-key-octet-j
1828
1829 The payload length, indicated in the framing as frame-payload-length,
1830 does NOT include the length of the masking key. It is the length of
1831 the "Payload data", e.g., the number of bytes following the masking
1832 key.
1833
18345.4. Fragmentation
1835
1836 The primary purpose of fragmentation is to allow sending a message
1837 that is of unknown size when the message is started without having to
1838 buffer that message. If messages couldn't be fragmented, then an
1839 endpoint would have to buffer the entire message so its length could
1840 be counted before the first byte is sent. With fragmentation, a
1841 server or intermediary may choose a reasonable size buffer and, when
1842 the buffer is full, write a fragment to the network.
1843
1844 A secondary use-case for fragmentation is for multiplexing, where it
1845 is not desirable for a large message on one logical channel to
1846 monopolize the output channel, so the multiplexing needs to be free
1847
1848
1849
1850Fette & Melnikov Standards Track [Page 33]
1851
1852RFC 6455 The WebSocket Protocol December 2011
1853
1854
1855 to split the message into smaller fragments to better share the
1856 output channel. (Note that the multiplexing extension is not
1857 described in this document.)
1858
1859 Unless specified otherwise by an extension, frames have no semantic
1860 meaning. An intermediary might coalesce and/or split frames, if no
1861 extensions were negotiated by the client and the server or if some
1862 extensions were negotiated, but the intermediary understood all the
1863 extensions negotiated and knows how to coalesce and/or split frames
1864 in the presence of these extensions. One implication of this is that
1865 in absence of extensions, senders and receivers must not depend on
1866 the presence of specific frame boundaries.
1867
1868 The following rules apply to fragmentation:
1869
1870 o An unfragmented message consists of a single frame with the FIN
1871 bit set (Section 5.2) and an opcode other than 0.
1872
1873 o A fragmented message consists of a single frame with the FIN bit
1874 clear and an opcode other than 0, followed by zero or more frames
1875 with the FIN bit clear and the opcode set to 0, and terminated by
1876 a single frame with the FIN bit set and an opcode of 0. A
1877 fragmented message is conceptually equivalent to a single larger
1878 message whose payload is equal to the concatenation of the
1879 payloads of the fragments in order; however, in the presence of
1880 extensions, this may not hold true as the extension defines the
1881 interpretation of the "Extension data" present. For instance,
1882 "Extension data" may only be present at the beginning of the first
1883 fragment and apply to subsequent fragments, or there may be
1884 "Extension data" present in each of the fragments that applies
1885 only to that particular fragment. In the absence of "Extension
1886 data", the following example demonstrates how fragmentation works.
1887
1888 EXAMPLE: For a text message sent as three fragments, the first
1889 fragment would have an opcode of 0x1 and a FIN bit clear, the
1890 second fragment would have an opcode of 0x0 and a FIN bit clear,
1891 and the third fragment would have an opcode of 0x0 and a FIN bit
1892 that is set.
1893
1894 o Control frames (see Section 5.5) MAY be injected in the middle of
1895 a fragmented message. Control frames themselves MUST NOT be
1896 fragmented.
1897
1898 o Message fragments MUST be delivered to the recipient in the order
1899 sent by the sender.
1900
1901
1902
1903
1904
1905
1906Fette & Melnikov Standards Track [Page 34]
1907
1908RFC 6455 The WebSocket Protocol December 2011
1909
1910
1911 o The fragments of one message MUST NOT be interleaved between the
1912 fragments of another message unless an extension has been
1913 negotiated that can interpret the interleaving.
1914
1915 o An endpoint MUST be capable of handling control frames in the
1916 middle of a fragmented message.
1917
1918 o A sender MAY create fragments of any size for non-control
1919 messages.
1920
1921 o Clients and servers MUST support receiving both fragmented and
1922 unfragmented messages.
1923
1924 o As control frames cannot be fragmented, an intermediary MUST NOT
1925 attempt to change the fragmentation of a control frame.
1926
1927 o An intermediary MUST NOT change the fragmentation of a message if
1928 any reserved bit values are used and the meaning of these values
1929 is not known to the intermediary.
1930
1931 o An intermediary MUST NOT change the fragmentation of any message
1932 in the context of a connection where extensions have been
1933 negotiated and the intermediary is not aware of the semantics of
1934 the negotiated extensions. Similarly, an intermediary that didn't
1935 see the WebSocket handshake (and wasn't notified about its
1936 content) that resulted in a WebSocket connection MUST NOT change
1937 the fragmentation of any message of such connection.
1938
1939 o As a consequence of these rules, all fragments of a message are of
1940 the same type, as set by the first fragment's opcode. Since
1941 control frames cannot be fragmented, the type for all fragments in
1942 a message MUST be either text, binary, or one of the reserved
1943 opcodes.
1944
1945 NOTE: If control frames could not be interjected, the latency of a
1946 ping, for example, would be very long if behind a large message.
1947 Hence, the requirement of handling control frames in the middle of a
1948 fragmented message.
1949
1950 IMPLEMENTATION NOTE: In the absence of any extension, a receiver
1951 doesn't have to buffer the whole frame in order to process it. For
1952 example, if a streaming API is used, a part of a frame can be
1953 delivered to the application. However, note that this assumption
1954 might not hold true for all future WebSocket extensions.
1955
1956
1957
1958
1959
1960
1961
1962Fette & Melnikov Standards Track [Page 35]
1963
1964RFC 6455 The WebSocket Protocol December 2011
1965
1966
19675.5. Control Frames
1968
1969 Control frames are identified by opcodes where the most significant
1970 bit of the opcode is 1. Currently defined opcodes for control frames
1971 include 0x8 (Close), 0x9 (Ping), and 0xA (Pong). Opcodes 0xB-0xF are
1972 reserved for further control frames yet to be defined.
1973
1974 Control frames are used to communicate state about the WebSocket.
1975 Control frames can be interjected in the middle of a fragmented
1976 message.
1977
1978 All control frames MUST have a payload length of 125 bytes or less
1979 and MUST NOT be fragmented.
1980
19815.5.1. Close
1982
1983 The Close frame contains an opcode of 0x8.
1984
1985 The Close frame MAY contain a body (the "Application data" portion of
1986 the frame) that indicates a reason for closing, such as an endpoint
1987 shutting down, an endpoint having received a frame too large, or an
1988 endpoint having received a frame that does not conform to the format
1989 expected by the endpoint. If there is a body, the first two bytes of
1990 the body MUST be a 2-byte unsigned integer (in network byte order)
1991 representing a status code with value /code/ defined in Section 7.4.
1992 Following the 2-byte integer, the body MAY contain UTF-8-encoded data
1993 with value /reason/, the interpretation of which is not defined by
1994 this specification. This data is not necessarily human readable but
1995 may be useful for debugging or passing information relevant to the
1996 script that opened the connection. As the data is not guaranteed to
1997 be human readable, clients MUST NOT show it to end users.
1998
1999 Close frames sent from client to server must be masked as per
2000 Section 5.3.
2001
2002 The application MUST NOT send any more data frames after sending a
2003 Close frame.
2004
2005 If an endpoint receives a Close frame and did not previously send a
2006 Close frame, the endpoint MUST send a Close frame in response. (When
2007 sending a Close frame in response, the endpoint typically echos the
2008 status code it received.) It SHOULD do so as soon as practical. An
2009 endpoint MAY delay sending a Close frame until its current message is
2010 sent (for instance, if the majority of a fragmented message is
2011 already sent, an endpoint MAY send the remaining fragments before
2012 sending a Close frame). However, there is no guarantee that the
2013 endpoint that has already sent a Close frame will continue to process
2014 data.
2015
2016
2017
2018Fette & Melnikov Standards Track [Page 36]
2019
2020RFC 6455 The WebSocket Protocol December 2011
2021
2022
2023 After both sending and receiving a Close message, an endpoint
2024 considers the WebSocket connection closed and MUST close the
2025 underlying TCP connection. The server MUST close the underlying TCP
2026 connection immediately; the client SHOULD wait for the server to
2027 close the connection but MAY close the connection at any time after
2028 sending and receiving a Close message, e.g., if it has not received a
2029 TCP Close from the server in a reasonable time period.
2030
2031 If a client and server both send a Close message at the same time,
2032 both endpoints will have sent and received a Close message and should
2033 consider the WebSocket connection closed and close the underlying TCP
2034 connection.
2035
20365.5.2. Ping
2037
2038 The Ping frame contains an opcode of 0x9.
2039
2040 A Ping frame MAY include "Application data".
2041
2042 Upon receipt of a Ping frame, an endpoint MUST send a Pong frame in
2043 response, unless it already received a Close frame. It SHOULD
2044 respond with Pong frame as soon as is practical. Pong frames are
2045 discussed in Section 5.5.3.
2046
2047 An endpoint MAY send a Ping frame any time after the connection is
2048 established and before the connection is closed.
2049
2050 NOTE: A Ping frame may serve either as a keepalive or as a means to
2051 verify that the remote endpoint is still responsive.
2052
20535.5.3. Pong
2054
2055 The Pong frame contains an opcode of 0xA.
2056
2057 Section 5.5.2 details requirements that apply to both Ping and Pong
2058 frames.
2059
2060 A Pong frame sent in response to a Ping frame must have identical
2061 "Application data" as found in the message body of the Ping frame
2062 being replied to.
2063
2064 If an endpoint receives a Ping frame and has not yet sent Pong
2065 frame(s) in response to previous Ping frame(s), the endpoint MAY
2066 elect to send a Pong frame for only the most recently processed Ping
2067 frame.
2068
2069
2070
2071
2072
2073
2074Fette & Melnikov Standards Track [Page 37]
2075
2076RFC 6455 The WebSocket Protocol December 2011
2077
2078
2079 A Pong frame MAY be sent unsolicited. This serves as a
2080 unidirectional heartbeat. A response to an unsolicited Pong frame is
2081 not expected.
2082
20835.6. Data Frames
2084
2085 Data frames (e.g., non-control frames) are identified by opcodes
2086 where the most significant bit of the opcode is 0. Currently defined
2087 opcodes for data frames include 0x1 (Text), 0x2 (Binary). Opcodes
2088 0x3-0x7 are reserved for further non-control frames yet to be
2089 defined.
2090
2091 Data frames carry application-layer and/or extension-layer data. The
2092 opcode determines the interpretation of the data:
2093
2094 Text
2095
2096 The "Payload data" is text data encoded as UTF-8. Note that a
2097 particular text frame might include a partial UTF-8 sequence;
2098 however, the whole message MUST contain valid UTF-8. Invalid
2099 UTF-8 in reassembled messages is handled as described in
2100 Section 8.1.
2101
2102 Binary
2103
2104 The "Payload data" is arbitrary binary data whose interpretation
2105 is solely up to the application layer.
2106
21075.7. Examples
2108
2109 o A single-frame unmasked text message
2110
2111 * 0x81 0x05 0x48 0x65 0x6c 0x6c 0x6f (contains "Hello")
2112
2113 o A single-frame masked text message
2114
2115 * 0x81 0x85 0x37 0xfa 0x21 0x3d 0x7f 0x9f 0x4d 0x51 0x58
2116 (contains "Hello")
2117
2118 o A fragmented unmasked text message
2119
2120 * 0x01 0x03 0x48 0x65 0x6c (contains "Hel")
2121
2122 * 0x80 0x02 0x6c 0x6f (contains "lo")
2123
2124
2125
2126
2127
2128
2129
2130Fette & Melnikov Standards Track [Page 38]
2131
2132RFC 6455 The WebSocket Protocol December 2011
2133
2134
2135 o Unmasked Ping request and masked Ping response
2136
2137 * 0x89 0x05 0x48 0x65 0x6c 0x6c 0x6f (contains a body of "Hello",
2138 but the contents of the body are arbitrary)
2139
2140 * 0x8a 0x85 0x37 0xfa 0x21 0x3d 0x7f 0x9f 0x4d 0x51 0x58
2141 (contains a body of "Hello", matching the body of the ping)
2142
2143 o 256 bytes binary message in a single unmasked frame
2144
2145 * 0x82 0x7E 0x0100 [256 bytes of binary data]
2146
2147 o 64KiB binary message in a single unmasked frame
2148
2149 * 0x82 0x7F 0x0000000000010000 [65536 bytes of binary data]
2150
21515.8. Extensibility
2152
2153 The protocol is designed to allow for extensions, which will add
2154 capabilities to the base protocol. The endpoints of a connection
2155 MUST negotiate the use of any extensions during the opening
2156 handshake. This specification provides opcodes 0x3 through 0x7 and
2157 0xB through 0xF, the "Extension data" field, and the frame-rsv1,
2158 frame-rsv2, and frame-rsv3 bits of the frame header for use by
2159 extensions. The negotiation of extensions is discussed in further
2160 detail in Section 9.1. Below are some anticipated uses of
2161 extensions. This list is neither complete nor prescriptive.
2162
2163 o "Extension data" may be placed in the "Payload data" before the
2164 "Application data".
2165
2166 o Reserved bits can be allocated for per-frame needs.
2167
2168 o Reserved opcode values can be defined.
2169
2170 o Reserved bits can be allocated to the opcode field if more opcode
2171 values are needed.
2172
2173 o A reserved bit or an "extension" opcode can be defined that
2174 allocates additional bits out of the "Payload data" to define
2175 larger opcodes or more per-frame bits.
2176
21776. Sending and Receiving Data
2178
21796.1. Sending Data
2180
2181 To _Send a WebSocket Message_ comprising of /data/ over a WebSocket
2182 connection, an endpoint MUST perform the following steps.
2183
2184
2185
2186Fette & Melnikov Standards Track [Page 39]
2187
2188RFC 6455 The WebSocket Protocol December 2011
2189
2190
2191 1. The endpoint MUST ensure the WebSocket connection is in the OPEN
2192 state (cf. Sections 4.1 and 4.2.2.) If at any point the state of
2193 the WebSocket connection changes, the endpoint MUST abort the
2194 following steps.
2195
2196 2. An endpoint MUST encapsulate the /data/ in a WebSocket frame as
2197 defined in Section 5.2. If the data to be sent is large or if
2198 the data is not available in its entirety at the point the
2199 endpoint wishes to begin sending the data, the endpoint MAY
2200 alternately encapsulate the data in a series of frames as defined
2201 in Section 5.4.
2202
2203 3. The opcode (frame-opcode) of the first frame containing the data
2204 MUST be set to the appropriate value from Section 5.2 for data
2205 that is to be interpreted by the recipient as text or binary
2206 data.
2207
2208 4. The FIN bit (frame-fin) of the last frame containing the data
2209 MUST be set to 1 as defined in Section 5.2.
2210
2211 5. If the data is being sent by the client, the frame(s) MUST be
2212 masked as defined in Section 5.3.
2213
2214 6. If any extensions (Section 9) have been negotiated for the
2215 WebSocket connection, additional considerations may apply as per
2216 the definition of those extensions.
2217
2218 7. The frame(s) that have been formed MUST be transmitted over the
2219 underlying network connection.
2220
22216.2. Receiving Data
2222
2223 To receive WebSocket data, an endpoint listens on the underlying
2224 network connection. Incoming data MUST be parsed as WebSocket frames
2225 as defined in Section 5.2. If a control frame (Section 5.5) is
2226 received, the frame MUST be handled as defined by Section 5.5. Upon
2227 receiving a data frame (Section 5.6), the endpoint MUST note the
2228 /type/ of the data as defined by the opcode (frame-opcode) from
2229 Section 5.2. The "Application data" from this frame is defined as
2230 the /data/ of the message. If the frame comprises an unfragmented
2231 message (Section 5.4), it is said that _A WebSocket Message Has Been
2232 Received_ with type /type/ and data /data/. If the frame is part of
2233 a fragmented message, the "Application data" of the subsequent data
2234 frames is concatenated to form the /data/. When the last fragment is
2235 received as indicated by the FIN bit (frame-fin), it is said that _A
2236 WebSocket Message Has Been Received_ with data /data/ (comprised of
2237 the concatenation of the "Application data" of the fragments) and
2238
2239
2240
2241
2242Fette & Melnikov Standards Track [Page 40]
2243
2244RFC 6455 The WebSocket Protocol December 2011
2245
2246
2247 type /type/ (noted from the first frame of the fragmented message).
2248 Subsequent data frames MUST be interpreted as belonging to a new
2249 WebSocket message.
2250
2251 Extensions (Section 9) MAY change the semantics of how data is read,
2252 specifically including what comprises a message boundary.
2253 Extensions, in addition to adding "Extension data" before the
2254 "Application data" in a payload, MAY also modify the "Application
2255 data" (such as by compressing it).
2256
2257 A server MUST remove masking for data frames received from a client
2258 as described in Section 5.3.
2259
22607. Closing the Connection
2261
22627.1. Definitions
2263
22647.1.1. Close the WebSocket Connection
2265
2266 To _Close the WebSocket Connection_, an endpoint closes the
2267 underlying TCP connection. An endpoint SHOULD use a method that
2268 cleanly closes the TCP connection, as well as the TLS session, if
2269 applicable, discarding any trailing bytes that may have been
2270 received. An endpoint MAY close the connection via any means
2271 available when necessary, such as when under attack.
2272
2273 The underlying TCP connection, in most normal cases, SHOULD be closed
2274 first by the server, so that it holds the TIME_WAIT state and not the
2275 client (as this would prevent it from re-opening the connection for 2
2276 maximum segment lifetimes (2MSL), while there is no corresponding
2277 server impact as a TIME_WAIT connection is immediately reopened upon
2278 a new SYN with a higher seq number). In abnormal cases (such as not
2279 having received a TCP Close from the server after a reasonable amount
2280 of time) a client MAY initiate the TCP Close. As such, when a server
2281 is instructed to _Close the WebSocket Connection_ it SHOULD initiate
2282 a TCP Close immediately, and when a client is instructed to do the
2283 same, it SHOULD wait for a TCP Close from the server.
2284
2285 As an example of how to obtain a clean closure in C using Berkeley
2286 sockets, one would call shutdown() with SHUT_WR on the socket, call
2287 recv() until obtaining a return value of 0 indicating that the peer
2288 has also performed an orderly shutdown, and finally call close() on
2289 the socket.
2290
2291
2292
2293
2294
2295
2296
2297
2298Fette & Melnikov Standards Track [Page 41]
2299
2300RFC 6455 The WebSocket Protocol December 2011
2301
2302
23037.1.2. Start the WebSocket Closing Handshake
2304
2305 To _Start the WebSocket Closing Handshake_ with a status code
2306 (Section 7.4) /code/ and an optional close reason (Section 7.1.6)
2307 /reason/, an endpoint MUST send a Close control frame, as described
2308 in Section 5.5.1, whose status code is set to /code/ and whose close
2309 reason is set to /reason/. Once an endpoint has both sent and
2310 received a Close control frame, that endpoint SHOULD _Close the
2311 WebSocket Connection_ as defined in Section 7.1.1.
2312
23137.1.3. The WebSocket Closing Handshake is Started
2314
2315 Upon either sending or receiving a Close control frame, it is said
2316 that _The WebSocket Closing Handshake is Started_ and that the
2317 WebSocket connection is in the CLOSING state.
2318
23197.1.4. The WebSocket Connection is Closed
2320
2321 When the underlying TCP connection is closed, it is said that _The
2322 WebSocket Connection is Closed_ and that the WebSocket connection is
2323 in the CLOSED state. If the TCP connection was closed after the
2324 WebSocket closing handshake was completed, the WebSocket connection
2325 is said to have been closed _cleanly_.
2326
2327 If the WebSocket connection could not be established, it is also said
2328 that _The WebSocket Connection is Closed_, but not _cleanly_.
2329
23307.1.5. The WebSocket Connection Close Code
2331
2332 As defined in Sections 5.5.1 and 7.4, a Close control frame may
2333 contain a status code indicating a reason for closure. A closing of
2334 the WebSocket connection may be initiated by either endpoint,
2335 potentially simultaneously. _The WebSocket Connection Close Code_ is
2336 defined as the status code (Section 7.4) contained in the first Close
2337 control frame received by the application implementing this protocol.
2338 If this Close control frame contains no status code, _The WebSocket
2339 Connection Close Code_ is considered to be 1005. If _The WebSocket
2340 Connection is Closed_ and no Close control frame was received by the
2341 endpoint (such as could occur if the underlying transport connection
2342 is lost), _The WebSocket Connection Close Code_ is considered to be
2343 1006.
2344
2345 NOTE: Two endpoints may not agree on the value of _The WebSocket
2346 Connection Close Code_. As an example, if the remote endpoint sent a
2347 Close frame but the local application has not yet read the data
2348 containing the Close frame from its socket's receive buffer, and the
2349 local application independently decided to close the connection and
2350 send a Close frame, both endpoints will have sent and received a
2351
2352
2353
2354Fette & Melnikov Standards Track [Page 42]
2355
2356RFC 6455 The WebSocket Protocol December 2011
2357
2358
2359 Close frame and will not send further Close frames. Each endpoint
2360 will see the status code sent by the other end as _The WebSocket
2361 Connection Close Code_. As such, it is possible that the two
2362 endpoints may not agree on the value of _The WebSocket Connection
2363 Close Code_ in the case that both endpoints _Start the WebSocket
2364 Closing Handshake_ independently and at roughly the same time.
2365
23667.1.6. The WebSocket Connection Close Reason
2367
2368 As defined in Sections 5.5.1 and 7.4, a Close control frame may
2369 contain a status code indicating a reason for closure, followed by
2370 UTF-8-encoded data, the interpretation of said data being left to the
2371 endpoints and not defined by this protocol. A closing of the
2372 WebSocket connection may be initiated by either endpoint, potentially
2373 simultaneously. _The WebSocket Connection Close Reason_ is defined as
2374 the UTF-8-encoded data following the status code (Section 7.4)
2375 contained in the first Close control frame received by the
2376 application implementing this protocol. If there is no such data in
2377 the Close control frame, _The WebSocket Connection Close Reason_ is
2378 the empty string.
2379
2380 NOTE: Following the same logic as noted in Section 7.1.5, two
2381 endpoints may not agree on _The WebSocket Connection Close Reason_.
2382
23837.1.7. Fail the WebSocket Connection
2384
2385 Certain algorithms and specifications require an endpoint to _Fail
2386 the WebSocket Connection_. To do so, the client MUST _Close the
2387 WebSocket Connection_, and MAY report the problem to the user (which
2388 would be especially useful for developers) in an appropriate manner.
2389 Similarly, to do so, the server MUST _Close the WebSocket
2390 Connection_, and SHOULD log the problem.
2391
2392 If _The WebSocket Connection is Established_ prior to the point where
2393 the endpoint is required to _Fail the WebSocket Connection_, the
2394 endpoint SHOULD send a Close frame with an appropriate status code
2395 (Section 7.4) before proceeding to _Close the WebSocket Connection_.
2396 An endpoint MAY omit sending a Close frame if it believes the other
2397 side is unlikely to be able to receive and process the Close frame,
2398 due to the nature of the error that led the WebSocket connection to
2399 fail in the first place. An endpoint MUST NOT continue to attempt to
2400 process data (including a responding Close frame) from the remote
2401 endpoint after being instructed to _Fail the WebSocket Connection_.
2402
2403 Except as indicated above or as specified by the application layer
2404 (e.g., a script using the WebSocket API), clients SHOULD NOT close
2405 the connection.
2406
2407
2408
2409
2410Fette & Melnikov Standards Track [Page 43]
2411
2412RFC 6455 The WebSocket Protocol December 2011
2413
2414
24157.2. Abnormal Closures
2416
24177.2.1. Client-Initiated Closure
2418
2419 Certain algorithms, in particular during the opening handshake,
2420 require the client to _Fail the WebSocket Connection_. To do so, the
2421 client MUST _Fail the WebSocket Connection_ as defined in
2422 Section 7.1.7.
2423
2424 If at any point the underlying transport layer connection is
2425 unexpectedly lost, the client MUST _Fail the WebSocket Connection_.
2426
2427 Except as indicated above or as specified by the application layer
2428 (e.g., a script using the WebSocket API), clients SHOULD NOT close
2429 the connection.
2430
24317.2.2. Server-Initiated Closure
2432
2433 Certain algorithms require or recommend that the server _Abort the
2434 WebSocket Connection_ during the opening handshake. To do so, the
2435 server MUST simply _Close the WebSocket Connection_ (Section 7.1.1).
2436
24377.2.3. Recovering from Abnormal Closure
2438
2439 Abnormal closures may be caused by any number of reasons. Such
2440 closures could be the result of a transient error, in which case
2441 reconnecting may lead to a good connection and a resumption of normal
2442 operations. Such closures may also be the result of a nontransient
2443 problem, in which case if each deployed client experiences an
2444 abnormal closure and immediately and persistently tries to reconnect,
2445 the server may experience what amounts to a denial-of-service attack
2446 by a large number of clients trying to reconnect. The end result of
2447 such a scenario could be that the service is unable to recover in a
2448 timely manner or recovery is made much more difficult.
2449
2450 To prevent this, clients SHOULD use some form of backoff when trying
2451 to reconnect after abnormal closures as described in this section.
2452
2453 The first reconnect attempt SHOULD be delayed by a random amount of
2454 time. The parameters by which this random delay is chosen are left
2455 to the client to decide; a value chosen randomly between 0 and 5
2456 seconds is a reasonable initial delay though clients MAY choose a
2457 different interval from which to select a delay length based on
2458 implementation experience and particular application.
2459
2460 Should the first reconnect attempt fail, subsequent reconnect
2461 attempts SHOULD be delayed by increasingly longer amounts of time,
2462 using a method such as truncated binary exponential backoff.
2463
2464
2465
2466Fette & Melnikov Standards Track [Page 44]
2467
2468RFC 6455 The WebSocket Protocol December 2011
2469
2470
24717.3. Normal Closure of Connections
2472
2473 Servers MAY close the WebSocket connection whenever desired. Clients
2474 SHOULD NOT close the WebSocket connection arbitrarily. In either
2475 case, an endpoint initiates a closure by following the procedures to
2476 _Start the WebSocket Closing Handshake_ (Section 7.1.2).
2477
24787.4. Status Codes
2479
2480 When closing an established connection (e.g., when sending a Close
2481 frame, after the opening handshake has completed), an endpoint MAY
2482 indicate a reason for closure. The interpretation of this reason by
2483 an endpoint, and the action an endpoint should take given this
2484 reason, are left undefined by this specification. This specification
2485 defines a set of pre-defined status codes and specifies which ranges
2486 may be used by extensions, frameworks, and end applications. The
2487 status code and any associated textual message are optional
2488 components of a Close frame.
2489
24907.4.1. Defined Status Codes
2491
2492 Endpoints MAY use the following pre-defined status codes when sending
2493 a Close frame.
2494
2495 1000
2496
2497 1000 indicates a normal closure, meaning that the purpose for
2498 which the connection was established has been fulfilled.
2499
2500 1001
2501
2502 1001 indicates that an endpoint is "going away", such as a server
2503 going down or a browser having navigated away from a page.
2504
2505 1002
2506
2507 1002 indicates that an endpoint is terminating the connection due
2508 to a protocol error.
2509
2510 1003
2511
2512 1003 indicates that an endpoint is terminating the connection
2513 because it has received a type of data it cannot accept (e.g., an
2514 endpoint that understands only text data MAY send this if it
2515 receives a binary message).
2516
2517
2518
2519
2520
2521
2522Fette & Melnikov Standards Track [Page 45]
2523
2524RFC 6455 The WebSocket Protocol December 2011
2525
2526
2527 1004
2528
2529 Reserved. The specific meaning might be defined in the future.
2530
2531 1005
2532
2533 1005 is a reserved value and MUST NOT be set as a status code in a
2534 Close control frame by an endpoint. It is designated for use in
2535 applications expecting a status code to indicate that no status
2536 code was actually present.
2537
2538 1006
2539
2540 1006 is a reserved value and MUST NOT be set as a status code in a
2541 Close control frame by an endpoint. It is designated for use in
2542 applications expecting a status code to indicate that the
2543 connection was closed abnormally, e.g., without sending or
2544 receiving a Close control frame.
2545
2546 1007
2547
2548 1007 indicates that an endpoint is terminating the connection
2549 because it has received data within a message that was not
2550 consistent with the type of the message (e.g., non-UTF-8 [RFC3629]
2551 data within a text message).
2552
2553 1008
2554
2555 1008 indicates that an endpoint is terminating the connection
2556 because it has received a message that violates its policy. This
2557 is a generic status code that can be returned when there is no
2558 other more suitable status code (e.g., 1003 or 1009) or if there
2559 is a need to hide specific details about the policy.
2560
2561 1009
2562
2563 1009 indicates that an endpoint is terminating the connection
2564 because it has received a message that is too big for it to
2565 process.
2566
2567 1010
2568
2569 1010 indicates that an endpoint (client) is terminating the
2570 connection because it has expected the server to negotiate one or
2571 more extension, but the server didn't return them in the response
2572 message of the WebSocket handshake. The list of extensions that
2573
2574
2575
2576
2577
2578Fette & Melnikov Standards Track [Page 46]
2579
2580RFC 6455 The WebSocket Protocol December 2011
2581
2582
2583 are needed SHOULD appear in the /reason/ part of the Close frame.
2584 Note that this status code is not used by the server, because it
2585 can fail the WebSocket handshake instead.
2586
2587 1011
2588
2589 1011 indicates that a server is terminating the connection because
2590 it encountered an unexpected condition that prevented it from
2591 fulfilling the request.
2592
2593 1015
2594
2595 1015 is a reserved value and MUST NOT be set as a status code in a
2596 Close control frame by an endpoint. It is designated for use in
2597 applications expecting a status code to indicate that the
2598 connection was closed due to a failure to perform a TLS handshake
2599 (e.g., the server certificate can't be verified).
2600
26017.4.2. Reserved Status Code Ranges
2602
2603 0-999
2604
2605 Status codes in the range 0-999 are not used.
2606
2607 1000-2999
2608
2609 Status codes in the range 1000-2999 are reserved for definition by
2610 this protocol, its future revisions, and extensions specified in a
2611 permanent and readily available public specification.
2612
2613 3000-3999
2614
2615 Status codes in the range 3000-3999 are reserved for use by
2616 libraries, frameworks, and applications. These status codes are
2617 registered directly with IANA. The interpretation of these codes
2618 is undefined by this protocol.
2619
2620 4000-4999
2621
2622 Status codes in the range 4000-4999 are reserved for private use
2623 and thus can't be registered. Such codes can be used by prior
2624 agreements between WebSocket applications. The interpretation of
2625 these codes is undefined by this protocol.
2626
2627
2628
2629
2630
2631
2632
2633
2634Fette & Melnikov Standards Track [Page 47]
2635
2636RFC 6455 The WebSocket Protocol December 2011
2637
2638
26398. Error Handling
2640
26418.1. Handling Errors in UTF-8-Encoded Data
2642
2643 When an endpoint is to interpret a byte stream as UTF-8 but finds
2644 that the byte stream is not, in fact, a valid UTF-8 stream, that
2645 endpoint MUST _Fail the WebSocket Connection_. This rule applies
2646 both during the opening handshake and during subsequent data
2647 exchange.
2648
26499. Extensions
2650
2651 WebSocket clients MAY request extensions to this specification, and
2652 WebSocket servers MAY accept some or all extensions requested by the
2653 client. A server MUST NOT respond with any extension not requested
2654 by the client. If extension parameters are included in negotiations
2655 between the client and the server, those parameters MUST be chosen in
2656 accordance with the specification of the extension to which the
2657 parameters apply.
2658
26599.1. Negotiating Extensions
2660
2661 A client requests extensions by including a |Sec-WebSocket-
2662 Extensions| header field, which follows the normal rules for HTTP
2663 header fields (see [RFC2616], Section 4.2) and the value of the
2664 header field is defined by the following ABNF [RFC2616]. Note that
2665 this section is using ABNF syntax/rules from [RFC2616], including the
2666 "implied *LWS rule". If a value is received by either the client or
2667 the server during negotiation that does not conform to the ABNF
2668 below, the recipient of such malformed data MUST immediately _Fail
2669 the WebSocket Connection_.
2670
2671 Sec-WebSocket-Extensions = extension-list
2672 extension-list = 1#extension
2673 extension = extension-token *( ";" extension-param )
2674 extension-token = registered-token
2675 registered-token = token
2676 extension-param = token [ "=" (token | quoted-string) ]
2677 ;When using the quoted-string syntax variant, the value
2678 ;after quoted-string unescaping MUST conform to the
2679 ;'token' ABNF.
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690Fette & Melnikov Standards Track [Page 48]
2691
2692RFC 6455 The WebSocket Protocol December 2011
2693
2694
2695 Note that like other HTTP header fields, this header field MAY be
2696 split or combined across multiple lines. Ergo, the following are
2697 equivalent:
2698
2699 Sec-WebSocket-Extensions: foo
2700 Sec-WebSocket-Extensions: bar; baz=2
2701
2702 is exactly equivalent to
2703
2704 Sec-WebSocket-Extensions: foo, bar; baz=2
2705
2706 Any extension-token used MUST be a registered token (see
2707 Section 11.4). The parameters supplied with any given extension MUST
2708 be defined for that extension. Note that the client is only offering
2709 to use any advertised extensions and MUST NOT use them unless the
2710 server indicates that it wishes to use the extension.
2711
2712 Note that the order of extensions is significant. Any interactions
2713 between multiple extensions MAY be defined in the documents defining
2714 the extensions. In the absence of such definitions, the
2715 interpretation is that the header fields listed by the client in its
2716 request represent a preference of the header fields it wishes to use,
2717 with the first options listed being most preferable. The extensions
2718 listed by the server in response represent the extensions actually in
2719 use for the connection. Should the extensions modify the data and/or
2720 framing, the order of operations on the data should be assumed to be
2721 the same as the order in which the extensions are listed in the
2722 server's response in the opening handshake.
2723
2724 For example, if there are two extensions "foo" and "bar" and if the
2725 header field |Sec-WebSocket-Extensions| sent by the server has the
2726 value "foo, bar", then operations on the data will be made as
2727 bar(foo(data)), be those changes to the data itself (such as
2728 compression) or changes to the framing that may "stack".
2729
2730 Non-normative examples of acceptable extension header fields (note
2731 that long lines are folded for readability):
2732
2733 Sec-WebSocket-Extensions: deflate-stream
2734 Sec-WebSocket-Extensions: mux; max-channels=4; flow-control,
2735 deflate-stream
2736 Sec-WebSocket-Extensions: private-extension
2737
2738 A server accepts one or more extensions by including a
2739 |Sec-WebSocket-Extensions| header field containing one or more
2740 extensions that were requested by the client. The interpretation of
2741
2742
2743
2744
2745
2746Fette & Melnikov Standards Track [Page 49]
2747
2748RFC 6455 The WebSocket Protocol December 2011
2749
2750
2751 any extension parameters, and what constitutes a valid response by a
2752 server to a requested set of parameters by a client, will be defined
2753 by each such extension.
2754
27559.2. Known Extensions
2756
2757 Extensions provide a mechanism for implementations to opt-in to
2758 additional protocol features. This document doesn't define any
2759 extension, but implementations MAY use extensions defined separately.
2760
276110. Security Considerations
2762
2763 This section describes some security considerations applicable to the
2764 WebSocket Protocol. Specific security considerations are described
2765 in subsections of this section.
2766
276710.1. Non-Browser Clients
2768
2769 The WebSocket Protocol protects against malicious JavaScript running
2770 inside a trusted application such as a web browser, for example, by
2771 checking of the |Origin| header field (see below). See Section 1.6
2772 for additional details. Such assumptions don't hold true in the case
2773 of a more-capable client.
2774
2775 While this protocol is intended to be used by scripts in web pages,
2776 it can also be used directly by hosts. Such hosts are acting on
2777 their own behalf and can therefore send fake |Origin| header fields,
2778 misleading the server. Servers should therefore be careful about
2779 assuming that they are talking directly to scripts from known origins
2780 and must consider that they might be accessed in unexpected ways. In
2781 particular, a server should not trust that any input is valid.
2782
2783 EXAMPLE: If the server uses input as part of SQL queries, all input
2784 text should be escaped before being passed to the SQL server, lest
2785 the server be susceptible to SQL injection.
2786
278710.2. Origin Considerations
2788
2789 Servers that are not intended to process input from any web page but
2790 only for certain sites SHOULD verify the |Origin| field is an origin
2791 they expect. If the origin indicated is unacceptable to the server,
2792 then it SHOULD respond to the WebSocket handshake with a reply
2793 containing HTTP 403 Forbidden status code.
2794
2795 The |Origin| header field protects from the attack cases when the
2796 untrusted party is typically the author of a JavaScript application
2797 that is executing in the context of the trusted client. The client
2798 itself can contact the server and, via the mechanism of the |Origin|
2799
2800
2801
2802Fette & Melnikov Standards Track [Page 50]
2803
2804RFC 6455 The WebSocket Protocol December 2011
2805
2806
2807 header field, determine whether to extend those communication
2808 privileges to the JavaScript application. The intent is not to
2809 prevent non-browsers from establishing connections but rather to
2810 ensure that trusted browsers under the control of potentially
2811 malicious JavaScript cannot fake a WebSocket handshake.
2812
281310.3. Attacks On Infrastructure (Masking)
2814
2815 In addition to endpoints being the target of attacks via WebSockets,
2816 other parts of web infrastructure, such as proxies, may be the
2817 subject of an attack.
2818
2819 As this protocol was being developed, an experiment was conducted to
2820 demonstrate a class of attacks on proxies that led to the poisoning
2821 of caching proxies deployed in the wild [TALKING]. The general form
2822 of the attack was to establish a connection to a server under the
2823 "attacker's" control, perform an UPGRADE on the HTTP connection
2824 similar to what the WebSocket Protocol does to establish a
2825 connection, and subsequently send data over that UPGRADEd connection
2826 that looked like a GET request for a specific known resource (which
2827 in an attack would likely be something like a widely deployed script
2828 for tracking hits or a resource on an ad-serving network). The
2829 remote server would respond with something that looked like a
2830 response to the fake GET request, and this response would be cached
2831 by a nonzero percentage of deployed intermediaries, thus poisoning
2832 the cache. The net effect of this attack would be that if a user
2833 could be convinced to visit a website the attacker controlled, the
2834 attacker could potentially poison the cache for that user and other
2835 users behind the same cache and run malicious script on other
2836 origins, compromising the web security model.
2837
2838 To avoid such attacks on deployed intermediaries, it is not
2839 sufficient to prefix application-supplied data with framing that is
2840 not compliant with HTTP, as it is not possible to exhaustively
2841 discover and test that each nonconformant intermediary does not skip
2842 such non-HTTP framing and act incorrectly on the frame payload.
2843 Thus, the defense adopted is to mask all data from the client to the
2844 server, so that the remote script (attacker) does not have control
2845 over how the data being sent appears on the wire and thus cannot
2846 construct a message that could be misinterpreted by an intermediary
2847 as an HTTP request.
2848
2849 Clients MUST choose a new masking key for each frame, using an
2850 algorithm that cannot be predicted by end applications that provide
2851 data. For example, each masking could be drawn from a
2852 cryptographically strong random number generator. If the same key is
2853 used or a decipherable pattern exists for how the next key is chosen,
2854 the attacker can send a message that, when masked, could appear to be
2855
2856
2857
2858Fette & Melnikov Standards Track [Page 51]
2859
2860RFC 6455 The WebSocket Protocol December 2011
2861
2862
2863 an HTTP request (by taking the message the attacker wishes to see on
2864 the wire and masking it with the next masking key to be used, the
2865 masking key will effectively unmask the data when the client applies
2866 it).
2867
2868 It is also necessary that once the transmission of a frame from a
2869 client has begun, the payload (application-supplied data) of that
2870 frame must not be capable of being modified by the application.
2871 Otherwise, an attacker could send a long frame where the initial data
2872 was a known value (such as all zeros), compute the masking key being
2873 used upon receipt of the first part of the data, and then modify the
2874 data that is yet to be sent in the frame to appear as an HTTP request
2875 when masked. (This is essentially the same problem described in the
2876 previous paragraph with using a known or predictable masking key.)
2877 If additional data is to be sent or data to be sent is somehow
2878 changed, that new or changed data must be sent in a new frame and
2879 thus with a new masking key. In short, once transmission of a frame
2880 begins, the contents must not be modifiable by the remote script
2881 (application).
2882
2883 The threat model being protected against is one in which the client
2884 sends data that appears to be an HTTP request. As such, the channel
2885 that needs to be masked is the data from the client to the server.
2886 The data from the server to the client can be made to look like a
2887 response, but to accomplish this request, the client must also be
2888 able to forge a request. As such, it was not deemed necessary to
2889 mask data in both directions (the data from the server to the client
2890 is not masked).
2891
2892 Despite the protection provided by masking, non-compliant HTTP
2893 proxies will still be vulnerable to poisoning attacks of this type by
2894 clients and servers that do not apply masking.
2895
289610.4. Implementation-Specific Limits
2897
2898 Implementations that have implementation- and/or platform-specific
2899 limitations regarding the frame size or total message size after
2900 reassembly from multiple frames MUST protect themselves against
2901 exceeding those limits. (For example, a malicious endpoint can try
2902 to exhaust its peer's memory or mount a denial-of-service attack by
2903 sending either a single big frame (e.g., of size 2**60) or by sending
2904 a long stream of small frames that are a part of a fragmented
2905 message.) Such an implementation SHOULD impose a limit on frame
2906 sizes and the total message size after reassembly from multiple
2907 frames.
2908
2909
2910
2911
2912
2913
2914Fette & Melnikov Standards Track [Page 52]
2915
2916RFC 6455 The WebSocket Protocol December 2011
2917
2918
291910.5. WebSocket Client Authentication
2920
2921 This protocol doesn't prescribe any particular way that servers can
2922 authenticate clients during the WebSocket handshake. The WebSocket
2923 server can use any client authentication mechanism available to a
2924 generic HTTP server, such as cookies, HTTP authentication, or TLS
2925 authentication.
2926
292710.6. Connection Confidentiality and Integrity
2928
2929 Connection confidentiality and integrity is provided by running the
2930 WebSocket Protocol over TLS (wss URIs). WebSocket implementations
2931 MUST support TLS and SHOULD employ it when communicating with their
2932 peers.
2933
2934 For connections using TLS, the amount of benefit provided by TLS
2935 depends greatly on the strength of the algorithms negotiated during
2936 the TLS handshake. For example, some TLS cipher mechanisms don't
2937 provide connection confidentiality. To achieve reasonable levels of
2938 protection, clients should use only Strong TLS algorithms. "Web
2939 Security Context: User Interface Guidelines"
2940 [W3C.REC-wsc-ui-20100812] discusses what constitutes Strong TLS
2941 algorithms. [RFC5246] provides additional guidance in Appendix A.5
2942 and Appendix D.3.
2943
294410.7. Handling of Invalid Data
2945
2946 Incoming data MUST always be validated by both clients and servers.
2947 If, at any time, an endpoint is faced with data that it does not
2948 understand or that violates some criteria by which the endpoint
2949 determines safety of input, or when the endpoint sees an opening
2950 handshake that does not correspond to the values it is expecting
2951 (e.g., incorrect path or origin in the client request), the endpoint
2952 MAY drop the TCP connection. If the invalid data was received after
2953 a successful WebSocket handshake, the endpoint SHOULD send a Close
2954 frame with an appropriate status code (Section 7.4) before proceeding
2955 to _Close the WebSocket Connection_. Use of a Close frame with an
2956 appropriate status code can help in diagnosing the problem. If the
2957 invalid data is sent during the WebSocket handshake, the server
2958 SHOULD return an appropriate HTTP [RFC2616] status code.
2959
2960 A common class of security problems arises when sending text data
2961 using the wrong encoding. This protocol specifies that messages with
2962 a Text data type (as opposed to Binary or other types) contain UTF-8-
2963 encoded data. Although the length is still indicated and
2964 applications implementing this protocol should use the length to
2965 determine where the frame actually ends, sending data in an improper
2966
2967
2968
2969
2970Fette & Melnikov Standards Track [Page 53]
2971
2972RFC 6455 The WebSocket Protocol December 2011
2973
2974
2975 encoding may still break assumptions that applications built on top
2976 of this protocol may make, leading to anything from misinterpretation
2977 of data to loss of data or potential security bugs.
2978
297910.8. Use of SHA-1 by the WebSocket Handshake
2980
2981 The WebSocket handshake described in this document doesn't depend on
2982 any security properties of SHA-1, such as collision resistance or
2983 resistance to the second pre-image attack (as described in
2984 [RFC4270]).
2985
298611. IANA Considerations
2987
298811.1. Registration of New URI Schemes
2989
299011.1.1. Registration of "ws" Scheme
2991
2992 A |ws| URI identifies a WebSocket server and resource name.
2993
2994 URI scheme name
2995 ws
2996
2997 Status
2998 Permanent
2999
3000 URI scheme syntax
3001 Using the ABNF [RFC5234] syntax and ABNF terminals from the URI
3002 specification [RFC3986]:
3003
3004 "ws:" "//" authority path-abempty [ "?" query ]
3005
3006 The <path-abempty> and <query> [RFC3986] components form the resource
3007 name sent to the server to identify the kind of service desired.
3008 Other components have the meanings described in [RFC3986].
3009
3010 URI scheme semantics
3011 The only operation for this scheme is to open a connection using
3012 the WebSocket Protocol.
3013
3014 Encoding considerations
3015 Characters in the host component that are excluded by the syntax
3016 defined above MUST be converted from Unicode to ASCII as specified
3017 in [RFC3987] or its replacement. For the purposes of scheme-based
3018 normalization, Internationalized Domain Name (IDN) forms of the
3019 host component and their conversions to punycode are considered
3020 equivalent (see Section 5.3.3 of [RFC3987]).
3021
3022
3023
3024
3025
3026Fette & Melnikov Standards Track [Page 54]
3027
3028RFC 6455 The WebSocket Protocol December 2011
3029
3030
3031 Characters in other components that are excluded by the syntax
3032 defined above MUST be converted from Unicode to ASCII by first
3033 encoding the characters as UTF-8 and then replacing the
3034 corresponding bytes using their percent-encoded form as defined in
3035 the URI [RFC3986] and Internationalized Resource Identifier (IRI)
3036 [RFC3987] specifications.
3037
3038 Applications/protocols that use this URI scheme name
3039 WebSocket Protocol
3040
3041 Interoperability considerations
3042 Use of WebSocket requires use of HTTP version 1.1 or higher.
3043
3044 Security considerations
3045 See "Security Considerations" section.
3046
3047 Contact
3048 HYBI WG <hybi@ietf.org>
3049
3050 Author/Change controller
3051 IETF <iesg@ietf.org>
3052
3053 References
3054 RFC 6455
3055
305611.1.2. Registration of "wss" Scheme
3057
3058 A |wss| URI identifies a WebSocket server and resource name and
3059 indicates that traffic over that connection is to be protected via
3060 TLS (including standard benefits of TLS such as data confidentiality
3061 and integrity and endpoint authentication).
3062
3063 URI scheme name
3064 wss
3065
3066 Status
3067 Permanent
3068
3069 URI scheme syntax
3070 Using the ABNF [RFC5234] syntax and ABNF terminals from the URI
3071 specification [RFC3986]:
3072
3073 "wss:" "//" authority path-abempty [ "?" query ]
3074
3075 The <path-abempty> and <query> components form the resource name sent
3076 to the server to identify the kind of service desired. Other
3077 components have the meanings described in [RFC3986].
3078
3079
3080
3081
3082Fette & Melnikov Standards Track [Page 55]
3083
3084RFC 6455 The WebSocket Protocol December 2011
3085
3086
3087 URI scheme semantics
3088 The only operation for this scheme is to open a connection using
3089 the WebSocket Protocol, encrypted using TLS.
3090
3091 Encoding considerations
3092 Characters in the host component that are excluded by the syntax
3093 defined above MUST be converted from Unicode to ASCII as specified
3094 in [RFC3987] or its replacement. For the purposes of scheme-based
3095 normalization IDN forms of the host component and their
3096 conversions to punycode are considered equivalent (see Section
3097 5.3.3 of [RFC3987]).
3098
3099 Characters in other components that are excluded by the syntax
3100 defined above MUST be converted from Unicode to ASCII by first
3101 encoding the characters as UTF-8 and then replacing the
3102 corresponding bytes using their percent-encoded form as defined in
3103 the URI [RFC3986] and IRI [RFC3987] specifications.
3104
3105 Applications/protocols that use this URI scheme name
3106 WebSocket Protocol over TLS
3107
3108 Interoperability considerations
3109 Use of WebSocket requires use of HTTP version 1.1 or higher.
3110
3111 Security considerations
3112 See "Security Considerations" section.
3113
3114 Contact
3115 HYBI WG <hybi@ietf.org>
3116
3117 Author/Change controller
3118 IETF <iesg@ietf.org>
3119
3120 References
3121 RFC 6455
3122
312311.2. Registration of the "WebSocket" HTTP Upgrade Keyword
3124
3125 This section defines a keyword registered in the HTTP Upgrade Tokens
3126 Registry as per RFC 2817 [RFC2817].
3127
3128 Name of token
3129 WebSocket
3130
3131 Author/Change controller
3132 IETF <iesg@ietf.org>
3133
3134
3135
3136
3137
3138Fette & Melnikov Standards Track [Page 56]
3139
3140RFC 6455 The WebSocket Protocol December 2011
3141
3142
3143 Contact
3144 HYBI <hybi@ietf.org>
3145
3146 References
3147 RFC 6455
3148
314911.3. Registration of New HTTP Header Fields
3150
315111.3.1. Sec-WebSocket-Key
3152
3153 This section describes a header field registered in the Permanent
3154 Message Header Field Names registry [RFC3864].
3155
3156 Header field name
3157 Sec-WebSocket-Key
3158
3159 Applicable protocol
3160 http
3161
3162 Status
3163 standard
3164
3165 Author/Change controller
3166 IETF
3167
3168 Specification document(s)
3169 RFC 6455
3170
3171 Related information
3172 This header field is only used for WebSocket opening handshake.
3173
3174 The |Sec-WebSocket-Key| header field is used in the WebSocket opening
3175 handshake. It is sent from the client to the server to provide part
3176 of the information used by the server to prove that it received a
3177 valid WebSocket opening handshake. This helps ensure that the server
3178 does not accept connections from non-WebSocket clients (e.g., HTTP
3179 clients) that are being abused to send data to unsuspecting WebSocket
3180 servers.
3181
3182 The |Sec-WebSocket-Key| header field MUST NOT appear more than once
3183 in an HTTP request.
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194Fette & Melnikov Standards Track [Page 57]
3195
3196RFC 6455 The WebSocket Protocol December 2011
3197
3198
319911.3.2. Sec-WebSocket-Extensions
3200
3201 This section describes a header field for registration in the
3202 Permanent Message Header Field Names registry [RFC3864].
3203
3204 Header field name
3205 Sec-WebSocket-Extensions
3206
3207 Applicable protocol
3208 http
3209
3210 Status
3211 standard
3212
3213 Author/Change controller
3214 IETF
3215
3216 Specification document(s)
3217 RFC 6455
3218
3219 Related information
3220 This header field is only used for WebSocket opening handshake.
3221
3222 The |Sec-WebSocket-Extensions| header field is used in the WebSocket
3223 opening handshake. It is initially sent from the client to the
3224 server, and then subsequently sent from the server to the client, to
3225 agree on a set of protocol-level extensions to use for the duration
3226 of the connection.
3227
3228 The |Sec-WebSocket-Extensions| header field MAY appear multiple times
3229 in an HTTP request (which is logically the same as a single
3230 |Sec-WebSocket-Extensions| header field that contains all values.
3231 However, the |Sec-WebSocket-Extensions| header field MUST NOT appear
3232 more than once in an HTTP response.
3233
323411.3.3. Sec-WebSocket-Accept
3235
3236 This section describes a header field registered in the Permanent
3237 Message Header Field Names registry [RFC3864].
3238
3239 Header field name
3240 Sec-WebSocket-Accept
3241
3242 Applicable protocol
3243 http
3244
3245 Status
3246 standard
3247
3248
3249
3250Fette & Melnikov Standards Track [Page 58]
3251
3252RFC 6455 The WebSocket Protocol December 2011
3253
3254
3255 Author/Change controller
3256 IETF
3257
3258 Specification document(s)
3259 RFC 6455
3260
3261 Related information
3262 This header field is only used for the WebSocket opening
3263 handshake.
3264
3265 The |Sec-WebSocket-Accept| header field is used in the WebSocket
3266 opening handshake. It is sent from the server to the client to
3267 confirm that the server is willing to initiate the WebSocket
3268 connection.
3269
3270 The |Sec-WebSocket-Accept| header MUST NOT appear more than once in
3271 an HTTP response.
3272
327311.3.4. Sec-WebSocket-Protocol
3274
3275 This section describes a header field registered in the Permanent
3276 Message Header Field Names registry [RFC3864].
3277
3278 Header field name
3279 Sec-WebSocket-Protocol
3280
3281 Applicable protocol
3282 http
3283
3284 Status
3285 standard
3286
3287 Author/Change controller
3288 IETF
3289
3290 Specification document(s)
3291 RFC 6455
3292
3293 Related information
3294 This header field is only used for the WebSocket opening
3295 handshake.
3296
3297 The |Sec-WebSocket-Protocol| header field is used in the WebSocket
3298 opening handshake. It is sent from the client to the server and back
3299 from the server to the client to confirm the subprotocol of the
3300 connection. This enables scripts to both select a subprotocol and be
3301 sure that the server agreed to serve that subprotocol.
3302
3303
3304
3305
3306Fette & Melnikov Standards Track [Page 59]
3307
3308RFC 6455 The WebSocket Protocol December 2011
3309
3310
3311 The |Sec-WebSocket-Protocol| header field MAY appear multiple times
3312 in an HTTP request (which is logically the same as a single
3313 |Sec-WebSocket-Protocol| header field that contains all values).
3314 However, the |Sec-WebSocket-Protocol| header field MUST NOT appear
3315 more than once in an HTTP response.
3316
331711.3.5. Sec-WebSocket-Version
3318
3319 This section describes a header field registered in the Permanent
3320 Message Header Field Names registry [RFC3864].
3321
3322 Header field name
3323 Sec-WebSocket-Version
3324
3325 Applicable protocol
3326 http
3327
3328 Status
3329 standard
3330
3331 Author/Change controller
3332 IETF
3333
3334 Specification document(s)
3335 RFC 6455
3336
3337 Related information
3338 This header field is only used for the WebSocket opening
3339 handshake.
3340
3341 The |Sec-WebSocket-Version| header field is used in the WebSocket
3342 opening handshake. It is sent from the client to the server to
3343 indicate the protocol version of the connection. This enables
3344 servers to correctly interpret the opening handshake and subsequent
3345 data being sent from the data, and close the connection if the server
3346 cannot interpret that data in a safe manner. The |Sec-WebSocket-
3347 Version| header field is also sent from the server to the client on
3348 WebSocket handshake error, when the version received from the client
3349 does not match a version understood by the server. In such a case,
3350 the header field includes the protocol version(s) supported by the
3351 server.
3352
3353 Note that there is no expectation that higher version numbers are
3354 necessarily backward compatible with lower version numbers.
3355
3356
3357
3358
3359
3360
3361
3362Fette & Melnikov Standards Track [Page 60]
3363
3364RFC 6455 The WebSocket Protocol December 2011
3365
3366
3367 The |Sec-WebSocket-Version| header field MAY appear multiple times in
3368 an HTTP response (which is logically the same as a single
3369 |Sec-WebSocket-Version| header field that contains all values).
3370 However, the |Sec-WebSocket-Version| header field MUST NOT appear
3371 more than once in an HTTP request.
3372
337311.4. WebSocket Extension Name Registry
3374
3375 This specification creates a new IANA registry for WebSocket
3376 Extension names to be used with the WebSocket Protocol in accordance
3377 with the principles set out in RFC 5226 [RFC5226].
3378
3379 As part of this registry, IANA maintains the following information:
3380
3381 Extension Identifier
3382 The identifier of the extension, as will be used in the
3383 |Sec-WebSocket-Extensions| header field registered in
3384 Section 11.3.2 of this specification. The value must conform to
3385 the requirements for an extension-token as defined in Section 9.1
3386 of this specification.
3387
3388 Extension Common Name
3389 The name of the extension, as the extension is generally referred
3390 to.
3391
3392 Extension Definition
3393 A reference to the document in which the extension being used with
3394 the WebSocket Protocol is defined.
3395
3396 Known Incompatible Extensions
3397 A list of extension identifiers with which this extension is known
3398 to be incompatible.
3399
3400 WebSocket Extension names are to be subject to the "First Come First
3401 Served" IANA registration policy [RFC5226].
3402
3403 There are no initial values in this registry.
3404
340511.5. WebSocket Subprotocol Name Registry
3406
3407 This specification creates a new IANA registry for WebSocket
3408 Subprotocol names to be used with the WebSocket Protocol in
3409 accordance with the principles set out in RFC 5226 [RFC5226].
3410
3411
3412
3413
3414
3415
3416
3417
3418Fette & Melnikov Standards Track [Page 61]
3419
3420RFC 6455 The WebSocket Protocol December 2011
3421
3422
3423 As part of this registry, IANA maintains the following information:
3424
3425 Subprotocol Identifier
3426 The identifier of the subprotocol, as will be used in the
3427 |Sec-WebSocket-Protocol| header field registered in Section 11.3.4
3428 of this specification. The value must conform to the requirements
3429 given in item 10 of Section 4.1 of this specification -- namely,
3430 the value must be a token as defined by RFC 2616 [RFC2616].
3431
3432 Subprotocol Common Name
3433 The name of the subprotocol, as the subprotocol is generally
3434 referred to.
3435
3436 Subprotocol Definition
3437 A reference to the document in which the subprotocol being used
3438 with the WebSocket Protocol is defined.
3439
3440 WebSocket Subprotocol names are to be subject to the "First Come
3441 First Served" IANA registration policy [RFC5226].
3442
344311.6. WebSocket Version Number Registry
3444
3445 This specification creates a new IANA registry for WebSocket Version
3446 Numbers to be used with the WebSocket Protocol in accordance with the
3447 principles set out in RFC 5226 [RFC5226].
3448
3449 As part of this registry, IANA maintains the following information:
3450
3451 Version Number
3452 The version number to be used in the |Sec-WebSocket-Version| is
3453 specified in Section 4.1 of this specification. The value must be
3454 a non-negative integer in the range between 0 and 255 (inclusive).
3455
3456 Reference
3457 The RFC requesting a new version number or a draft name with
3458 version number (see below).
3459
3460 Status
3461 Either "Interim" or "Standard". See below for description.
3462
3463 A version number is designated as either "Interim" or "Standard".
3464
3465 A "Standard" version number is documented in an RFC and used to
3466 identify a major, stable version of the WebSocket protocol, such as
3467 the version defined by this RFC. "Standard" version numbers are
3468 subject to the "IETF Review" IANA registration policy [RFC5226].
3469
3470
3471
3472
3473
3474Fette & Melnikov Standards Track [Page 62]
3475
3476RFC 6455 The WebSocket Protocol December 2011
3477
3478
3479 An "Interim" version number is documented in an Internet-Draft and
3480 used to help implementors identify and interoperate with deployed
3481 versions of the WebSocket protocol, such as versions developed before
3482 the publication of this RFC. "Interim" version numbers are subject
3483 to the "Expert Review" IANA registration policy [RFC5226], with the
3484 chairs of the HYBI Working Group (or, if the working group closes,
3485 the Area Directors for the IETF Applications Area) being the initial
3486 Designated Experts.
3487
3488 IANA has added initial values to the registry as follows.
3489
3490 +--------+-----------------------------------------+----------+
3491 |Version | Reference | Status |
3492 | Number | | |
3493 +--------+-----------------------------------------+----------+
3494 | 0 + draft-ietf-hybi-thewebsocketprotocol-00 | Interim |
3495 +--------+-----------------------------------------+----------+
3496 | 1 + draft-ietf-hybi-thewebsocketprotocol-01 | Interim |
3497 +--------+-----------------------------------------+----------+
3498 | 2 + draft-ietf-hybi-thewebsocketprotocol-02 | Interim |
3499 +--------+-----------------------------------------+----------+
3500 | 3 + draft-ietf-hybi-thewebsocketprotocol-03 | Interim |
3501 +--------+-----------------------------------------+----------+
3502 | 4 + draft-ietf-hybi-thewebsocketprotocol-04 | Interim |
3503 +--------+-----------------------------------------+----------+
3504 | 5 + draft-ietf-hybi-thewebsocketprotocol-05 | Interim |
3505 +--------+-----------------------------------------+----------+
3506 | 6 + draft-ietf-hybi-thewebsocketprotocol-06 | Interim |
3507 +--------+-----------------------------------------+----------+
3508 | 7 + draft-ietf-hybi-thewebsocketprotocol-07 | Interim |
3509 +--------+-----------------------------------------+----------+
3510 | 8 + draft-ietf-hybi-thewebsocketprotocol-08 | Interim |
3511 +--------+-----------------------------------------+----------+
3512 | 9 + Reserved | |
3513 +--------+-----------------------------------------+----------+
3514 | 10 + Reserved | |
3515 +--------+-----------------------------------------+----------+
3516 | 11 + Reserved | |
3517 +--------+-----------------------------------------+----------+
3518 | 12 + Reserved | |
3519 +--------+-----------------------------------------+----------+
3520 | 13 + RFC 6455 | Standard |
3521 +--------+-----------------------------------------+----------+
3522
3523
3524
3525
3526
3527
3528
3529
3530Fette & Melnikov Standards Track [Page 63]
3531
3532RFC 6455 The WebSocket Protocol December 2011
3533
3534
353511.7. WebSocket Close Code Number Registry
3536
3537 This specification creates a new IANA registry for WebSocket
3538 Connection Close Code Numbers in accordance with the principles set
3539 out in RFC 5226 [RFC5226].
3540
3541 As part of this registry, IANA maintains the following information:
3542
3543 Status Code
3544 The Status Code denotes a reason for a WebSocket connection
3545 closure as per Section 7.4 of this document. The status code is
3546 an integer number between 1000 and 4999 (inclusive).
3547
3548 Meaning
3549 The meaning of the status code. Each status code has to have a
3550 unique meaning.
3551
3552 Contact
3553 A contact for the entity reserving the status code.
3554
3555 Reference
3556 The stable document requesting the status codes and defining their
3557 meaning. This is required for status codes in the range 1000-2999
3558 and recommended for status codes in the range 3000-3999.
3559
3560 WebSocket Close Code Numbers are subject to different registration
3561 requirements depending on their range. Requests for status codes for
3562 use by this protocol and its subsequent versions or extensions are
3563 subject to any one of the "Standards Action", "Specification
3564 Required" (which implies "Designated Expert"), or "IESG Review" IANA
3565 registration policies and should be granted in the range 1000-2999.
3566 Requests for status codes for use by libraries, frameworks, and
3567 applications are subject to the "First Come First Served" IANA
3568 registration policy and should be granted in the range 3000-3999.
3569 The range of status codes from 4000-4999 is designated for Private
3570 Use. Requests should indicate whether they are requesting status
3571 codes for use by the WebSocket Protocol (or a future version of the
3572 protocol), by extensions, or by libraries/frameworks/applications.
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586Fette & Melnikov Standards Track [Page 64]
3587
3588RFC 6455 The WebSocket Protocol December 2011
3589
3590
3591 IANA has added initial values to the registry as follows.
3592
3593 |Status Code | Meaning | Contact | Reference |
3594 -+------------+-----------------+---------------+-----------|
3595 | 1000 | Normal Closure | hybi@ietf.org | RFC 6455 |
3596 -+------------+-----------------+---------------+-----------|
3597 | 1001 | Going Away | hybi@ietf.org | RFC 6455 |
3598 -+------------+-----------------+---------------+-----------|
3599 | 1002 | Protocol error | hybi@ietf.org | RFC 6455 |
3600 -+------------+-----------------+---------------+-----------|
3601 | 1003 | Unsupported Data| hybi@ietf.org | RFC 6455 |
3602 -+------------+-----------------+---------------+-----------|
3603 | 1004 | ---Reserved---- | hybi@ietf.org | RFC 6455 |
3604 -+------------+-----------------+---------------+-----------|
3605 | 1005 | No Status Rcvd | hybi@ietf.org | RFC 6455 |
3606 -+------------+-----------------+---------------+-----------|
3607 | 1006 | Abnormal Closure| hybi@ietf.org | RFC 6455 |
3608 -+------------+-----------------+---------------+-----------|
3609 | 1007 | Invalid frame | hybi@ietf.org | RFC 6455 |
3610 | | payload data | | |
3611 -+------------+-----------------+---------------+-----------|
3612 | 1008 | Policy Violation| hybi@ietf.org | RFC 6455 |
3613 -+------------+-----------------+---------------+-----------|
3614 | 1009 | Message Too Big | hybi@ietf.org | RFC 6455 |
3615 -+------------+-----------------+---------------+-----------|
3616 | 1010 | Mandatory Ext. | hybi@ietf.org | RFC 6455 |
3617 -+------------+-----------------+---------------+-----------|
3618 | 1011 | Internal Server | hybi@ietf.org | RFC 6455 |
3619 | | Error | | |
3620 -+------------+-----------------+---------------+-----------|
3621 | 1015 | TLS handshake | hybi@ietf.org | RFC 6455 |
3622 -+------------+-----------------+---------------+-----------|
3623
362411.8. WebSocket Opcode Registry
3625
3626 This specification creates a new IANA registry for WebSocket Opcodes
3627 in accordance with the principles set out in RFC 5226 [RFC5226].
3628
3629 As part of this registry, IANA maintains the following information:
3630
3631 Opcode
3632 The opcode denotes the frame type of the WebSocket frame, as
3633 defined in Section 5.2. The opcode is an integer number between 0
3634 and 15, inclusive.
3635
3636 Meaning
3637 The meaning of the opcode value.
3638
3639
3640
3641
3642Fette & Melnikov Standards Track [Page 65]
3643
3644RFC 6455 The WebSocket Protocol December 2011
3645
3646
3647 Reference
3648 The specification requesting the opcode.
3649
3650 WebSocket Opcode numbers are subject to the "Standards Action" IANA
3651 registration policy [RFC5226].
3652
3653 IANA has added initial values to the registry as follows.
3654
3655 |Opcode | Meaning | Reference |
3656 -+--------+-------------------------------------+-----------|
3657 | 0 | Continuation Frame | RFC 6455 |
3658 -+--------+-------------------------------------+-----------|
3659 | 1 | Text Frame | RFC 6455 |
3660 -+--------+-------------------------------------+-----------|
3661 | 2 | Binary Frame | RFC 6455 |
3662 -+--------+-------------------------------------+-----------|
3663 | 8 | Connection Close Frame | RFC 6455 |
3664 -+--------+-------------------------------------+-----------|
3665 | 9 | Ping Frame | RFC 6455 |
3666 -+--------+-------------------------------------+-----------|
3667 | 10 | Pong Frame | RFC 6455 |
3668 -+--------+-------------------------------------+-----------|
3669
367011.9. WebSocket Framing Header Bits Registry
3671
3672 This specification creates a new IANA registry for WebSocket Framing
3673 Header Bits in accordance with the principles set out in RFC 5226
3674 [RFC5226]. This registry controls assignment of the bits marked
3675 RSV1, RSV2, and RSV3 in Section 5.2.
3676
3677 These bits are reserved for future versions or extensions of this
3678 specification.
3679
3680 WebSocket Framing Header Bits assignments are subject to the
3681 "Standards Action" IANA registration policy [RFC5226].
3682
368312. Using the WebSocket Protocol from Other Specifications
3684
3685 The WebSocket Protocol is intended to be used by another
3686 specification to provide a generic mechanism for dynamic author-
3687 defined content, e.g., in a specification defining a scripted API.
3688
3689 Such a specification first needs to _Establish a WebSocket
3690 Connection_, providing that algorithm with:
3691
3692 o The destination, consisting of a /host/ and a /port/.
3693
3694
3695
3696
3697
3698Fette & Melnikov Standards Track [Page 66]
3699
3700RFC 6455 The WebSocket Protocol December 2011
3701
3702
3703 o A /resource name/, which allows for multiple services to be
3704 identified at one host and port.
3705
3706 o A /secure/ flag, which is true if the connection is to be
3707 encrypted and false otherwise.
3708
3709 o An ASCII serialization of an origin [RFC6454] that is being made
3710 responsible for the connection.
3711
3712 o Optionally, a string identifying a protocol that is to be layered
3713 over the WebSocket connection.
3714
3715 The /host/, /port/, /resource name/, and /secure/ flag are usually
3716 obtained from a URI using the steps to parse a WebSocket URI's
3717 components. These steps fail if the URI does not specify a
3718 WebSocket.
3719
3720 If at any time the connection is to be closed, then the specification
3721 needs to use the _Close the WebSocket Connection_ algorithm
3722 (Section 7.1.1).
3723
3724 Section 7.1.4 defines when _The WebSocket Connection is Closed_.
3725
3726 While a connection is open, the specification will need to handle the
3727 cases when _A WebSocket Message Has Been Received_ (Section 6.2).
3728
3729 To send some data /data/ to an open connection, the specification
3730 needs to _Send a WebSocket Message_ (Section 6.1).
3731
373213. Acknowledgements
3733
3734 Special thanks are due to Ian Hickson, who was the original author
3735 and editor of this protocol. The initial design of this
3736 specification benefitted from the participation of many people in the
3737 WHATWG and WHATWG mailing list. Contributions to that specification
3738 are not tracked by section, but a list of all who contributed to that
3739 specification is given in the WHATWG HTML specification at
3740 http://whatwg.org/html5.
3741
3742 Special thanks also to John Tamplin for providing a significant
3743 amount of text for the "Data Framing" section of this specification.
3744
3745 Special thanks also to Adam Barth for providing a significant amount
3746 of text and background research for the "Data Masking" section of
3747 this specification.
3748
3749
3750
3751
3752
3753
3754Fette & Melnikov Standards Track [Page 67]
3755
3756RFC 6455 The WebSocket Protocol December 2011
3757
3758
3759 Special thanks to Lisa Dusseault for the Apps Area review (and for
3760 helping to start this work), Richard Barnes for the Gen-Art review,
3761 and Magnus Westerlund for the Transport Area Review. Special thanks
3762 to HYBI WG past and present WG chairs who tirelessly worked behind
3763 the scene to move this work toward completion: Joe Hildebrand,
3764 Salvatore Loreto, and Gabriel Montenegro. And last but not least,
3765 special thank you to the responsible Area Director Peter Saint-Andre.
3766
3767 Thank you to the following people who participated in discussions on
3768 the HYBI WG mailing list and contributed ideas and/or provided
3769 detailed reviews (the list is likely to be incomplete): Greg Wilkins,
3770 John Tamplin, Willy Tarreau, Maciej Stachowiak, Jamie Lokier, Scott
3771 Ferguson, Bjoern Hoehrmann, Julian Reschke, Dave Cridland, Andy
3772 Green, Eric Rescorla, Inaki Baz Castillo, Martin Thomson, Roberto
3773 Peon, Patrick McManus, Zhong Yu, Bruce Atherton, Takeshi Yoshino,
3774 Martin J. Duerst, James Graham, Simon Pieters, Roy T. Fielding,
3775 Mykyta Yevstifeyev, Len Holgate, Paul Colomiets, Piotr Kulaga, Brian
3776 Raymor, Jan Koehler, Joonas Lehtolahti, Sylvain Hellegouarch, Stephen
3777 Farrell, Sean Turner, Pete Resnick, Peter Thorson, Joe Mason, John
3778 Fallows, and Alexander Philippou. Note that people listed above
3779 didn't necessarily endorse the end result of this work.
3780
378114. References
3782
378314.1. Normative References
3784
3785 [ANSI.X3-4.1986]
3786 American National Standards Institute, "Coded Character
3787 Set - 7-bit American Standard Code for Information
3788 Interchange", ANSI X3.4, 1986.
3789
3790 [FIPS.180-3]
3791 National Institute of Standards and Technology, "Secure
3792 Hash Standard", FIPS PUB 180-3, October 2008,
3793 <http://csrc.nist.gov/publications/fips/fips180-3/
3794 fips180-3_final.pdf>.
3795
3796 [RFC1928] Leech, M., Ganis, M., Lee, Y., Kuris, R., Koblas, D., and
3797 L. Jones, "SOCKS Protocol Version 5", RFC 1928,
3798 March 1996.
3799
3800 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
3801 Requirement Levels", BCP 14, RFC 2119, March 1997.
3802
3803 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H.,
3804 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext
3805 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999.
3806
3807
3808
3809
3810Fette & Melnikov Standards Track [Page 68]
3811
3812RFC 6455 The WebSocket Protocol December 2011
3813
3814
3815 [RFC2817] Khare, R. and S. Lawrence, "Upgrading to TLS Within
3816 HTTP/1.1", RFC 2817, May 2000.
3817
3818 [RFC2818] Rescorla, E., "HTTP Over TLS", RFC 2818, May 2000.
3819
3820 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO
3821 10646", STD 63, RFC 3629, November 2003.
3822
3823 [RFC3864] Klyne, G., Nottingham, M., and J. Mogul, "Registration
3824 Procedures for Message Header Fields", BCP 90, RFC 3864,
3825 September 2004.
3826
3827 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform
3828 Resource Identifier (URI): Generic Syntax", STD 66,
3829 RFC 3986, January 2005.
3830
3831 [RFC3987] Duerst, M. and M. Suignard, "Internationalized Resource
3832 Identifiers (IRIs)", RFC 3987, January 2005.
3833
3834 [RFC4086] Eastlake, D., Schiller, J., and S. Crocker, "Randomness
3835 Requirements for Security", BCP 106, RFC 4086, June 2005.
3836
3837 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data
3838 Encodings", RFC 4648, October 2006.
3839
3840 [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an
3841 IANA Considerations Section in RFCs", BCP 26, RFC 5226,
3842 May 2008.
3843
3844 [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax
3845 Specifications: ABNF", STD 68, RFC 5234, January 2008.
3846
3847 [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security
3848 (TLS) Protocol Version 1.2", RFC 5246, August 2008.
3849
3850 [RFC6066] Eastlake, D., "Transport Layer Security (TLS) Extensions:
3851 Extension Definitions", RFC 6066, January 2011.
3852
3853 [RFC6454] Barth, A., "The Web Origin Concept", RFC 6454,
3854 December 2011.
3855
385614.2. Informative References
3857
3858 [RFC4122] Leach, P., Mealling, M., and R. Salz, "A Universally
3859 Unique IDentifier (UUID) URN Namespace", RFC 4122,
3860 July 2005.
3861
3862
3863
3864
3865
3866Fette & Melnikov Standards Track [Page 69]
3867
3868RFC 6455 The WebSocket Protocol December 2011
3869
3870
3871 [RFC4270] Hoffman, P. and B. Schneier, "Attacks on Cryptographic
3872 Hashes in Internet Protocols", RFC 4270, November 2005.
3873
3874 [RFC5321] Klensin, J., "Simple Mail Transfer Protocol", RFC 5321,
3875 October 2008.
3876
3877 [RFC6202] Loreto, S., Saint-Andre, P., Salsano, S., and G. Wilkins,
3878 "Known Issues and Best Practices for the Use of Long
3879 Polling and Streaming in Bidirectional HTTP", RFC 6202,
3880 April 2011.
3881
3882 [RFC6265] Barth, A., "HTTP State Management Mechanism", RFC 6265,
3883 April 2011.
3884
3885 [TALKING] Huang, L-S., Chen, E., Barth, A., Rescorla, E., and C.
3886 Jackson, "Talking to Yourself for Fun and Profit", 2010,
3887 <http://w2spconf.com/2011/papers/websocket.pdf>.
3888
3889 [W3C.REC-wsc-ui-20100812]
3890 Roessler, T. and A. Saldhana, "Web Security Context: User
3891 Interface Guidelines", World Wide Web Consortium
3892 Recommendation REC-wsc-ui-20100812, August 2010,
3893 <http://www.w3.org/TR/2010/REC-wsc-ui-20100812/>.
3894
3895 Latest version available at
3896 <http://www.w3.org/TR/wsc-ui/>.
3897
3898 [WSAPI] Hickson, I., "The WebSocket API", W3C Working Draft WD-
3899 websockets-20110929, September 2011,
3900 <http://www.w3.org/TR/2011/WD-websockets-20110929/>.
3901
3902 Latest version available at
3903 <http://www.w3.org/TR/websockets/>.
3904
3905 [XMLHttpRequest]
3906 van Kesteren, A., Ed., "XMLHttpRequest", W3C Candidate
3907 Recommendation CR-XMLHttpRequest-20100803, August 2010,
3908 <http://www.w3.org/TR/2010/CR-XMLHttpRequest-20100803/>.
3909
3910 Latest version available at
3911 <http://www.w3.org/TR/XMLHttpRequest/>.
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922Fette & Melnikov Standards Track [Page 70]
3923
3924RFC 6455 The WebSocket Protocol December 2011
3925
3926
3927Authors' Addresses
3928
3929 Ian Fette
3930 Google, Inc.
3931
3932 EMail: ifette+ietf@google.com
3933 URI: http://www.ianfette.com/
3934
3935
3936 Alexey Melnikov
3937 Isode Ltd.
3938 5 Castle Business Village
3939 36 Station Road
3940 Hampton, Middlesex TW12 2BX
3941 UK
3942
3943 EMail: Alexey.Melnikov@isode.com
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978Fette & Melnikov Standards Track [Page 71]
3979
3980