draft-ietf-hybi-thewebsocketprotocol-00.txt   draft-ietf-hybi-thewebsocketprotocol-01.txt 
Network Working Group I. Hickson HyBi Working Group I. Fette
Internet-Draft Google, Inc. Internet-Draft Google, Inc.
Intended status: Standards Track May 23, 2010 Intended status: Standards Track August 31, 2010
Expires: November 24, 2010 Expires: March 4, 2011
The WebSocket protocol The WebSocket protocol
draft-ietf-hybi-thewebsocketprotocol-00 draft-ietf-hybi-thewebsocketprotocol-01
Abstract Abstract
The WebSocket protocol enables two-way communication between a user The WebSocket protocol enables two-way communication between a user
agent running untrusted code running in a controlled environment to a agent running untrusted code running in a controlled environment to a
remote host that has opted-in to communications from that code. The remote host that has opted-in to communications from that code. The
security model used for this is the Origin-based security model security model used for this is the Origin-based security model
commonly used by Web browsers. The protocol consists of an initial commonly used by Web browsers. The protocol consists of an initial
handshake followed by basic message framing, layered over TCP. The handshake followed by basic message framing, layered over TCP. The
goal of this technology is to provide a mechanism for browser-based goal of this technology is to provide a mechanism for browser-based
applications that need two-way communication with servers that does applications that need two-way communication with servers that does
not rely on opening multiple HTTP connections (e.g. using not rely on opening multiple HTTP connections (e.g. using
XMLHttpRequest or <iframe>s and long polling). XMLHttpRequest or <iframe>s and long polling).
NOTE! THIS COPY OF THIS DOCUMENT IS OBSOLETE. Please send feedback to the hybi@ietf.org mailing list.
For an up-to-date copy of this specification, please see:
http://www.whatwg.org/specs/web-socket-protocol/
Author's note
This document is automatically generated from the same source Note
document as the HTML specification. [HTML]
Please send feedback to either the hybi@ietf.org list or the This draft is meant to reflect changes in direction in the HyBi
whatwg@whatwg.org list. working group. There is not yet consensus on everything in this
draft. Specifically, details about the framing are still under
discussion, however this draft is much closer to what the group is
discussing than the previous draft. There have also been proposals
to change the handshake, so the handshake is also not in a final
form.
Status of this Memo Status of this Memo
This Internet-Draft is submitted to IETF in full conformance with the This Internet-Draft is submitted in full conformance with the
provisions of BCP 78 and BCP 79. provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF). Note that other groups may also distribute Task Force (IETF). Note that other groups may also distribute
working documents as Internet-Drafts. The list of current Internet- working documents as Internet-Drafts. The list of current Internet-
Drafts is at http://datatracker.ietf.org/drafts/current/. Drafts is at http://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months Internet-Drafts are draft documents valid for a maximum of six months
and may be updated, replaced, or obsoleted by other documents at any and may be updated, replaced, or obsoleted by other documents at any
time. It is inappropriate to use Internet-Drafts as reference time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress." material or to cite them other than as "work in progress."
This Internet-Draft will expire on November 24, 2010. This Internet-Draft will expire on March 4, 2011.
Copyright Notice Copyright Notice
Copyright (c) 2010 IETF Trust and the persons identified as the Copyright (c) 2010 IETF Trust and the persons identified as the
document authors. All rights reserved. document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents Provisions Relating to IETF Documents
(http://trustee.ietf.org/license-info) in effect on the date of (http://trustee.ietf.org/license-info) in effect on the date of
publication of this document. Please review these documents publication of this document. Please review these documents
carefully, as they describe your rights and restrictions with respect carefully, as they describe your rights and restrictions with respect
to this document. Code Components extracted from this document must to this document. Code Components extracted from this document must
include Simplified BSD License text as described in Section 4.e of include Simplified BSD License text as described in Section 4.e of
the Trust Legal Provisions and are provided without warranty as the Trust Legal Provisions and are provided without warranty as
described in the Simplified BSD License. described in the Simplified BSD License.
Table of Contents Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 4 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1. Background . . . . . . . . . . . . . . . . . . . . . . . . 4 1.1. Background . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2. Protocol overview . . . . . . . . . . . . . . . . . . . . 4 1.2. Protocol overview . . . . . . . . . . . . . . . . . . . . 5
1.3. Opening handshake . . . . . . . . . . . . . . . . . . . . 7 1.3. Opening handshake . . . . . . . . . . . . . . . . . . . . 9
1.4. Closing handshake . . . . . . . . . . . . . . . . . . . . 10 1.4. Closing handshake . . . . . . . . . . . . . . . . . . . . 12
1.5. Design philosophy . . . . . . . . . . . . . . . . . . . . 11 1.5. Design philosophy . . . . . . . . . . . . . . . . . . . . 13
1.6. Security model . . . . . . . . . . . . . . . . . . . . . . 12 1.6. Security model . . . . . . . . . . . . . . . . . . . . . . 14
1.7. Relationship to TCP and HTTP . . . . . . . . . . . . . . . 12 1.7. Relationship to TCP and HTTP . . . . . . . . . . . . . . . 14
1.8. Establishing a connection . . . . . . . . . . . . . . . . 12 1.8. Establishing a connection . . . . . . . . . . . . . . . . 14
1.9. Subprotocols using the WebSocket protocol . . . . . . . . 13 1.9. Subprotocols using the WebSocket protocol . . . . . . . . 15
2. Conformance requirements . . . . . . . . . . . . . . . . . . . 15 2. Conformance requirements . . . . . . . . . . . . . . . . . . . 17
2.1. Terminology . . . . . . . . . . . . . . . . . . . . . . . 15 2.1. Terminology . . . . . . . . . . . . . . . . . . . . . . . 17
3. WebSocket URLs . . . . . . . . . . . . . . . . . . . . . . . . 17 3. WebSocket URLs . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1. Parsing WebSocket URLs . . . . . . . . . . . . . . . . . . 17 3.1. Parsing WebSocket URLs . . . . . . . . . . . . . . . . . . 19
3.2. Constructing WebSocket URLs . . . . . . . . . . . . . . . 18 3.2. Constructing WebSocket URLs . . . . . . . . . . . . . . . 20
4. Client-side requirements . . . . . . . . . . . . . . . . . . . 19 3.3. Valid WebSocket URLs . . . . . . . . . . . . . . . . . . . 20
4.1. Opening handshake . . . . . . . . . . . . . . . . . . . . 19 4. Data Framing . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.2. Data framing . . . . . . . . . . . . . . . . . . . . . . . 28 4.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.3. Handling errors in UTF-8 from the server . . . . . . . . . 30 4.2. Base Framing Protocol . . . . . . . . . . . . . . . . . . 21
5. Server-side requirements . . . . . . . . . . . . . . . . . . . 32 4.3. Fragmentation . . . . . . . . . . . . . . . . . . . . . . 22
5.1. Reading the client's opening handshake . . . . . . . . . . 32 4.4. Control Frames . . . . . . . . . . . . . . . . . . . . . . 23
5.2. Sending the server's opening handshake . . . . . . . . . . 35 4.5. Data Frames . . . . . . . . . . . . . . . . . . . . . . . 24
5.3. Data framing . . . . . . . . . . . . . . . . . . . . . . . 39 4.6. Examples . . . . . . . . . . . . . . . . . . . . . . . . . 24
5.4. Handling errors in UTF-8 from the client . . . . . . . . . 41 4.7. Extensibility . . . . . . . . . . . . . . . . . . . . . . 25
6. Closing the connection . . . . . . . . . . . . . . . . . . . . 42 5. Opening Handshake . . . . . . . . . . . . . . . . . . . . . . 26
6.1. Client-initiated closure . . . . . . . . . . . . . . . . . 42 5.1. Client Requirements . . . . . . . . . . . . . . . . . . . 26
6.2. Server-initiated closure . . . . . . . . . . . . . . . . . 42 5.2. Server-side requirements . . . . . . . . . . . . . . . . . 35
6.3. Closure . . . . . . . . . . . . . . . . . . . . . . . . . 42 5.2.1. Reading the client's opening handshake . . . . . . . . 35
7. Security considerations . . . . . . . . . . . . . . . . . . . 44 5.2.2. Sending the server's opening handshake . . . . . . . . 38
8. IANA considerations . . . . . . . . . . . . . . . . . . . . . 45 6. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 43
8.1. Registration of ws: scheme . . . . . . . . . . . . . . . . 45 6.1. Handling errors in UTF-8 from the server . . . . . . . . . 43
8.2. Registration of wss: scheme . . . . . . . . . . . . . . . 46 6.2. Handling errors in UTF-8 from the client . . . . . . . . . 43
8.3. Registration of the "WebSocket" HTTP Upgrade keyword . . . 47 7. Closing the connection . . . . . . . . . . . . . . . . . . . . 44
8.4. Sec-WebSocket-Key1 and Sec-WebSocket-Key2 . . . . . . . . 47 7.1. Client-initiated closure . . . . . . . . . . . . . . . . . 44
8.5. Sec-WebSocket-Location . . . . . . . . . . . . . . . . . . 48 7.2. Server-initiated closure . . . . . . . . . . . . . . . . . 44
8.6. Sec-WebSocket-Origin . . . . . . . . . . . . . . . . . . . 49 7.3. Closure . . . . . . . . . . . . . . . . . . . . . . . . . 44
8.7. Sec-WebSocket-Protocol . . . . . . . . . . . . . . . . . . 50 8. Security considerations . . . . . . . . . . . . . . . . . . . 46
9. Using the WebSocket protocol from other specifications . . . . 51 9. IANA considerations . . . . . . . . . . . . . . . . . . . . . 47
10. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 52 9.1. Registration of ws: scheme . . . . . . . . . . . . . . . . 47
11. Normative References . . . . . . . . . . . . . . . . . . . . . 53 9.2. Registration of wss: scheme . . . . . . . . . . . . . . . 48
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 55 9.3. Registration of the "WebSocket" HTTP Upgrade keyword . . . 49
9.4. Sec-WebSocket-Key1 and Sec-WebSocket-Key2 . . . . . . . . 49
9.5. Sec-WebSocket-Location . . . . . . . . . . . . . . . . . . 50
9.6. Sec-WebSocket-Origin . . . . . . . . . . . . . . . . . . . 51
9.7. Sec-WebSocket-Protocol . . . . . . . . . . . . . . . . . . 52
10. Using the WebSocket protocol from other specifications . . . . 53
11. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 54
12. Normative References . . . . . . . . . . . . . . . . . . . . . 55
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . . 57
1. Introduction 1. Introduction
1.1. Background 1.1. Background
_This section is non-normative._ _This section is non-normative._
Historically, creating an instant messenger chat client as a Web Historically, creating an instant messenger chat client as a Web
application has required an abuse of HTTP to poll the server for application has required an abuse of HTTP to poll the server for
updates while sending upstream notifications as distinct HTTP calls. updates while sending upstream notifications as distinct HTTP calls.
skipping to change at page 5, line 35 skipping to change at page 7, line 4
8jKS'y:G*Co,Wxa- 8jKS'y:G*Co,Wxa-
The leading line from the client follows the Request-Line format. The leading line from the client follows the Request-Line format.
The leading line from the server follows the Status-Line format. The The leading line from the server follows the Status-Line format. The
Request-Line and Status-Line productions are defined in the HTTP Request-Line and Status-Line productions are defined in the HTTP
specification. specification.
After the leading line in both cases come an unordered ASCII case- After the leading line in both cases come an unordered ASCII case-
insensitive set of fields, one per line, that each match the insensitive set of fields, one per line, that each match the
following non-normative ABNF: [RFC5234] following non-normative ABNF: [RFC5234]
field = 1*name-char colon [ space ] *any-char cr lf
field = 1*name-char colon [ space ] *any-char cr lf colon = %x003A ; U+003A COLON (:)
colon = %x003A ; U+003A COLON (:) space = %x0020 ; U+0020 SPACE
space = %x0020 ; U+0020 SPACE cr = %x000D ; U+000D CARRIAGE RETURN (CR)
cr = %x000D ; U+000D CARRIAGE RETURN (CR) lf = %x000A ; U+000A LINE FEED (LF)
lf = %x000A ; U+000A LINE FEED (LF) name-char = %x0000-0009
name-char = %x0000-0009 / %x000B-000C / %x000E-0039 / %x003B-10FFFF / %x000B-000C
; a Unicode character other than U+000A LINE FEED (LF), U+000D CARRIAGE RETURN (CR), or U+003A COLON (:) / %x000E-0039
any-char = %x0000-0009 / %x000B-000C / %x000E-10FFFF / %x003B-10FFFF
; a Unicode character other than U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) ; a Unicode character other than
; U+000A LINE FEED (LF),
; U+000D CARRIAGE RETURN (CR),
; or U+003A COLON (:)
any-char = %x0000-0009 / %x000B-000C / %x000E-10FFFF
; a Unicode character other than
; U+000A LINE FEED (LF)
; or U+000D CARRIAGE RETURN (CR)
NOTE: The character set for the above ABNF is Unicode. The fields NOTE: The character set for the above ABNF is Unicode. The fields
themselves are encoded as UTF-8. themselves are encoded as UTF-8.
Lines that don't match the above production cause the connection to Lines that don't match the above production cause the connection to
be aborted. be aborted.
Finally, after the last field, the client sends 10 bytes starting Finally, after the last field, the client sends 10 bytes starting
with 0x0D 0x0A and followed by 8 random bytes, part of a challenge, with 0x0D 0x0A and followed by 8 random bytes, part of a challenge,
and the server sends 18 bytes starting with 0x0D 0x0A and followed by and the server sends 18 bytes starting with 0x0D 0x0A and followed by
16 bytes consisting of a challenge response. The details of this 16 bytes consisting of a challenge response. The details of this
challenge and other parts of the handshake are described in the next challenge and other parts of the handshake are described in the next
section. section.
Once the client and server have both sent their handshakes, and if Once the client and server have both sent their handshakes, and if
the handshake was successful, then the data transfer part starts. the handshake was successful, then the data transfer part starts.
This is a two-way communication channel where each side can, This is a two-way communication channel where each side can,
independently from the other, send data at will. independently from the other, send data at will.
Data is sent in the form of UTF-8 text. Each frame of data starts Clients and servers, after a successful handshake, transfer data back
with a 0x00 byte and ends with a 0xFF byte, with the UTF-8 text in and forth in conceptual units referred to in this specification as
between. "messages". A message is a complete unit of data at an application
level, with the expectation that many or most applications
implementing this protocol (such as web user agents) provide APIs in
terms of sending and receiving messages. On the network layer, a
message may be represented as one or more frames.
Data is sent on the wire in the form of frames that have an
associated type. Broadly speaking, there are types for textual data,
which is interpreted as UTF-8 text, binary data (whose interpretation
is left up to the application), and control frames, which are not
intended to carry data for the application, but instead for protocol-
level signalling, such as to signal that the connection should be
closed.
The WebSocket protocol uses this framing so that specifications that The WebSocket protocol uses this framing so that specifications that
use the WebSocket protocol can expose such connections using an use the WebSocket protocol can expose such connections using an
event-based mechanism instead of requiring users of those event-based mechanism instead of requiring users of those
specifications to implement buffering and piecing together of specifications to implement buffering and piecing together of
messages manually. messages manually.
To close the connection cleanly, a frame consisting of just a 0xFF To close the connection cleanly, a control frame is sent from one
byte followed by a 0x00 byte is sent from one peer to ask that the peer to ask that the other peer close the connection. Details are
other peer close the connection. specified in Section 7.
The protocol is designed to support other frame types in future. The protocol is designed to support other frame types in future.
Instead of the 0x00 and 0xFF bytes, other bytes might in future be Currently only four frame types are defined -- continuation (used for
defined. Frames denoted by bytes that do not have the high bit set fragmented messages), control frames, text frames, and binary data
(0x00 to 0x7F) are treated as a stream of bytes terminated by 0xFF. frames. Eight frame types are reserved for future use, and four
Frames denoted by bytes that have the high bit set (0x80 to 0xFF) frame types are reserved for private use.
have a leading length indicator, which is encoded as a series of
7-bit bytes stored in octets with the 8th bit being set for all but
the last byte. The remainder of the frame is then as much data as
was specified. (The closing handshake contains no data and therefore
has a length byte of 0x00.)
This wire format for the data transfer part is described by the This wire format for the data transfer part is described by the ABNF
following non-normative ABNF, which is given in two alternative given in detail in Section 4. A high level overview of the framing
forms: the first describing the wire format as allowed by this is given in the following figure. [RFC5234]
specification, and the second describing how an arbitrary bytestream
would be parsed. [RFC5234]
; the wire protocol as allowed by this specification
frames = *frame
frame = text-frame / closing-frame
text-frame = %x00 *( UTF8-char ) %xFF
closing-frame = %xFF %x00
; the wire protocol including error-handling and forward-compatible parsing rules 0 1 2 3
frames = *frame 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
frame = text-frame / binary-frame +-+-+-+-+-------+-+-------------+-------------------------------+
text-frame = (%x00-7F) *(%x00-FE) %xFF |M|R|R|R| opcode|R| Payload len | Extended payload length |
binary-frame = (%x80-FF) length < as many bytes as given by the length > |O|S|S|S| (4) |S| (7) | (16/63) |
length = *(%x80-FF) (%x00-7F) |R|V|V|V| |V| | (if payload len==126/127) |
|E|1|2|3| |4| | |
+-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
| Extended payload length continued, if payload len == 127 |
+ - - - - - - - - - - - - - - - +-------------------------------+
| | Extension data |
+-------------------------------+ - - - - - - - - - - - - - - - +
: :
+---------------------------------------------------------------+
: Application data :
+---------------------------------------------------------------+
The UTF8-char rule is defined in the UTF-8 specification. [RFC3629] MORE: 1 bit
NOTE: The above ABNF is intended for a binary octet environment. Indicates more fragments follow in the current message
!!! WARNING: At this time, the WebSocket protocol cannot be used to RSV1, RSV2, RSV3, RSV4: 1 bit each
send binary data. Using any of the frame types other than 0x00 and
0xFF is invalid. All other frame types are reserved for future use
by future versions of this protocol.
The following diagram summarises the protocol: Must be 0 unless an extension is negotiated which defines meanings
for non-zero values
Handshake Opcode: 4 bits
|
V Defines the interpretation of the payload data
Frame type byte <--------------------------------------.
| | | Payload length: 7 bits
| `--> (0x00 to 0x7F) --> Data... --> 0xFF -->-+
| | The length of the payload: if 0-125, that is the payload length.
`--> (0x80 to 0xFE) --> Length --> Data... ------->-' If 126, the following 2 bytes interpreted as a 16 bit unsigned
integer are the payload length. If 127, the following 8 bytes
interpreted as a 64-bit unsigned integer (the high bit must be 0)
are the payload length. The payload length is the length of the
Extension data + the length of the Application Data. The length
of the Extension data may be zero, in which case the Payload
length is the length of the Application data.
Extension data: n bytes
Only present if an extension is negotiated during the handshake
which defines it. If present, it is included in the total payload
length.
Application data: n bytes
Arbitrary application data, taking up the remainder of the frame
after any extension data. The length of the Application data is
equal to the payload length minus the length of the Extension
data.
1.3. Opening handshake 1.3. Opening handshake
_This section is non-normative._ _This section is non-normative._
The opening handshake is intended to be compatible with HTTP-based The opening handshake is intended to be compatible with HTTP-based
server-side software, so that a single port can be used by both HTTP server-side software, so that a single port can be used by both HTTP
clients talking to that server and WebSocket clients talking to that clients talking to that server and WebSocket clients talking to that
server. To this end, the WebSocket client's handshake appears to server. To this end, the WebSocket client's handshake appears to
HTTP servers to be a regular GET request with an Upgrade offer: HTTP servers to be a regular GET request with an Upgrade offer:
skipping to change at page 10, line 51 skipping to change at page 13, line 4
disconnect. disconnect.
Having part of the handshake appear after the fields ensures that Having part of the handshake appear after the fields ensures that
both the server and the client verify that the connection is not both the server and the client verify that the connection is not
being interrupted by an HTTP intermediary such as a man-in-the-middle being interrupted by an HTTP intermediary such as a man-in-the-middle
cache or proxy. cache or proxy.
1.4. Closing handshake 1.4. Closing handshake
_This section is non-normative._ _This section is non-normative._
The closing handshake is far simpler than the opening handshake. The closing handshake is far simpler than the opening handshake.
Either peer can send a 0xFF frame with length 0x00 to begin the Either peer can send a control frame with data containing a specified
closing handshake. Upon receiving a 0xFF frame, the other peer sends control sequence to begin the closing handshake. Upon receiving such
an identical 0xFF frame in acknowledgement, if it hasn't already sent a frame, the other peer sends an identical frame in acknowledgement,
one. Upon receiving _that_ 0xFF frame, the first peer then closes if it hasn't already sent one. Upon receiving _that_ control frame,
the connection, safe in the knowledge that no further data is the first peer then closes the connection, safe in the knowledge that
forthcoming. no further data is forthcoming.
After sending a 0xFF frame, a peer does not send any further data; After sending a control frame indicating the connection should be
after receiving a 0xFF frame, a peer discards any further data closed, a peer does not send any further data; after receiving a
received. control frame frame indicating the connection should be closed, a
peer discards any further data received.
It is safe for both peers to initiate this handshake simultaneously. It is safe for both peers to initiate this handshake simultaneously.
The closing handshake is intended to replace the TCP closing The closing handshake is intended to replace the TCP closing
handshake (FIN/ACK), on the basis that the TCP closing handshake is handshake (FIN/ACK), on the basis that the TCP closing handshake is
not always reliable end-to-end, especially in the presence of man-in- not always reliable end-to-end, especially in the presence of man-in-
the-middle proxies and other intermediaries. the-middle proxies and other intermediaries.
1.5. Design philosophy 1.5. Design philosophy
skipping to change at page 13, line 48 skipping to change at page 15, line 50
Corporation were to create a Chat subprotocol to be implemented by Corporation were to create a Chat subprotocol to be implemented by
many servers around the Web, they could name it "chat.example.com". many servers around the Web, they could name it "chat.example.com".
If the Example Organisation called their competing subprotocol If the Example Organisation called their competing subprotocol
"example.org's chat protocol", then the two subprotocols could be "example.org's chat protocol", then the two subprotocols could be
implemented by servers simultaneously, with the server dynamically implemented by servers simultaneously, with the server dynamically
selecting which subprotocol to use based on the value sent by the selecting which subprotocol to use based on the value sent by the
client. client.
Subprotocols can be versioned in backwards-incompatible ways by Subprotocols can be versioned in backwards-incompatible ways by
changing the subprotocol name, eg. going from "bookings.example.net" changing the subprotocol name, eg. going from "bookings.example.net"
to "bookings.example.net2". These subprotocols would be considered to "v2.bookings.example.net". These subprotocols would be considered
completely separate by WebSocket clients. Backwards-compatible completely separate by WebSocket clients. Backwards-compatible
versioning can be implemented by reusing the same subprotocol string versioning can be implemented by reusing the same subprotocol string
but carefully designing the actual subprotocol to support this kind but carefully designing the actual subprotocol to support this kind
of extensibility. of extensibility.
2. Conformance requirements 2. Conformance requirements
All diagrams, examples, and notes in this specification are non- All diagrams, examples, and notes in this specification are non-
normative, as are all sections explicitly marked non-normative. normative, as are all sections explicitly marked non-normative.
Everything else in this specification is normative. Everything else in this specification is normative.
skipping to change at page 19, line 5 skipping to change at page 20, line 27
3. Append /host/ to /url/. 3. Append /host/ to /url/.
4. If the /secure/ flag is false and port is not 80, or if the 4. If the /secure/ flag is false and port is not 80, or if the
/secure/ flag is true and port is not 443, then append the string /secure/ flag is true and port is not 443, then append the string
":" followed by /port/ to /url/. ":" followed by /port/ to /url/.
5. Append /resource name/ to /url/. 5. Append /resource name/ to /url/.
6. Return /url/. 6. Return /url/.
4. Client-side requirements 3.3. Valid WebSocket URLs
_This section only applies to user agents, not to servers._ For a WebSocket URL to be considered valid, the following conditions
MUST hold.
NOTE: This specification doesn't currently define a limit to the o The /host/ must be ASCII-only (i.e. it must have been punycode-
number of simultaneous connections that a client can establish to a encoded already if necessary).
server.
4.1. Opening handshake o The /origin/ must not contain characters in the range U+0041 to
U+005A (i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z).
o The /resource name/ and /protocol/ strings must be non-empty
strings of ASCII characters in the range U+0020 to U+007E.
o The /resource name/ string must start with a U+002F SOLIDUS
character (/) and must not contain a U+0020 SPACE character.
Any WebSocket URLs not meeting the above criteria are considered
invalid, and a client MUST NOT attempt to make a connection to an
invalid WebSocket URL. A client SHOULD attempt to parse a URL
obtained from any external source (such as a web site or a user)
using the steps specified in Section 3.1 to obtain a valid WebSocket
URL, but MUST NOT attempt to connect with such an unparsed URL, and
instead only use the parsed version and only if that version is
considered valid by the criteria above.
4. Data Framing
4.1. Overview
The base framing protocol is deliberately kept simple so that simple
implementations may ignore advanced features. In the absence of
extensions negotiated during the opening handshake (Section 5), all
reserved bits must be 0 and no reserved opcode values may be used.
4.2. Base Framing Protocol
The base framing protocol is defined by the following ABNF [RFC5234]:
ws-frame = frame-more
frame-rsv1
frame-rsv2
frame-rsv3
frame-opcode
frame-rsv4
frame-length
frame-extension
application-data;
frame-more = %x0 ; final frame of message
/ %x1 ; more frames of this message follow
frame-rsv1 = %x0 ; 1 bit, must be 0
frame-rsv2 = %x0 ; 1 bit, must be 0
frame-rsv3 = %x0 ; 1 bit, must be 0
frame-opcode = %x0 ; continuation frame
/ %x1 ; connection close
/ %x2 ; ping
/ %x3 ; pong
/ %x4 ; text frame
/ %x5 ; binary frame
/ %x6-F ; reserved
frame-rsv4 = %x0 ; 1 bit, must be 0
frame-length = %x00-7D
/ %x7E frame-length-16
/ %x7F frame-length-63
frame-length-16 = %x0000-FFFF
frame-length-63 = %x0000000000000000-7FFFFFFFFFFFFFFF
frame-extension = *( %x00-FF ) ; to be defined later
application-data = *( %x00-FF )
4.3. Fragmentation
The following rules apply to fragmentation:
o An unfragmented message consists of a single frame with the MORE
bit clear and an opcode other than 0.
o A fragmented message consists of a single frame with the MORE bit
set and an opcode other than 0, followed by zero or more frames
with the MORE bit set and the opcode set to 0, and terminated by a
single frame with the MORE bit clear and an opcode of 0. Its
content is the concatenation of the application data from each of
those frames in order.
o _Note: There is an open question as to whether control frames be
interjected in the middle of a fragmented message. If so, it must
be decided whether they be fragmented (which would require keeping
a stack of "in-progress" messages)._
o A sender MAY arbitrarily fragment a single message (which allows
generation of dynamic content without having to buffer the data in
order to count it).
o A receiver MUST be prepared to accept arbitrarily fragmented
messages, even if the sender sent the message in a single frame.
o An intermediary MAY fragment a message arbitrarily, except that it
MUST NOT fragment or otherwise modify any message with any
reserved bits set or using any reserved opcode, unless it observed
the negotiation of an extension which it understands and which
defines the interpretation of those values.
4.4. Control Frames
The Close (0x01), Ping (0x02), and Pong (0x03) frames are contol
frames -- they do not supply data to the ultimate endpoint, but
instead are used to carry out tasks related to the WebSocket
connection itself.
A receiver MUST take the following action upon receiving control
frames:
Close:
Upon receipt of a close frame, an endpoint SHOULD send a Close
frame to the remote recipient, if it has not already done so,
deliver a close event to the application if necessary, and then
close the WebSocket.
Ping
Upon receipt of a Ping message, an endpoint SHOULD send a Pong
response as soon as is practical. The Pong response MUST contain
the payload provided in the Ping message, though an implementation
MAY truncate the message at an implementation-defined size which
MUST be at least 8 _(TBD)_ bytes.
Ping frames MAY be sent as a keep-alive mechanism, but if so the
interval SHOULD be configurable.
Pong
If a Pong message is received without a matching Ping message
being sent, an endpoint MUST drop the connection. Otherwise, the
endpoint SHOULD update any liveness timer it may have for the
connection.
4.5. Data Frames
All frame types not listed above are data frames, which transport
application-layer data. The opcode determines the interpretation of
the application data:
Text
The payload data is text data encoded as UTF-8.
Binary
The payload data is arbitrary binary data whose interpretation is
solely up to the application layer.
Additional data frame types will be defined in extensions or in a
subsequent version of the protocol.
4.6. Examples
_This section is non-normative._
o A single-frame text message
* 0x04 0x05 "Hello"
o A fragmented text message
* 0x84 0x03 "Hel"
* 0x00 0x02 "lo"
o Ping request and response
* 0x02 0x05 "Hello"
* 0x03 0x05 "Hello"
o 256 bytes binary message in a single frame
* 0x05 0x7E 0x0100 [256 bytes of binary data]
o 64KiB binary message in a single frame
* 0x05 0x7F 0x0000000000010000 [65536 bytes of binary data]
4.7. Extensibility
Extensions will be defined which extend the base protocol, but only
if their use is negotiated during the handshake. The following
mechanisms will be used for extension:
o Extension data may be placed in the payload before the application
data.
o Reserved bits can be allocated for per-frame needs.
o Reserved opcode values can be defined.
o Reserved bits can be allocated to the opcode field if more opcode
values are needed.
o A reserved bit or an "extension" opcode can be defined which
allocates additional bits out of the payload area to define larger
opcodes or more per-frame bits.
5. Opening Handshake
5.1. Client Requirements
When the user agent is to *establish a WebSocket connection* to a When the user agent is to *establish a WebSocket connection* to a
host /host/, on a port /port/, from an origin whose ASCII host /host/, on a port /port/, from an origin whose ASCII
serialization is /origin/, with a flag /secure/, with a string giving serialization is /origin/, with a flag /secure/, with a string giving
a /resource name/, and optionally with a string giving a /protocol/, a /resource name/, and optionally with a string giving a /protocol/,
it must run the following steps. The /host/ must be ASCII-only (i.e. it must run the following steps. [ORIGIN]
it must have been punycode-encoded already if necessary). The
/origin/ must not contain characters in the range U+0041 to U+005A
(i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z). The
/resource name/ and /protocol/ strings must be non-empty strings of
ASCII characters in the range U+0020 to U+007E. The /resource name/
string must start with a U+002F SOLIDUS character (/) and must not
contain a U+0020 SPACE character. [ORIGIN]
1. If the user agent already has a WebSocket connection to the 1. Verify that the WebSocket URL and its components are valid
according to Section 3.3. If any of the requirements are not
met, the client MUST fail the WebSocket connection and abort
these steps.
2. If the user agent already has a WebSocket connection to the
remote host (IP address) identified by /host/, even if known by remote host (IP address) identified by /host/, even if known by
another name, wait until that connection has been established or another name, wait until that connection has been established or
for that connection to have failed. If multiple connections to for that connection to have failed. If multiple connections to
the same IP address are attempted simultaneously, the user agent the same IP address are attempted simultaneously, the user agent
must serialize them so that there is no more than one connection must serialize them so that there is no more than one connection
at a time running through the following steps. at a time running through the following steps.
NOTE: This makes it harder for a script to perform a denial of NOTE: This makes it harder for a script to perform a denial of
service attack by just opening a large number of WebSocket service attack by just opening a large number of WebSocket
connections to a remote host. connections to a remote host.
NOTE: There is no limit to the number of established WebSocket NOTE: There is no limit to the number of established WebSocket
connections a user agent can have with a single remote host. connections a user agent can have with a single remote host.
Servers can refuse to connect users with an excessive number of Servers can refuse to connect users with an excessive number of
connections, or disconnect resource-hogging users when suffering connections, or disconnect resource-hogging users when suffering
high load. high load.
2. _Connect_: If the user agent is configured to use a proxy when 3. _Connect_: If the user agent is configured to use a proxy when
using the WebSocket protocol to connect to host /host/ and/or using the WebSocket protocol to connect to host /host/ and/or
port /port/, then connect to that proxy and ask it to open a TCP port /port/, then connect to that proxy and ask it to open a TCP
connection to the host given by /host/ and the port given by connection to the host given by /host/ and the port given by
/port/. /port/.
EXAMPLE: For example, if the user agent uses an HTTP proxy EXAMPLE: For example, if the user agent uses an HTTP proxy
for all traffic, then if it was to try to connect to port 80 for all traffic, then if it was to try to connect to port 80
on server example.com, it might send the following lines to on server example.com, it might send the following lines to
the proxy server: the proxy server:
skipping to change at page 20, line 39 skipping to change at page 27, line 31
For the purpose of proxy autoconfiguration scripts, the URL to For the purpose of proxy autoconfiguration scripts, the URL to
pass the function must be constructed from /host/, /port/, pass the function must be constructed from /host/, /port/,
/resource name/, and the /secure/ flag using the steps to /resource name/, and the /secure/ flag using the steps to
construct a WebSocket URL. construct a WebSocket URL.
NOTE: The WebSocket protocol can be identified in proxy NOTE: The WebSocket protocol can be identified in proxy
autoconfiguration scripts from the scheme ("ws:" for unencrypted autoconfiguration scripts from the scheme ("ws:" for unencrypted
connections and "wss:" for encrypted connections). connections and "wss:" for encrypted connections).
3. If the connection could not be opened, then fail the WebSocket 4. If the connection could not be opened, then fail the WebSocket
connection and abort these steps. connection and abort these steps.
4. If /secure/ is true, perform a TLS handshake over the 5. If /secure/ is true, perform a TLS handshake over the
connection. If this fails (e.g. the server's certificate could connection. If this fails (e.g. the server's certificate could
not be verified), then fail the WebSocket connection and abort not be verified), then fail the WebSocket connection and abort
these steps. Otherwise, all further communication on this these steps. Otherwise, all further communication on this
channel must run through the encrypted tunnel. [RFC2246] channel must run through the encrypted tunnel. [RFC2246]
User agents must use the Server Name Indication extension in the User agents must use the Server Name Indication extension in the
TLS handshake. [RFC4366] TLS handshake. [RFC4366]
5. Send the UTF-8 string "GET" followed by a UTF-8-encoded U+0020 6. Send the UTF-8 string "GET" followed by a UTF-8-encoded U+0020
SPACE character to the remote side (the server). SPACE character to the remote side (the server).
Send the /resource name/ value, encoded as UTF-8. Send the /resource name/ value, encoded as UTF-8.
Send another UTF-8-encoded U+0020 SPACE character, followed by Send another UTF-8-encoded U+0020 SPACE character, followed by
the UTF-8 string "HTTP/1.1", followed by a UTF-8-encoded U+000D the UTF-8 string "HTTP/1.1", followed by a UTF-8-encoded U+000D
CARRIAGE RETURN U+000A LINE FEED character pair (CRLF). CARRIAGE RETURN U+000A LINE FEED character pair (CRLF).
6. Let /fields/ be an empty list of strings. 7. Let /fields/ be an empty list of strings.
7. Add the string "Upgrade: WebSocket" to /fields/. 8. Add the string "Upgrade: WebSocket" to /fields/.
8. Add the string "Connection: Upgrade" to /fields/. 9. Add the string "Connection: Upgrade" to /fields/.
9. Let /hostport/ be an empty string. 10. Let /hostport/ be an empty string.
10. Append the /host/ value, converted to ASCII lowercase, to 11. Append the /host/ value, converted to ASCII lowercase, to
/hostport/. /hostport/.
11. If /secure/ is false, and /port/ is not 80, or if /secure/ is 12. If /secure/ is false, and /port/ is not 80, or if /secure/ is
true, and /port/ is not 443, then append a U+003A COLON true, and /port/ is not 443, then append a U+003A COLON
character (:) followed by the value of /port/, expressed as a character (:) followed by the value of /port/, expressed as a
base-ten integer, to /hostport/. base-ten integer, to /hostport/.
12. Add the string consisting of the concatenation of the string 13. Add the string consisting of the concatenation of the string
"Host:", a U+0020 SPACE character, and /hostport/, to /fields/. "Host:", a U+0020 SPACE character, and /hostport/, to /fields/.
13. Add the string consisting of the concatenation of the string 14. Add the string consisting of the concatenation of the string
"Origin:", a U+0020 SPACE character, and the /origin/ value, to "Origin:", a U+0020 SPACE character, and the /origin/ value, to
/fields/. /fields/.
14. If there is no /protocol/, then skip this step. 15. If there is no /protocol/, then skip this step.
Otherwise, add the string consisting of the concatenation of the Otherwise, add the string consisting of the concatenation of the
string "Sec-WebSocket-Protocol:", a U+0020 SPACE character, and string "Sec-WebSocket-Protocol:", a U+0020 SPACE character, and
the /protocol/ value, to /fields/. the /protocol/ value, to /fields/.
15. If the client has any cookies that would be relevant to a 16. If the client has any cookies that would be relevant to a
resource accessed over HTTP, if /secure/ is false, or HTTPS, if resource accessed over HTTP, if /secure/ is false, or HTTPS, if
it is true, on host /host/, port /port/, with /resource name/ as it is true, on host /host/, port /port/, with /resource name/ as
the path (and possibly query parameters), then add to /fields/ the path (and possibly query parameters), then add to /fields/
any HTTP headers that would be appropriate for that information. any HTTP headers that would be appropriate for that information.
[RFC2616] [RFC2109] [RFC2965] [RFC2616] [RFC2109] [RFC2965]
This includes "HttpOnly" cookies (cookies with the http-only- This includes "HttpOnly" cookies (cookies with the http-only-
flag set to true); the WebSocket protocol is not considered a flag set to true); the WebSocket protocol is not considered a
non-HTTP API for the purpose of cookie processing. non-HTTP API for the purpose of cookie processing.
16. Let /spaces_1/ be a random integer from 1 to 12 inclusive. 17. Let /spaces_1/ be a random integer from 1 to 12 inclusive.
Let /spaces_2/ be a random integer from 1 to 12 inclusive. Let /spaces_2/ be a random integer from 1 to 12 inclusive.
EXAMPLE: For example, 5 and 9. EXAMPLE: For example, 5 and 9.
17. Let /max_1/ be the largest integer not greater than 18. Let /max_1/ be the largest integer not greater than
4,294,967,295 divided by /spaces_1/. 4,294,967,295 divided by /spaces_1/.
Let /max_2/ be the largest integer not greater than Let /max_2/ be the largest integer not greater than
4,294,967,295 divided by /spaces_2/. 4,294,967,295 divided by /spaces_2/.
EXAMPLE: Continuing the example, 858,993,459 and 477,218,588. EXAMPLE: Continuing the example, 858,993,459 and 477,218,588.
18. Let /number_1/ be a random integer from 0 to /max_1/ inclusive. 19. Let /number_1/ be a random integer from 0 to /max_1/ inclusive.
Let /number_2/ be a random integer from 0 to /max_2/ inclusive. Let /number_2/ be a random integer from 0 to /max_2/ inclusive.
EXAMPLE: For example, 777,007,543 and 114,997,259. EXAMPLE: For example, 777,007,543 and 114,997,259.
19. Let /product_1/ be the result of multiplying /number_1/ and 20. Let /product_1/ be the result of multiplying /number_1/ and
/spaces_1/ together. /spaces_1/ together.
Let /product_2/ be the result of multiplying /number_2/ and Let /product_2/ be the result of multiplying /number_2/ and
/spaces_2/ together. /spaces_2/ together.
EXAMPLE: Continuing the example, 3,885,037,715 and EXAMPLE: Continuing the example, 3,885,037,715 and
1,034,975,331. 1,034,975,331.
20. Let /key_1/ be a string consisting of /product_1/, expressed in 21. Let /key_1/ be a string consisting of /product_1/, expressed in
base ten using the numerals in the range U+0030 DIGIT ZERO (0) base ten using the numerals in the range U+0030 DIGIT ZERO (0)
to U+0039 DIGIT NINE (9). to U+0039 DIGIT NINE (9).
Let /key_2/ be a string consisting of /product_2/, expressed in Let /key_2/ be a string consisting of /product_2/, expressed in
base ten using the numerals in the range U+0030 DIGIT ZERO (0) base ten using the numerals in the range U+0030 DIGIT ZERO (0)
to U+0039 DIGIT NINE (9). to U+0039 DIGIT NINE (9).
EXAMPLE: Continuing the example, "3885037715" and "1034975331". EXAMPLE: Continuing the example, "3885037715" and "1034975331".
21. Insert between one and twelve random characters from the ranges 22. Insert between one and twelve random characters from the ranges
U+0021 to U+002F and U+003A to U+007E into /key_1/ at random U+0021 to U+002F and U+003A to U+007E into /key_1/ at random
positions. positions.
Insert between one and twelve random characters from the ranges Insert between one and twelve random characters from the ranges
U+0021 to U+002F and U+003A to U+007E into /key_2/ at random U+0021 to U+002F and U+003A to U+007E into /key_2/ at random
positions. positions.
NOTE: This corresponds to random printable ASCII characters NOTE: This corresponds to random printable ASCII characters
other than the digits and the U+0020 SPACE character. other than the digits and the U+0020 SPACE character.
EXAMPLE: Continuing the example, this could lead to "P388O503D& EXAMPLE: Continuing the example, this could lead to "P388O503D&
ul7{K%gX(%715" and "1N?|kUT0or3o4I97N5-S3O31". ul7{K%gX(%715" and "1N?|kUT0or3o4I97N5-S3O31".
22. Insert /spaces_1/ U+0020 SPACE characters into /key_1/ at random 23. Insert /spaces_1/ U+0020 SPACE characters into /key_1/ at random
positions other than the start or end of the string. positions other than the start or end of the string.
Insert /spaces_2/ U+0020 SPACE characters into /key_2/ at random Insert /spaces_2/ U+0020 SPACE characters into /key_2/ at random
positions other than the start or end of the string. positions other than the start or end of the string.
EXAMPLE: Continuing the example, this could lead to "P388 O503D& EXAMPLE: Continuing the example, this could lead to "P388 O503D&
ul7 {K%gX( %7 15" and "1 N ?|k UT0or 3o 4 I97N 5-S3O 31". ul7 {K%gX( %7 15" and "1 N ?|k UT0or 3o 4 I97N 5-S3O 31".
23. Add the string consisting of the concatenation of the string 24. Add the string consisting of the concatenation of the string
"Sec-WebSocket-Key1:", a U+0020 SPACE character, and the /key_1/ "Sec-WebSocket-Key1:", a U+0020 SPACE character, and the /key_1/
value, to /fields/. value, to /fields/.
Add the string consisting of the concatenation of the string Add the string consisting of the concatenation of the string
"Sec-WebSocket-Key2:", a U+0020 SPACE character, and the /key_2/ "Sec-WebSocket-Key2:", a U+0020 SPACE character, and the /key_2/
value, to /fields/. value, to /fields/.
24. For each string in /fields/, in a random order: send the string, 25. For each string in /fields/, in a random order: send the string,
encoded as UTF-8, followed by a UTF-8-encoded U+000D CARRIAGE encoded as UTF-8, followed by a UTF-8-encoded U+000D CARRIAGE
RETURN U+000A LINE FEED character pair (CRLF). It is important RETURN U+000A LINE FEED character pair (CRLF). It is important
that the fields be output in a random order so that servers not that the fields be output in a random order so that servers not
depend on the particular order used by any particular client. depend on the particular order used by any particular client.
25. Send a UTF-8-encoded U+000D CARRIAGE RETURN U+000A LINE FEED 26. Send a UTF-8-encoded U+000D CARRIAGE RETURN U+000A LINE FEED
character pair (CRLF). character pair (CRLF).
26. Let /key3/ be a string consisting of eight random bytes (or 27. Let /key3/ be a string consisting of eight random bytes (or
equivalently, a random 64 bit integer encoded in big-endian equivalently, a random 64 bit integer encoded in big-endian
order). order).
EXAMPLE: For example, 0x47 0x30 0x22 0x2D 0x5A 0x3F 0x47 0x58. EXAMPLE: For example, 0x47 0x30 0x22 0x2D 0x5A 0x3F 0x47 0x58.
27. Send /key3/ to the server. 28. Send /key3/ to the server.
28. Read bytes from the server until either the connection closes, 29. Read bytes from the server until either the connection closes,
or a 0x0A byte is read. Let /field/ be these bytes, including or a 0x0A byte is read. Let /field/ be these bytes, including
the 0x0A byte. the 0x0A byte.
If /field/ is not at least seven bytes long, or if the last two If /field/ is not at least seven bytes long, or if the last two
bytes aren't 0x0D and 0x0A respectively, or if it does not bytes aren't 0x0D and 0x0A respectively, or if it does not
contain at least two 0x20 bytes, then fail the WebSocket contain at least two 0x20 bytes, then fail the WebSocket
connection and abort these steps. connection and abort these steps.
User agents may apply a timeout to this step, failing the User agents may apply a timeout to this step, failing the
WebSocket connection if the server does not send back data in a WebSocket connection if the server does not send back data in a
suitable time period. suitable time period.
29. Let /code/ be the substring of /field/ that starts from the byte 30. Let /code/ be the substring of /field/ that starts from the byte
after the first 0x20 byte, and ends with the byte before the after the first 0x20 byte, and ends with the byte before the
second 0x20 byte. second 0x20 byte.
30. If /code/ is not three bytes long, or if any of the bytes in 31. If /code/ is not three bytes long, or if any of the bytes in
/code/ are not in the range 0x30 to 0x39, then fail the /code/ are not in the range 0x30 to 0x39, then fail the
WebSocket connection and abort these steps. WebSocket connection and abort these steps.
31. If /code/, interpreted as UTF-8, is "101", then move to the next 32. If /code/, interpreted as UTF-8, is "101", then move to the next
step. step.
If /code/, interpreted as UTF-8, is "407", then either close the If /code/, interpreted as UTF-8, is "407", then either close the
connection and jump back to step 2, providing appropriate connection and jump back to step 2, providing appropriate
authentication information, or fail the WebSocket connection. authentication information, or fail the WebSocket connection.
407 is the code used by HTTP meaning "Proxy Authentication 407 is the code used by HTTP meaning "Proxy Authentication
Required". User agents that support proxy authentication must Required". User agents that support proxy authentication must
interpret the response as defined by HTTP (e.g. to find and interpret the response as defined by HTTP (e.g. to find and
interpret the |Proxy-Authenticate| header). interpret the |Proxy-Authenticate| header).
Otherwise, fail the WebSocket connection and abort these steps. Otherwise, fail the WebSocket connection and abort these steps.
32. Let /fields/ be a list of name-value pairs, initially empty. 33. Let /fields/ be a list of name-value pairs, initially empty.
33. _Field_: Let /name/ and /value/ be empty byte arrays. 34. _Field_: Let /name/ and /value/ be empty byte arrays.
34. Read a byte from the server. 35. Read a byte from the server.
If the connection closes before this byte is received, then fail If the connection closes before this byte is received, then fail
the WebSocket connection and abort these steps. the WebSocket connection and abort these steps.
Otherwise, handle the byte as described in the appropriate entry Otherwise, handle the byte as described in the appropriate entry
below: below:
-> If the byte is 0x0D (ASCII CR) -> If the byte is 0x0D (ASCII CR)
If the /name/ byte array is empty, then jump to the fields If the /name/ byte array is empty, then jump to the fields
processing step. Otherwise, fail the WebSocket connection processing step. Otherwise, fail the WebSocket connection
skipping to change at page 25, line 17 skipping to change at page 32, line 9
the /name/ byte array and redo this step for the next byte. the /name/ byte array and redo this step for the next byte.
-> Otherwise -> Otherwise
Append the byte to the /name/ byte array and redo this step Append the byte to the /name/ byte array and redo this step
for the next byte. for the next byte.
NOTE: This reads a field name, terminated by a colon, converting NOTE: This reads a field name, terminated by a colon, converting
upper-case ASCII letters to lowercase, and aborting if a stray upper-case ASCII letters to lowercase, and aborting if a stray
CR or LF is found. CR or LF is found.
35. Let /count/ equal 0. 36. Let /count/ equal 0.
NOTE: This is used in the next step to skip past a space NOTE: This is used in the next step to skip past a space
character after the colon, if necessary. character after the colon, if necessary.
36. Read a byte from the server and increment /count/ by 1. 37. Read a byte from the server and increment /count/ by 1.
If the connection closes before this byte is received, then fail If the connection closes before this byte is received, then fail
the WebSocket connection and abort these steps. the WebSocket connection and abort these steps.
Otherwise, handle the byte as described in the appropriate entry Otherwise, handle the byte as described in the appropriate entry
below: below:
-> If the byte is 0x20 (ASCII space) and /count/ equals 1 -> If the byte is 0x20 (ASCII space) and /count/ equals 1
Ignore the byte and redo this step for the next byte. Ignore the byte and redo this step for the next byte.
skipping to change at page 25, line 46 skipping to change at page 32, line 38
-> If the byte is 0x0A (ASCII LF) -> If the byte is 0x0A (ASCII LF)
Fail the WebSocket connection and abort these steps. Fail the WebSocket connection and abort these steps.
-> Otherwise -> Otherwise
Append the byte to the /value/ byte array and redo this step Append the byte to the /value/ byte array and redo this step
for the next byte. for the next byte.
NOTE: This reads a field value, terminated by a CRLF, skipping NOTE: This reads a field value, terminated by a CRLF, skipping
past a single space after the colon if there is one. past a single space after the colon if there is one.
37. Read a byte from the server. 38. Read a byte from the server.
If the connection closes before this byte is received, or if the If the connection closes before this byte is received, or if the
byte is not a 0x0A byte (ASCII LF), then fail the WebSocket byte is not a 0x0A byte (ASCII LF), then fail the WebSocket
connection and abort these steps. connection and abort these steps.
NOTE: This skips past the LF byte of the CRLF after the field. NOTE: This skips past the LF byte of the CRLF after the field.
38. Append an entry to the /fields/ list that has the name given by 39. Append an entry to the /fields/ list that has the name given by
the string obtained by interpreting the /name/ byte array as a the string obtained by interpreting the /name/ byte array as a
UTF-8 byte stream and the value given by the string obtained by UTF-8 byte stream and the value given by the string obtained by
interpreting the /value/ byte array as a UTF-8 byte stream. interpreting the /value/ byte array as a UTF-8 byte stream.
39. Return to the "Field" step above. 40. Return to the "Field" step above.
40. _Fields processing_: Read a byte from the server. 41. _Fields processing_: Read a byte from the server.
If the connection closes before this byte is received, or if the If the connection closes before this byte is received, or if the
byte is not a 0x0A byte (ASCII LF), then fail the WebSocket byte is not a 0x0A byte (ASCII LF), then fail the WebSocket
connection and abort these steps. connection and abort these steps.
NOTE: This skips past the LF byte of the CRLF after the blank NOTE: This skips past the LF byte of the CRLF after the blank
line after the fields. line after the fields.
41. If there is not exactly one entry in the /fields/ list whose 42. If there is not exactly one entry in the /fields/ list whose
name is "upgrade", or if there is not exactly one entry in the name is "upgrade", or if there is not exactly one entry in the
/fields/ list whose name is "connection", or if there is not /fields/ list whose name is "connection", or if there is not
exactly one entry in the /fields/ list whose name is "sec- exactly one entry in the /fields/ list whose name is "sec-
websocket-origin", or if there is not exactly one entry in the websocket-origin", or if there is not exactly one entry in the
/fields/ list whose name is "sec-websocket-location", or if the /fields/ list whose name is "sec-websocket-location", or if the
/protocol/ was specified but there is not exactly one entry in /protocol/ was specified but there is not exactly one entry in
the /fields/ list whose name is "sec-websocket-protocol", or if the /fields/ list whose name is "sec-websocket-protocol", or if
there are any entries in the /fields/ list whose names are the there are any entries in the /fields/ list whose names are the
empty string, then fail the WebSocket connection and abort these empty string, then fail the WebSocket connection and abort these
steps. Otherwise, handle each entry in the /fields/ list as steps. Otherwise, handle each entry in the /fields/ list as
skipping to change at page 27, line 27 skipping to change at page 34, line 21
parameters) /resource name/, and the scheme |http| if parameters) /resource name/, and the scheme |http| if
/secure/ is false and |https| if /secure/ is true. [RFC2109] /secure/ is false and |https| if /secure/ is true. [RFC2109]
[RFC2965] [RFC2965]
If the relevant specification is not supported by the user If the relevant specification is not supported by the user
agent, then the field must be ignored. agent, then the field must be ignored.
-> Any other name -> Any other name
Ignore it. Ignore it.
42. Let /challenge/ be the concatenation of /number_1/, expressed as 43. Let /challenge/ be the concatenation of /number_1/, expressed as
a big-endian 32 bit integer, /number_2/, expressed as a big- a big-endian 32 bit integer, /number_2/, expressed as a big-
endian 32 bit integer, and the eight bytes of /key_3/ in the endian 32 bit integer, and the eight bytes of /key_3/ in the
order they were sent on the wire. order they were sent on the wire.
EXAMPLE: Using the examples given earlier, this leads to the 16 EXAMPLE: Using the examples given earlier, this leads to the 16
bytes 0x2E 0x50 0x31 0xB7 0x06 0xDA 0xB8 0x0B 0x47 0x30 0x22 bytes 0x2E 0x50 0x31 0xB7 0x06 0xDA 0xB8 0x0B 0x47 0x30 0x22
0x2D 0x5A 0x3F 0x47 0x58. 0x2D 0x5A 0x3F 0x47 0x58.
43. Let /expected/ be the MD5 fingerprint of /challenge/ as a big- 44. Let /expected/ be the MD5 fingerprint of /challenge/ as a big-
endian 128 bit string. [RFC1321] endian 128 bit string. [RFC1321]
EXAMPLE: Using the examples given earlier, this leads to the 16 EXAMPLE: Using the examples given earlier, this leads to the 16
bytes 0x30 0x73 0x74 0x33 0x52 0x6C 0x26 0x71 0x2D 0x32 0x5A bytes 0x30 0x73 0x74 0x33 0x52 0x6C 0x26 0x71 0x2D 0x32 0x5A
0x55 0x5E 0x77 0x65 0x75. In ASCII, these bytes correspond to 0x55 0x5E 0x77 0x65 0x75. In ASCII, these bytes correspond to
the string "0st3Rl&q-2ZU^weu". the string "0st3Rl&q-2ZU^weu".
44. Read sixteen bytes from the server. Let /reply/ be those bytes. 45. Read sixteen bytes from the server. Let /reply/ be those bytes.
If the connection closes before these bytes are received, then If the connection closes before these bytes are received, then
fail the WebSocket connection and abort these steps. fail the WebSocket connection and abort these steps.
45. If /reply/ does not exactly equal /expected/, then fail the 46. If /reply/ does not exactly equal /expected/, then fail the
WebSocket connection and abort these steps. WebSocket connection and abort these steps.
46. The *WebSocket connection is established*. Now the user agent 47. The *WebSocket connection is established*. Now the user agent
must send and receive to and from the connection as described in must send and receive to and from the connection as described in
the next section. the next section.
4.2. Data framing 5.2. Server-side requirements
Once a WebSocket connection is established, the user agent must run
through the following state machine for the bytes sent by the server.
If at any point during these steps a read is attempted but fails
because the WebSocket connection is closed, then abort.
1. Try to read a byte from the server. Let /frame type/ be that
byte.
2. Let /error/ be false.
3. Handle the /frame type/ byte as follows:
If the high-order bit of the /frame type/ byte is set (i.e. if
/frame type/ _and_ed with 0x80 returns 0x80)
Run these steps:
1. Let /length/ be zero.
2. _Length_: Read a byte, let /b/ be that byte.
3. Let /b_v/ be an integer corresponding to the low 7 bits of
/b/ (the value you would get by _and_ing /b/ with 0x7F).
4. Multiply /length/ by 128, add /b_v/ to that result, and
store the final result in /length/.
5. If the high-order bit of /b/ is set (i.e. if /b/ _and_ed
with 0x80 returns 0x80), then return to the step above
labeled _length_.
6. Read /length/ bytes.
!!! WARNING: It is possible for a server to (innocently
or maliciously) send frames with lengths greater than
2**(31) or 2**(32) bytes, overflowing a signed or unsigned
32bit integer. User agents may therefore impose
implementation-specific limits on the lengths of invalid
frames that they will skip; even supporting frames 2GB in
length is considered, at the time of writing, as going
well above and beyond the call of duty.
7. Discard the read bytes.
8. If the /frame type/ is 0xFF and the /length/ was 0, then
run the following substeps:
1. If the WebSocket closing handshake has not yet
started, then start the WebSocket closing handshake.
2. Wait until either the WebSocket closing handshake has
started or the WebSocket connection is closed.
3. If the WebSocket connection is not already closed,
then close the WebSocket connection: *The WebSocket
closing handshake has finished*. (If the connection
closes before this happens, then the closing handshake
doesn't finish.)
4. Abort these steps. Any data on the connection after
the 0xFF frame is discarded.
Otherwise, let /error/ be true.
If the high-order bit of the /frame type/ byte is _not_ set (i.e.
if /frame type/ _and_ed with 0x80 returns 0x00)
Run these steps:
1. Let /raw data/ be an empty byte array.
2. _Data_: Read a byte, let /b/ be that byte.
3. If /b/ is not 0xFF, then append /b/ to /raw data/ and
return to the previous step (labeled _data_).
4. Interpret /raw data/ as a UTF-8 string, and store that
string in /data/.
5. If /frame type/ is 0x00, then *a WebSocket message has
been received* with text /data/. Otherwise, discard the
data and let /error/ be true.
4. If /error/ is true, then *a WebSocket error has been detected*.
5. Return to the first step to read the next byte.
If the user agent is faced with content that is too large to be
handled appropriately, runs out of resources for buffering incoming
data, or hits an artificial resource limit intended to avoid resource
starvation, then it must fail the WebSocket connection.
Once a WebSocket connection is established, but before the WebSocket
closing handshake has started, the user agent must use the following
steps to *send /data/ using the WebSocket*:
1. Send a 0x00 byte to the server.
2. Encode /data/ using UTF-8 and send the resulting byte stream to
the server.
3. Send a 0xFF byte to the server.
Once the WebSocket closing handshake has started, the user agent must
not send any further data on the connection.
Once a WebSocket connection is established, the user agent must use
the following steps to *start the WebSocket closing handshake*.
These steps must be run asynchronously relative to whatever algorithm
invoked this one.
1. If the WebSocket closing handshake has started, then abort these
steps.
2. Send a 0xFF byte to the server.
3. Send a 0x00 byte to the server.
4. *The WebSocket closing handshake has started*.
5. Wait a user-agent-determined length of time, or until the
WebSocket connection is closed.
6. If the WebSocket connection is not already closed, then close the
WebSocket connection. (If this happens, then the closing
handshake doesn't finish.)
NOTE: The closing handshake finishes once the server returns the 0xFF
packet, as described above.
If at any point there is a fatal problem with sending data to the
server, the user agent must fail the WebSocket connection.
4.3. Handling errors in UTF-8 from the server
When a client is to interpret a byte stream as UTF-8 but finds that
the byte stream is not in fact a valid UTF-8 stream, then any bytes
or sequences of bytes that are not valid UTF-8 sequences must be
interpreted as a U+FFFD REPLACEMENT CHARACTER.
5. Server-side requirements
_This section only applies to servers._ _This section only applies to servers._
5.1. Reading the client's opening handshake 5.2.1. Reading the client's opening handshake
When a client starts a WebSocket connection, it sends its part of the When a client starts a WebSocket connection, it sends its part of the
opening handshake. The server must parse at least part of this opening handshake. The server must parse at least part of this
handshake in order to obtain the necessary information to generate handshake in order to obtain the necessary information to generate
the server part of the handshake. the server part of the handshake.
The client handshake consists of the following parts. If the server, The client handshake consists of the following parts. If the server,
while reading the handshake, finds that the client did not send a while reading the handshake, finds that the client did not send a
handshake that matches the description below, the server should abort handshake that matches the description below, the server should abort
the WebSocket connection. the WebSocket connection.
skipping to change at page 35, line 5 skipping to change at page 38, line 5
Other fields can be used, such as "Cookie", for authentication Other fields can be used, such as "Cookie", for authentication
purposes. Their semantics are equivalent to the semantics of the purposes. Their semantics are equivalent to the semantics of the
HTTP headers with the same names. HTTP headers with the same names.
Unrecognized fields can be safely ignored, and are probably either Unrecognized fields can be safely ignored, and are probably either
the result of intermediaries injecting fields unrelated to the the result of intermediaries injecting fields unrelated to the
operation of the WebSocket protocol, or clients that support future operation of the WebSocket protocol, or clients that support future
versions of the protocol offering options that the server doesn't versions of the protocol offering options that the server doesn't
support. support.
5.2. Sending the server's opening handshake 5.2.2. Sending the server's opening handshake
When a client establishes a WebSocket connection to a server, the When a client establishes a WebSocket connection to a server, the
server must run the following steps. server must run the following steps.
1. If the server supports encryption, perform a TLS handshake over 1. If the server supports encryption, perform a TLS handshake over
the connection. If this fails (e.g. the client indicated a host the connection. If this fails (e.g. the client indicated a host
name in the extended client hello "server_name" extension that name in the extended client hello "server_name" extension that
the server does not host), then close the connection; otherwise, the server does not host), then close the connection; otherwise,
all further communication for the connection (including the all further communication for the connection (including the
server handshake) must run through the encrypted tunnel. server handshake) must run through the encrypted tunnel.
skipping to change at page 39, line 8 skipping to change at page 43, line 5
12. Send two bytes 0x0D 0x0A (ASCII CRLF). 12. Send two bytes 0x0D 0x0A (ASCII CRLF).
13. Send /response/. 13. Send /response/.
This completes the server's handshake. If the server finishes these This completes the server's handshake. If the server finishes these
steps without aborting the WebSocket connection, and if the client steps without aborting the WebSocket connection, and if the client
does not then fail the connection, then the connection is established does not then fail the connection, then the connection is established
and the server may begin and receiving sending data, as described in and the server may begin and receiving sending data, as described in
the next section. the next section.
5.3. Data framing 6. Error Handling
The server must run through the following steps to process the bytes
sent by the client. If at any point during these steps a read is
attempted but fails because the WebSocket connection is closed, then
abort.
1. _Frame_: Read a byte from the client. Let /type/ be that byte.
2. If the most significant bit of /type/ is not set, then run the
following steps:
1. If /type/ is not a 0x00 byte, then the server may abort these
steps and either immediately disconnect from the client or
set the /client terminated/ flag.
2. Let /raw data/ be an empty byte array.
3. _Data_: Read a byte, let /b/ be that byte.
4. If /b/ is not 0xFF, then append /b/ to /raw data/ and return
to the previous step (labeled _data_).
5. If /type/ was 0x00, interpret /raw data/ as a UTF-8 string,
and apply whatever server-specific processing is to occur for
the resulting string (the message from the client).
Otherwise, the most significant bit of /type/ is set. Run the
following steps.
6. If /type/ is not a 0xFF byte, then the server may abort
these steps and either immediately disconnect from the
client or set the /client terminated/ flag.
7. Let /length/ be zero.
8. _Length_: Read a byte, let /b/ be that byte.
9. If /b/ is not a 0x00 byte, then run these substeps:
1. The server may abort these steps and either immediately
disconnect from the client or set the /client
terminated/ flag.
2. Let /b_v/ be an integer corresponding to the low 7 bits
of /b/ (the value you would get by _and_ing /b/ with
0x7F).
3. Multiply /length/ by 128, add /b_v/ to that result, and
store the final result in /length/.
4. If the high-order bit of /b/ is set (i.e. if /b/ _and_ed
with 0x80 returns 0x80), then return to the step above
labeled _length_.
5. Read /length/ bytes.
!!! WARNING: It is possible for a malicious client to
send frames with lengths greater than 2**(31) or 2**(32)
bytes, overflowing a signed or unsigned 32bit integer.
Servers may therefore impose implementation-specific
limits on the lengths of invalid frames that they will
skip, if they support skipping such frames at all. If a
server cannot correctly skip past a long frame, then the
server must abort these steps (discarding all future
data), and should either immediately disconnect from the
client or set the /client terminated/ flag.
6. Discard the read bytes.
10. If /type/ is 0xFF and /length/ is 0, then set the /client
terminated/ flag and abort these steps. All further data
sent by the client should be discarded.
3. Return to the step labeled _frame_.
The server must run through the following steps to send strings to
the client:
1. Send a 0x00 byte to the client to indicate the start of a string.
2. Encode /data/ using UTF-8 and send the resulting byte stream to
the client.
3. Send a 0xFF byte to the client to indicate the end of the
message.
At any time, the server may decide to terminate the WebSocket
connection by running through the following steps:
1. Send a 0xFF byte and a 0x00 byte to the client to indicate the
start of the closing handshake.
2. Wait until the /client terminated/ flag has been set, or until a
server-defined timeout expires.
3. Close the WebSocket connection. 6.1. Handling errors in UTF-8 from the server
Once these steps have started, the server must not send any further When a client is to interpret a byte stream as UTF-8 but finds that
data to the server. The 0xFF 0x00 bytes indicate the end of the the byte stream is not in fact a valid UTF-8 stream, then any bytes
server's data, and further bytes will be discarded by the client. or sequences of bytes that are not valid UTF-8 sequences must be
interpreted as a U+FFFD REPLACEMENT CHARACTER.
5.4. Handling errors in UTF-8 from the client 6.2. Handling errors in UTF-8 from the client
When a server is to interpret a byte stream as UTF-8 but finds that When a server is to interpret a byte stream as UTF-8 but finds that
the byte stream is not in fact a valid UTF-8 stream, behavior is the byte stream is not in fact a valid UTF-8 stream, behavior is
undefined. A server could close the connection, convert invalid byte undefined. A server could close the connection, convert invalid byte
sequences to U+FFFD REPLACEMENT CHARACTERs, store the data verbatim, sequences to U+FFFD REPLACEMENT CHARACTERs, store the data verbatim,
or perform application-specific processing. Subprotocols layered on or perform application-specific processing. Subprotocols layered on
the WebSocket protocol might define specific behavior for servers. the WebSocket protocol might define specific behavior for servers.
6. Closing the connection 7. Closing the connection
6.1. Client-initiated closure 7.1. Client-initiated closure
Certain algorithms require the user agent to *fail the WebSocket Certain algorithms require the user agent to *fail the WebSocket
connection*. To do so, the user agent must close the WebSocket connection*. To do so, the user agent must close the WebSocket
connection, and may report the problem to the user (which would be connection, and may report the problem to the user (which would be
especially useful for developers). especially useful for developers).
Except as indicated above or as specified by the application layer Except as indicated above or as specified by the application layer
(e.g. a script using the WebSocket API), user agents should not close (e.g. a script using the WebSocket API), user agents should not close
the connection. the connection.
skipping to change at page 42, line 39 skipping to change at page 44, line 39
it was not a WebSocket server). it was not a WebSocket server).
o A WebSocket server that sent a correct opening handshake, but that o A WebSocket server that sent a correct opening handshake, but that
specified options that caused the client to drop the connection specified options that caused the client to drop the connection
(e.g. the server specified an origin that differed from the (e.g. the server specified an origin that differed from the
script's). script's).
o A WebSocket server that abruptly closed the connection after o A WebSocket server that abruptly closed the connection after
successfully completing the opening handshake. successfully completing the opening handshake.
6.2. Server-initiated closure 7.2. Server-initiated closure
Certain algorithms require or recommend that the server *abort the Certain algorithms require or recommend that the server *abort the
WebSocket connection* during the opening handshake. To do so, the WebSocket connection* during the opening handshake. To do so, the
server must simply close the WebSocket connection. server must simply close the WebSocket connection.
6.3. Closure 7.3. Closure
To *close the WebSocket connection*, the user agent or server must To *close the WebSocket connection*, the user agent or server must
close the TCP connection, using whatever mechanism possible (e.g. close the TCP connection, using whatever mechanism possible (e.g.
either the TCP RST or FIN mechanisms). When a user agent notices either the TCP RST or FIN mechanisms). When a user agent notices
that the server has closed its connection, it must immediately close that the server has closed its connection, it must immediately close
its side of the connection also. Whether the user agent or the its side of the connection also. Whether the user agent or the
server closes the connection first, it is said that the *WebSocket server closes the connection first, it is said that the *WebSocket
connection is closed*. If the connection was closed after the client connection is closed*. If the connection was closed after the client
finished the WebSocket closing handshake, then the WebSocket finished the WebSocket closing handshake, then the WebSocket
connection is said to have been closed _cleanly_. connection is said to have been closed _cleanly_.
Servers may close the WebSocket connection whenever desired. User Servers may close the WebSocket connection whenever desired. User
agents should not close the WebSocket connection arbitrarily. agents should not close the WebSocket connection arbitrarily.
7. Security considerations 8. Security considerations
While this protocol is intended to be used by scripts in Web pages, While this protocol is intended to be used by scripts in Web pages,
it can also be used directly by hosts. Such hosts are acting on it can also be used directly by hosts. Such hosts are acting on
their own behalf, and can therefore send fake "Origin" fields, their own behalf, and can therefore send fake "Origin" fields,
misleading the server. Servers should therefore be careful about misleading the server. Servers should therefore be careful about
assuming that they are talking directly to scripts from known assuming that they are talking directly to scripts from known
origins, and must consider that they might be accessed in unexpected origins, and must consider that they might be accessed in unexpected
ways. In particular, a server should not trust that any input is ways. In particular, a server should not trust that any input is
valid. valid.
skipping to change at page 45, line 5 skipping to change at page 47, line 5
does not correspond to the values the server is expecting (e.g. does not correspond to the values the server is expecting (e.g.
incorrect path or origin), the server should just disconnect. It is incorrect path or origin), the server should just disconnect. It is
always safe to disconnect. always safe to disconnect.
The biggest security risk when sending text data using this protocol The biggest security risk when sending text data using this protocol
is sending data using the wrong encoding. If an attacker can trick is sending data using the wrong encoding. If an attacker can trick
the server into sending data encoded as ISO-8859-1 verbatim (for the server into sending data encoded as ISO-8859-1 verbatim (for
instance), rather than encoded as UTF-8, then the attacker could instance), rather than encoded as UTF-8, then the attacker could
inject arbitrary frames into the data stream. inject arbitrary frames into the data stream.
8. IANA considerations 9. IANA considerations
8.1. Registration of ws: scheme 9.1. Registration of ws: scheme
A |ws:| URL identifies a WebSocket server and resource name. A |ws:| URL identifies a WebSocket server and resource name.
URI scheme name. URI scheme name.
ws ws
Status. Status.
Permanent. Permanent.
URI scheme syntax. URI scheme syntax.
skipping to change at page 46, line 17 skipping to change at page 48, line 17
Contact. Contact.
Ian Hickson <ian@hixie.ch> Ian Hickson <ian@hixie.ch>
Author/Change controller. Author/Change controller.
Ian Hickson <ian@hixie.ch> Ian Hickson <ian@hixie.ch>
References. References.
This document. This document.
8.2. Registration of wss: scheme 9.2. Registration of wss: scheme
A |wss:| URL identifies a WebSocket server and resource name, and A |wss:| URL identifies a WebSocket server and resource name, and
indicates that traffic over that connection is to be encrypted. indicates that traffic over that connection is to be encrypted.
URI scheme name. URI scheme name.
wss wss
Status. Status.
Permanent. Permanent.
skipping to change at page 47, line 24 skipping to change at page 49, line 24
Contact. Contact.
Ian Hickson <ian@hixie.ch> Ian Hickson <ian@hixie.ch>
Author/Change controller. Author/Change controller.
Ian Hickson <ian@hixie.ch> Ian Hickson <ian@hixie.ch>
References. References.
This document. This document.
8.3. Registration of the "WebSocket" HTTP Upgrade keyword 9.3. Registration of the "WebSocket" HTTP Upgrade keyword
Name of token. Name of token.
WebSocket WebSocket
Author/Change controller. Author/Change controller.
Ian Hickson <ian@hixie.ch> Ian Hickson <ian@hixie.ch>
Contact. Contact.
Ian Hickson <ian@hixie.ch> Ian Hickson <ian@hixie.ch>
References. References.
This document. This document.
8.4. Sec-WebSocket-Key1 and Sec-WebSocket-Key2 9.4. Sec-WebSocket-Key1 and Sec-WebSocket-Key2
This section describes two header fields for registration in the This section describes two header fields for registration in the
Permanent Message Header Field Registry. [RFC3864] Permanent Message Header Field Registry. [RFC3864]
Header field name Header field name
Sec-WebSocket-Key1 Sec-WebSocket-Key1
Applicable protocol Applicable protocol
http http
skipping to change at page 48, line 43 skipping to change at page 50, line 43
None. None.
The |Sec-WebSocket-Key1| and |Sec-WebSocket-Key2| headers are used in The |Sec-WebSocket-Key1| and |Sec-WebSocket-Key2| headers are used in
the WebSocket handshake. They are sent from the client to the server the WebSocket handshake. They are sent from the client to the server
to provide part of the information used by the server to prove that to provide part of the information used by the server to prove that
it received a valid WebSocket handshake. This helps ensure that the it received a valid WebSocket handshake. This helps ensure that the
server does not accept connections from non-Web-Socket clients (e.g. server does not accept connections from non-Web-Socket clients (e.g.
HTTP clients) that are being abused to send data to unsuspecting HTTP clients) that are being abused to send data to unsuspecting
WebSocket servers. WebSocket servers.
8.5. Sec-WebSocket-Location 9.5. Sec-WebSocket-Location
This section describes a header field for registration in the This section describes a header field for registration in the
Permanent Message Header Field Registry. [RFC3864] Permanent Message Header Field Registry. [RFC3864]
Header field name Header field name
Sec-WebSocket-Location Sec-WebSocket-Location
Applicable protocol Applicable protocol
http http
skipping to change at page 49, line 27 skipping to change at page 51, line 27
Related information Related information
None. None.
The |Sec-WebSocket-Location| header is used in the WebSocket The |Sec-WebSocket-Location| header is used in the WebSocket
handshake. It is sent from the server to the client to confirm the handshake. It is sent from the server to the client to confirm the
URL of the connection. This enables the client to verify that the URL of the connection. This enables the client to verify that the
connection was established to the right server, port, and path, connection was established to the right server, port, and path,
instead of relying on the server to verify that the requested host, instead of relying on the server to verify that the requested host,
port, and path are correct. port, and path are correct.
8.6. Sec-WebSocket-Origin 9.6. Sec-WebSocket-Origin
This section describes a header field for registration in the This section describes a header field for registration in the
Permanent Message Header Field Registry. [RFC3864] Permanent Message Header Field Registry. [RFC3864]
Header field name Header field name
Sec-WebSocket-Origin Sec-WebSocket-Origin
Applicable protocol Applicable protocol
http http
skipping to change at page 50, line 7 skipping to change at page 52, line 7
Related information Related information
None. None.
The |Sec-WebSocket-Origin| header is used in the WebSocket handshake. The |Sec-WebSocket-Origin| header is used in the WebSocket handshake.
It is sent from the server to the client to confirm the origin of the It is sent from the server to the client to confirm the origin of the
script that opened the connection. This enables user agents to script that opened the connection. This enables user agents to
verify that the server is willing to serve the script that opened the verify that the server is willing to serve the script that opened the
connection. connection.
8.7. Sec-WebSocket-Protocol 9.7. Sec-WebSocket-Protocol
This section describes a header field for registration in the This section describes a header field for registration in the
Permanent Message Header Field Registry. [RFC3864] Permanent Message Header Field Registry. [RFC3864]
Header field name Header field name
Sec-WebSocket-Protocol Sec-WebSocket-Protocol
Applicable protocol Applicable protocol
http http
skipping to change at page 51, line 5 skipping to change at page 53, line 5
Related information Related information
None. None.
The |Sec-WebSocket-Protocol| header is used in the WebSocket The |Sec-WebSocket-Protocol| header is used in the WebSocket
handshake. It is sent from the client to the server and back from handshake. It is sent from the client to the server and back from
the server to the client to confirm the subprotocol of the the server to the client to confirm the subprotocol of the
connection. This enables scripts to both select a subprotocol and be connection. This enables scripts to both select a subprotocol and be
sure that the server agreed to serve that subprotocol. sure that the server agreed to serve that subprotocol.
9. Using the WebSocket protocol from other specifications 10. Using the WebSocket protocol from other specifications
The WebSocket protocol is intended to be used by another The WebSocket protocol is intended to be used by another
specification to provide a generic mechanism for dynamic author- specification to provide a generic mechanism for dynamic author-
defined content, e.g. in a specification defining a scripted API. defined content, e.g. in a specification defining a scripted API.
Such a specification first needs to "establish a WebSocket Such a specification first needs to "establish a WebSocket
connection", providing that algorithm with: connection", providing that algorithm with:
o The destination, consisting of a /host/ and a /port/. o The destination, consisting of a /host/ and a /port/.
skipping to change at page 52, line 5 skipping to change at page 54, line 5
When the connection is closed, for any reason including failure to When the connection is closed, for any reason including failure to
establish the connection in the first place, it is said that the establish the connection in the first place, it is said that the
"WebSocket connection is closed". "WebSocket connection is closed".
While a connection is open, the specification will need to handle the While a connection is open, the specification will need to handle the
cases when "a WebSocket message has been received" with text /data/. cases when "a WebSocket message has been received" with text /data/.
To send some text /data/ to an open connection, the specification To send some text /data/ to an open connection, the specification
needs to "send /data/ using the WebSocket". needs to "send /data/ using the WebSocket".
10. Acknowledgements 11. Acknowledgements
The WebSocket protocol is the result of many years of development, Special thanks are due to Ian Hickson, who was the original author
and as such hundreds of people have contributed to the specification and editor of this protocol. The initial design of this
during its lifetime. Unfortunately, since the specification started specification benefitted from the participation of many people in the
as nothing but a minor section of the larger WHATWG Web Applications WHATWG and WHATWG mailing list. Contributions to that specification
1.0 specification, and later the HTML5 specification, no record was are not tracked by section, but a list of all who contributed to that
kept of who exactly contributed to what ended up becoming this specification is given in the WHATWG HTML specification. [HTML]
specification as opposed to who contributed to other parts of that
document.
The reader is therefore referred to the Acknowledgements section of Special thanks also to John Tamplin for providing a significant
the WHATWG HTML specification for a full list of all contributions amount of text for the Data Framing section of this specification.
that have been made to the source document from which this
specification is generated. [HTML]
11. Normative References 12. Normative References
[HTML] Hickson, I., "HTML", May 2010, <http://whatwg.org/html5>. [HTML] Hickson, I., "HTML", August 2010,
<http://whatwg.org/html5>.
[ORIGIN] Barth, A., Jackson, C., and I. Hickson, "The HTTP Origin [ORIGIN] Barth, A., Jackson, C., and I. Hickson, "The HTTP Origin
Header", September 2009, Header", draft-abarth-origin (work in progress),
September 2009,
<http://tools.ietf.org/html/draft-abarth-origin>. <http://tools.ietf.org/html/draft-abarth-origin>.
[RFC1321] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, [RFC1321] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321,
April 1992. April 1992.
[RFC2109] Kristol, D. and L. Montulli, "HTTP State Management [RFC2109] Kristol, D. and L. Montulli, "HTTP State Management
Mechanism", RFC 2109, February 1997. Mechanism", RFC 2109, February 1997.
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
Requirement Levels", BCP 14, RFC 2119, March 1997. Requirement Levels", BCP 14, RFC 2119, March 1997.
skipping to change at page 54, line 12 skipping to change at page 56, line 14
and T. Wright, "Transport Layer Security (TLS) and T. Wright, "Transport Layer Security (TLS)
Extensions", RFC 4366, April 2006. Extensions", RFC 4366, April 2006.
[RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax
Specifications: ABNF", STD 68, RFC 5234, January 2008. Specifications: ABNF", STD 68, RFC 5234, January 2008.
[WEBADDRESSES] [WEBADDRESSES]
Connolly, D. and C. Sperberg-McQueen, "Web addresses in Connolly, D. and C. Sperberg-McQueen, "Web addresses in
HTML 5", May 2009, <http://www.w3.org/html/wg/href/draft>. HTML 5", May 2009, <http://www.w3.org/html/wg/href/draft>.
[WSAPI] Hickson, I., "The Web Sockets API", May 2010, [WSAPI] Hickson, I., "The Web Sockets API", August 2010,
<http://dev.w3.org/html5/websockets/>. <http://dev.w3.org/html5/websockets/>.
Author's Address Author's Address
Ian Hickson Ian Fette
Google, Inc. Google, Inc.
Email: ian@hixie.ch Email: ifette+ietf@google.com
URI: http://ln.hixie.ch/ URI: http://www.ianfette.com/
 End of changes. 105 change blocks. 
460 lines changed or deleted 469 lines changed or added

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