<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
<!-- generated by https://github.com/cabo/kramdown-rfc2629 version 1.2.7 -->
<?rfc toc="yes"?>
<?rfc tocindent="yes"?>
<?rfc sortrefs="yes"?>
<?rfc symrefs="yes"?>
<?rfc strict="yes"?>
<?rfc compact="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc-ext html-pretty-print="prettyprint https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"?>
<rfc xmlns:x="http://purl.org/net/xml2rfc/ext"
     category="std"
     docName="draft-ietf-httpbis-h2-websockets-07"
     ipr="trust200902"
     submissionType="IETF"
     updates="6455">
   <x:feedback template="mailto:ietf-http-wg@w3.org?subject={docname},%20%22{section}%22\&amp;amp;body=%3c{ref}%3e:"/>
   <front>
      <title abbrev="H2 Websockets">Bootstrapping WebSockets with HTTP/2</title>
      <author fullname="Patrick McManus" initials="P." surname="McManus">
         <organization>Mozilla</organization>
         <address>
            <email>mcmanus@ducksong.com</email>
         </address>
      </author>
      <date year="2018" month="June" day="18"/>
      <area>Applications and Real-Time</area>
      <workgroup>HTTP</workgroup>
      <keyword>Internet-Draft</keyword>
      <abstract>
         <t>This document defines a mechanism for running the WebSocket Protocol (RFC 6455) over a single stream of an HTTP/2 connection.</t>
      </abstract>
   </front>
   <middle>
      <section anchor="introduction" title="Introduction">
         <t>The Hypertext Transfer Protocol (HTTP) <xref target="RFC7230"/> provides compatible resource-level semantics across different versions but it does not offer compatibility at the connection management level. Other protocols, such as WebSockets, that rely on connection management details of HTTP must be updated for new versions of HTTP.</t>
         <t>The WebSocket Protocol <xref target="RFC6455"/> uses the HTTP/1.1 Upgrade mechanism (<xref target="RFC7230" x:fmt="of" x:sec="6.7"/>) to transition a TCP connection from HTTP into a WebSocket connection. A different approach must be taken with HTTP/2 <xref target="RFC7540"/>. HTTP/2 does not allow connection-wide header fields and status codes such as the Upgrade and Connection request header fields or the 101 (Switching Protocols) response code due to its multiplexing nature. These are all required by the <xref target="RFC6455"/> opening handshake.</t>
         <t>Being able to bootstrap WebSockets from HTTP/2 allows one TCP connection to be shared by both protocols and extends HTTP/2’s more efficient use of the network to WebSockets.</t>
         <t>This document extends the HTTP CONNECT method (as specified for HTTP/2 in <xref target="RFC7540" x:fmt="of" x:sec="8.3"/>). The extension allows the substitution of a new protocol name to connect to rather than the external host normally used by CONNECT. The result is a tunnel on a single HTTP/2 stream that can carry data for WebSockets (or any other protocol). The other streams on the connection may carry more extended CONNECT tunnels, traditional HTTP/2 data, or a mixture of both.</t>
         <t>This tunneled stream will be multiplexed with other regular streams on the connection and enjoys the normal priority, cancellation, and flow control features of HTTP/2.</t>
         <t>Streams that successfully establish a WebSocket connection using a tunneled stream and the modifications to the opening handshake defined in this document then use the traditional WebSocket Protocol, treating the stream as if were the TCP connection in that specification.</t>
      </section>
      <section anchor="terminology" title="Terminology">
         <t>The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in BCP 14 <xref target="RFC2119"/>
            <xref target="RFC8174"/> when, and only when, they appear in all capitals, as shown here.</t>
      </section>
      <section anchor="the-settingsenableconnectprotocol-settings-parameter"
               title="The SETTINGS_ENABLE_CONNECT_PROTOCOL SETTINGS Parameter">
         <t>This document adds a new SETTINGS Parameter to those defined by <xref target="RFC7540" x:fmt="," x:sec="6.5.2"/>.</t>
         <t>The new parameter name is SETTINGS_ENABLE_CONNECT_PROTOCOL. The value of the parameter MUST be 0 or 1.</t>
         <t>Upon receipt of SETTINGS_ENABLE_CONNECT_PROTOCOL with a value of 1, a client MAY use the Extended CONNECT definition of this document when creating new streams. Receipt of this parameter by a server does not have any impact.</t>
         <t>A sender MUST NOT send a SETTINGS_ENABLE_CONNECT_PROTOCOL parameter with the value of 0 after previously sending a value of 1.</t>
         <t>The use of a SETTINGS Parameter to opt-in to an otherwise incompatible protocol change is a use of “Extending HTTP/2” defined by <xref target="RFC7540" x:fmt="of" x:sec="5.5"/>. Specifically, the addition a new pseudo-header field “:protocol” and the change in meaning of the “:authority” pseudo-header field in <xref target="method"/> require opt-in negotiation. If a client were to use the provisions of the extended CONNECT method defined in this document without first receiving a SETTINGS_ENABLE_CONNECT_PROTOCOL parameter, a non-supporting peer would detect a malformed request and generate a stream error (<xref target="RFC7540" x:fmt="of" x:sec="8.1.2.6"/>).</t>
      </section>
      <section anchor="method" title="The Extended CONNECT Method">
         <t>Usage of the CONNECT method in HTTP/2 is defined by <xref target="RFC7540" x:fmt="of" x:sec="8.3"/>. This extension modifies the method in the following ways:</t>
         <t>
            <list style="symbols">
               <t>A new pseudo-header field :protocol MAY be included on request HEADERS indicating the desired protocol to be spoken on the tunnel created by CONNECT. The pseudo-header field is single valued and contains a value from the HTTP Upgrade Token Registry located at https://www.iana.org/assignments/http-upgrade-tokens/http-upgrade-tokens.xhtml</t>
               <t>On requests that contain the :protocol pseudo-header field, the :scheme and :path pseudo-header fields of the target URI (See <xref target="usingExtended"/>) MUST also be included.</t>
               <t>On requests bearing the :protocol pseudo-header field, the :authority pseudo-header field is interpreted according to <xref target="RFC7540" x:fmt="of" x:sec="8.1.2.3"/> instead of <xref target="RFC7540" x:fmt="of" x:sec="8.3"/>. In particular, the server MUST NOT create a tunnel to the host indicated by the :authority as it would with a CONNECT method request that was not modified by this extension.</t>
            </list>
         </t>
         <t>Upon receiving a CONNECT request bearing the :protocol pseudo-header field the server establishes a tunnel to another service of the protocol type indicated by the pseudo-header field. This service may or may not be co-located with the server.</t>
      </section>
      <section anchor="usingExtended"
               title="Using Extended CONNECT To Bootstrap the WebSocket Protocol">
         <t>The :protocol pseudo-header field MUST be included in the CONNECT request and it MUST have a value of <spanx style="verb">websocket</spanx> to initiate a WebSocket connection on an HTTP/2 stream. Other HTTP request and response header fields, such as those for manipulating cookies, may be included in the HEADERS with the CONNECT method as usual. This request replaces the GET-based request in <xref target="RFC6455"/> and is used to process the WebSockets opening handshake.</t>
         <t>The scheme of the target URI (<xref target="RFC7230" x:fmt="of" x:sec="5.1"/>) MUST be <spanx style="verb">https</spanx> for <spanx style="verb">wss</spanx> schemed WebSockets and <spanx style="verb">http</spanx> for <spanx style="verb">ws</spanx> schemed WebSockets. The remainder of the Target URI is the same as the websocket URI. The websocket URI is still used for proxy autoconfiguration. The security requirements for the HTTP/2 connection used by this specification are established by <xref target="RFC7540"/> for https requests and <xref target="RFC8164"/> for http requests.</t>
         <t>
            <xref target="RFC6455"/> requires the use of Connection and Upgrade header fields that are not part of HTTP/2. They MUST NOT be included in the CONNECT request defined here.</t>
         <t>
            <xref target="RFC6455"/> requires the use of a Host header field which is also not part of HTTP/2. The Host information is conveyed as part of the :authority pseudo-header field which is required on every HTTP/2 transaction.</t>
         <t>Implementations using this extended CONNECT to bootstrap WebSockets do not do the processing of the <xref target="RFC6455"/> Sec-WebSocket-Key and Sec-WebSocket-Accept header fields as that functionality has been superseded by the :protocol pseudo-header field.</t>
         <t>The Origin <xref target="RFC6454"/>, Sec-WebSocket-Version, Sec-WebSocket-Protocol, and Sec-WebSocket-Extensions header fields are used in the CONNECT request and response header fields in the same way as defined in <xref target="RFC6455"/>. Note that HTTP/1 header field names were case-insensitive and HTTP/2 requires they be encoded as lower case.</t>
         <t>After successfully processing the opening handshake, the peers should proceed with the WebSocket Protocol <xref target="RFC6455"/> using the HTTP/2 stream from the CONNECT transaction as if it were the TCP connection referred to in <xref target="RFC6455"/>. The state of the WebSocket connection at this point is OPEN as defined by <xref target="RFC6455" x:fmt="," x:sec="4.1"/>.</t>
         <t>The HTTP/2 stream closure is also analogous to the TCP connection closure of <xref target="RFC6455"/>. Orderly TCP level closures are represented as END_STREAM (<xref target="RFC7540" x:fmt="," x:sec="6.1"/>) flags and RST exceptions are represented with the RST_STREAM (<xref target="RFC7540" x:fmt="," x:sec="6.4"/>) frame with the CANCEL (<xref target="RFC7540" x:fmt="," x:sec="7"/>) error code.</t>
         <section anchor="example" title="Example">
            <figure>
               <artwork type="example">
[[ From Client ]]                       [[ From Server ]]

                                        SETTINGS
                                        SETTINGS_ENABLE_CONNECT_[..] = 1

HEADERS + END_HEADERS
:method = CONNECT
:protocol = websocket
:scheme = https
:path = /chat
:authority = server.example.com
sec-websocket-protocol = chat, superchat
sec-websocket-extensions = permessage-deflate
sec-websocket-version = 13
origin = http://www.example.com

                                        HEADERS + END_HEADERS
                                        :status = 200
                                        sec-websocket-protocol = chat

DATA
WebSocket Data

                                        DATA + END_STREAM
                                        WebSocket Data

DATA + END_STREAM
WebSocket Data
</artwork>
            </figure>
         </section>
      </section>
      <section anchor="design-considerations" title="Design Considerations">
         <t>A more native integration with HTTP/2 is certainly possible with larger additions to HTTP/2. This design was selected to minimize the solution complexity while still addressing the primary concern of running HTTP/2 and WebSockets concurrently.</t>
      </section>
      <section anchor="about-intermediaries" title="About Intermediaries">
         <t>This document does not change how WebSockets interacts with HTTP forward proxies. If a client wishing to speak WebSockets connects via HTTP/2 to an HTTP proxy it should continue to use a traditional (i.e. not with a :protocol pseudo-header field) CONNECT to tunnel through that proxy to the WebSocket server via HTTP.</t>
         <t>The resulting version of HTTP on that tunnel determines whether WebSockets is initiated directly or via a modified CONNECT request described in this document.</t>
      </section>
      <section anchor="security-considerations" title="Security Considerations">
         <t>
            <xref target="RFC6455"/> ensures that non-WebSockets clients, especially XMLHttpRequest based clients, cannot make a WebSocket connection. Its primary mechanism for doing that is the use of Sec- prefixed request header fields that cannot be created by XMLHttpRequest-based clients. This specification addresses that concern in two ways:</t>
         <t>
            <list style="symbols">
               <t>XMLHttpRequest also prohibits use of the CONNECT method in addition to Sec- prefixed request header fields.</t>
               <t>The use of a pseudo-header field is something that is connection specific and HTTP/2 does not ever allow to be created outside of the protocol stack.</t>
            </list>
         </t>
         <t>The security considerations of <xref target="RFC6455"/> section 10 continue to apply to the use of the WebSocket Protocol when using this specification with the exception of 10.8. That section is not relevant because it is specific to the boostrapping handshake that is changed in this document.</t>
      </section>
      <section anchor="iana-considerations" title="IANA Considerations">
         <t>This document establishes an entry for the HTTP/2 Settings Registry that was established by <xref target="RFC7540" x:fmt="of" x:sec="11.3"/>.</t>
         <t>Name: SETTINGS_ENABLE_CONNECT_PROTOCOL</t>
         <t>Code: 0x8</t>
         <t>Initial Value: 0</t>
         <t>Specification: This document</t>
      </section>
   </middle>
   <back>
      <references title="Normative References">
         <reference anchor="RFC7230">
            <front>
               <title>Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing</title>
               <author fullname="R. Fielding"
                       initials="R."
                       role="editor"
                       surname="Fielding"/>
               <author fullname="J. Reschke"
                       initials="J."
                       role="editor"
                       surname="Reschke"/>
               <date month="June" year="2014"/>
            </front>
            <seriesInfo name="RFC" value="7230"/>
            <seriesInfo name="DOI" value="10.17487/RFC7230"/>
         </reference>
         <reference anchor="RFC6455">
            <front>
               <title>The WebSocket Protocol</title>
               <author fullname="I. Fette" initials="I." surname="Fette"/>
               <author fullname="A. Melnikov" initials="A." surname="Melnikov"/>
               <date month="December" year="2011"/>
            </front>
            <seriesInfo name="RFC" value="6455"/>
            <seriesInfo name="DOI" value="10.17487/RFC6455"/>
         </reference>
         <reference anchor="RFC7540">
            <front>
               <title>Hypertext Transfer Protocol Version 2 (HTTP/2)</title>
               <author fullname="M. Belshe" initials="M." surname="Belshe"/>
               <author fullname="R. Peon" initials="R." surname="Peon"/>
               <author fullname="M. Thomson"
                       initials="M."
                       role="editor"
                       surname="Thomson"/>
               <date month="May" year="2015"/>
            </front>
            <seriesInfo name="RFC" value="7540"/>
            <seriesInfo name="DOI" value="10.17487/RFC7540"/>
         </reference>
         <reference anchor="RFC2119">
            <front>
               <title>Key words for use in RFCs to Indicate Requirement Levels</title>
               <author fullname="S. Bradner" initials="S." surname="Bradner"/>
               <date month="March" year="1997"/>
            </front>
            <seriesInfo name="BCP" value="14"/>
            <seriesInfo name="RFC" value="2119"/>
            <seriesInfo name="DOI" value="10.17487/RFC2119"/>
         </reference>
         <reference anchor="RFC8174">
            <front>
               <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
               <author fullname="B. Leiba" initials="B." surname="Leiba"/>
               <date month="May" year="2017"/>
            </front>
            <seriesInfo name="BCP" value="14"/>
            <seriesInfo name="RFC" value="8174"/>
            <seriesInfo name="DOI" value="10.17487/RFC8174"/>
         </reference>
         <reference anchor="RFC8164">
            <front>
               <title>Opportunistic Security for HTTP/2</title>
               <author fullname="M. Nottingham" initials="M." surname="Nottingham"/>
               <author fullname="M. Thomson" initials="M." surname="Thomson"/>
               <date month="May" year="2017"/>
            </front>
            <seriesInfo name="RFC" value="8164"/>
            <seriesInfo name="DOI" value="10.17487/RFC8164"/>
         </reference>
         <reference anchor="RFC6454">
            <front>
               <title>The Web Origin Concept</title>
               <author fullname="A. Barth" initials="A." surname="Barth"/>
               <date month="December" year="2011"/>
            </front>
            <seriesInfo name="RFC" value="6454"/>
            <seriesInfo name="DOI" value="10.17487/RFC6454"/>
         </reference>
      </references>
      <section anchor="acknowledgments" numbered="false" title="Acknowledgments">
         <t>The 2017 HTTP Workshop had a very productive discussion that helped determine the key problem and acceptable level of solution complexity.</t>
      </section>
   </back>
</rfc>
