<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc [
<!ENTITY RFC2119 SYSTEM "http://www.rfc-editor.org/refs/bibxml/reference.RFC.2119.xml">
<!ENTITY RFC4234 SYSTEM "http://www.rfc-editor.org/refs/bibxml/reference.RFC.4234.xml">
<!ENTITY RFC7230 SYSTEM "http://www.rfc-editor.org/refs/bibxml/reference.RFC.7230.xml">
<!ENTITY RFC7233 SYSTEM "http://www.rfc-editor.org/refs/bibxml/reference.RFC.7233.xml">

<!-- Fudge for XMLmind which doesn't have this built in -->
<!ENTITY nbsp    "&#160;">
]>

<!-- Extra statement used by XSLT processors to control the output style. -->
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>

<!-- Processing Instructions can be placed here but if you are editing 
     with XMLmind (and maybe other XML editors) they are better placed
     after the rfc element start tag as shown below. -->
     
<rfc
    category="exp"
    ipr="trust200902"
    docName="draft-ietf-httpbis-rand-access-live-02" >

    <!-- Processing Instructions- PIs (for a complete list and description,
          see file http://xml.resource.org/authoring/README.html and below... -->

    <!-- Some of the more generally applicable PIs that most I-Ds might want to use -->
    
    <!-- Try to enforce the ID-nits conventions and DTD validity -->
    <?rfc strict="yes" ?>

    <!-- Items used when reviewing the document -->
    <?rfc comments="no" ?>  <!-- Controls display of <cref> elements -->
    <?rfc inline="no" ?>    <!-- When no, put comments at end in comments section,
                                 otherwise, put inline -->
    <?rfc editing="no" ?>   <!-- When yes, insert editing marks: editing marks consist of a 
                                 string such as <29> printed in the blank line at the 
                                 beginning of each paragraph of text. -->

    <!-- Create Table of Contents (ToC) and set some options for it.  
         Note the ToC may be omitted for very short documents,but idnits insists on a ToC 
         if the document has more than 15 pages. --> 
   <?rfc toc="yes"?>
   <?rfc tocompact="yes"?> <!-- If "yes" eliminates blank lines before main section entries. -->
   <?rfc tocdepth="4"?>    <!-- Sets the number of levels of sections/subsections... in ToC --> 

    <!-- Choose the options for the references. 
         Some like symbolic tags in the references (and citations) and others prefer 
         numbers. The RFC Editor always uses symbolic tags.
         The tags used are the anchor attributes of the references. --> 
    <?rfc symrefs="yes"?>
    <?rfc sortrefs="yes" ?> <!-- If "yes", causes the references to be sorted in order of tags.
                                 This doesn't have any effect unless symrefs is "yes" also. -->

    <!-- These two save paper: Just setting compact to "yes" makes savings by not starting each 
         main section on a new page but does not omit the blank lines between list items. 
         If subcompact is also "yes" the blank lines between list items are also omitted. -->
    <?rfc compact="yes" ?>
    <?rfc subcompact="no" ?>
    <!-- end of list of popular I-D processing instructions -->

    <!-- ***** FRONT MATTER ***** -->
<feedback xmlns='http://purl.org/net/xml2rfc/ext' template="mailto:ietf-http-wg@w3.org?subject={docname},%20%22{section}%22&amp;body=%3c{ref}%3e:"/><front>
    <!-- The abbreviated title is used in the page header - it is only necessary if the 
         full title is longer than 42 characters -->
    <title abbrev="http-rand-access-live">HTTP Random Access and Live Content</title>

    <author
        fullname="Craig Pratt" 
        initials="C." 
        surname="Pratt">

        <organization abbrev="CableLabs">CableLabs</organization>
        <address>
            <postal>
                <street>858 Coal Creek Circle</street>
                <city>Louisville</city>
                <region>CO</region>
                <code>80027</code>
            </postal>
        <email>pratt@acm.org</email>
        </address>
    </author>
    
    <author fullname="Barbara Stark" 
            initials="B.H." 
            surname="Stark" >
      <organization>AT&amp;T</organization>
      <address>
        <postal>
          <street></street>
          <city>Atlanta</city>
          <region>GA</region>
          <code></code>
          <country>US</country>
        </postal>
        <email>barbara.stark@att.com</email>
      </address>
    </author>
    
    <author fullname="Darshak Thakore"
            initials="D." 
            surname="Thakore" >
        <organization abbrev="CableLabs">CableLabs</organization>
        <address>
            <postal>
                <street>858 Coal Creek Circle</street>
                <city>Louisville</city>
                <region>CO</region>
                <code>80027</code>
            </postal>
            <email>d.thakore@cablelabs.com</email>
        </address>
    </author>
    
    <date year="2017" month="November" day="14"/>
         
    <!-- Meta-data Declarations -->
    
    <!-- Notice the use of &amp; as an escape for & which would otherwise
         start an entity declaration, whereas we want a literal &. -->
    <area>Applications and Real-Time</area>

    <!-- WG name at the upperleft corner of the doc,
         IETF fine for individual submissions.  You can also
         omit this element in which case in defaults to "Network Working Group" -
         a hangover from the ancient history of the IETF! -->
    <workgroup>HTTP</workgroup>
    
    <keyword>http range unit live aggregation</keyword>
    
    <!-- The DTD allows multiple area and workgroup elements but only the first one has any
         effect on output.  -->
    <!-- You can add <keyword/> elements here.  They will be incorporated into HTML output
         files in a meta tag but they have no effect on text or nroff output. -->
    
    
    <abstract>
        <t>
            To accommodate byte range requests for content that has 
            data appended over time, this document defines semantics 
            that allow a HTTP client and server to perform byte-range
      GET and HEAD requests that start at an arbitrary byte offset 
      within the representation and ends at an indeterminate offset.
        </t>
    </abstract>

    <note title="Editorial Note (To be removed by RFC Editor before publication)">
      <t>
        Discussion of this draft takes place on the HTTPBIS working group mailing list
        (ietf-http-wg@w3.org), which is archived at <eref
        target="https://lists.w3.org/Archives/Public/ietf-http-wg/"/>.
      </t>
      <t>
        Working Group information can be found at <eref target="http://httpwg.github.io/"/>; source code and issues
        list for this draft can be found at
        <eref target="https://github.com/httpwg/http-extensions/labels/rand-access-live"/>.
      </t><!--
      <t>
        The changes in this draft are summarized in <xref target="change.log"/>.
      </t>-->
    </note>
</front>

<middle>
    
    <section anchor="introduction" title="Introduction">
        <t>
             Some Hypertext Transfer Protocol (HTTP) clients use byte-range requests (Range requests using the "bytes" Range Unit) to transfer select portions of large representations. And in some cases large representations require content to be continuously or periodically appended - such as representations consisting of live audio or video sources, blockchain databases, and log files. Clients cannot access the appended/live content using a Range request with the bytes range unit using the currently defined byte-range semantics without accepting performance or behavior sacrifices which are not acceptable for many applications.
        </t>
        <t>
			For instance, HTTP clients have the ability to access appended content on an indeterminate-length resource by transferring the entire representation from the beginning and continuing to read the appended content as it's made available. Obviously, this is highly inefficient for cases where the representation is large and only the most recently appended content is needed by the client. 
		</t>
    	<t>
			Alternatively, clients can also access appended content by sending periodic open-ended bytes Range requests using the last-known end byte position as the range start. Performing low-frequency periodic bytes Range requests in this fashion (polling) introduces latency since the client will necessarily be somewhat behind the aggregated content - mimicking the behavior (and latency) of segmented content representations such as HLS or MPEG-DASH. And while performing these Range requests at higher frequency can reduce this latency, it also incurs more processing overhead and HTTP exchanges as many of the requests will return no content - since content is usually aggregated in groups of bytes (e.g. a video frame, audio sample, block, or log entry).
        </t>
        <t>
            This document describes a usage model for range requests which enables
            efficient retrieval of representations that are appended to over time
            by using large values and associated semantics for communicating
            range end positions. This model allows representations to be
            progressively delivered by servers as new content is added. It also
            ensures compatibility with servers and intermediaries that don't
            support this technique.
        </t>

        <section title="Requirements Language">
            <t>The key words &quot;MUST&quot;, &quot;MUST NOT&quot;,
            &quot;REQUIRED&quot;, &quot;SHALL&quot;, &quot;SHALL NOT&quot;,
            &quot;SHOULD&quot;, &quot;SHOULD NOT&quot;, &quot;RECOMMENDED&quot;,
            &quot;MAY&quot;, and &quot;OPTIONAL&quot; in this document are to be
            interpreted as described in <xref target="RFC2119">RFC 2119</xref>.
            </t>
        </section>

    </section>
    
    <section anchor="definition" title="Performing Range requests on Random-Access Aggregating (&quot;live&quot;) Content">
        <t>
            This document recommends a two-step process for accessing resources
            that have indeterminate length representations.
            
            Two steps are necessary because of limitations with the Range request
            header and the Content-Range response header fields. A server cannot
            know from a range request that a client wishes to receive a response
            that does not have a definite end. More critically, the header fields
            do not allow the server to signal that a resource has indeterminate
            length without also providing a fixed portion of the resource.

            A client first learns that the resource has a representation of
            indeterminate length by requesting a range of the resource. The server
            responds with the range that is available, but indicates that the
            length of the representation is unknown using the existing
            Content-Range syntax. See <xref target="establishing-range" /> 
            for details and examples.

            Once the client knows the resource has indeterminate length, it can
            request a range with a very large end position from the resource. The
            client chooses an explicit end value larger than can be transferred in
            the foreseeable term. A server which supports range requests of
            indeterminate length signals its understanding of the client's
            indeterminate range request by indicating that the range it is
            providing has a range end that exactly matches the client's requested
            range end rather than a range that is bounded by what is currently
            available. See <xref target="live-range-requests" /> for details.
    </t>
      
      <section anchor="establishing-range" title="Establishing the Randomly Accessible Byte Range">       
      <t>
        Establishing if a representation is continuously aggregating ("live") and determining the randomly-accessible byte range can both be determined using the existing definition for an open-ended byte-range request. Specifically, <xref target="RFC7233"></xref> defines a byte-range request of the form:
      </t>
<figure><artwork type="abnf2616">
   byte-range-spec = first-byte-pos "-" [ last-byte-pos ]
</artwork></figure>
      <t>
      which allows a client to send a HEAD request with a first-byte-pos and leave last-byte-pos absent. A
      server that receives a satisfiable byte-range request (with first-byte-pos smaller than the current
      representation length) may respond with a 206 status code (Partial Content) with a Content-Range
      header indicating the currently satisfiable byte range. For example:
      </t>
<figure><artwork type="example">
      HEAD /resource HTTP/1.1
      Range: bytes=0-
</artwork></figure>
      <t>      
      returns a response of the form:
      </t>  
<figure><artwork type="example">
    HTTP/1.1 206 Partial Content
    Content-Range: bytes 0-1234567/*
</artwork></figure>
      <t>
      from the server indicating that (1) the complete representation length is unknown (via the "*" in place of the complete-length field) and (2) that only bytes 0-1234567 were accessable at the time the request was processed by the server. The client can infer from this response that bytes 0-1234567 of the representation can be requested and returned in a timely fashion (the bytes are immediately available).
      </t>
    </section>
    <section anchor="live-range-requests" title="Byte-Range Requests Beyond the Randomly Accessible Byte Range">
      <t>
        Once a client has determined that a representation has an indeterminate length and established the byte range that can be accessed, it may want to perform a request with a start position within the randomly-accessible content range and an end position at an indefinite "live" point - a point where the byte-range GET request is fulfilled on-demand as the content is aggregated. 
      </t>
      <t>
        For example, for a large video asset, a client may wish to start a content transfer from the video "key" frame immediately before the point of aggregation and continue the content transfer indefinitely as content is aggregated - in order to support low-latency startup of a live video stream.
      </t> 
      <t>
        Unlike a byte-range Range request, a byte-range Content-Range response header cannot be "open ended", per <xref target="RFC7233"></xref>:
      </t>
<figure><artwork type="abnf">
   byte-content-range  = bytes-unit SP
                        ( byte-range-resp / unsatisfied-range )

   byte-range-resp     = byte-range "/" ( complete-length / "*" )
   byte-range          = first-byte-pos "-" last-byte-pos
   unsatisfied-range   = "*/" complete-length
                          
   complete-length     = 1*DIGIT
</artwork></figure>
      <t>
        Specifically, last-byte-pos is required in byte-range. So in order to preserve interoperability with existing HTTP clients, servers, proxies, and caches, this document proposes a mechanism for a client to indicate support for handling an indeterminate-length byte-range response, and a mechanism for a server to indicate if/when it's providing a indeterminate-length response. 
      </t>
      <t>
        A client can indicate support for handling indeterminate-length byte-range responses by providing a Very Large Value for the last-byte-pos in the byte-range request. For example, a client can perform a byte-range GET request of the form:
      </t>
<figure><artwork type="example">
    GET /resource HTTP/1.1
    Range: bytes=1230000-999999999999
</artwork></figure>
      <t>    
        where the last-byte-pos in the Request is much larger than the last-byte-pos returned in response to an open-ended byte-range HEAD request, as described above.
      </t>
      <t>
        In response, a server may indicate that it is supplying a continuously aggregating ("live") response by supplying the client request's last-byte-pos in the Content-Range response header. 
      </t>
      <t>
        For example:
      </t>
<figure><artwork type="example">
    GET /resource HTTP/1.1
    Range: bytes=1230000-999999999999
</artwork></figure>
      <t>
        returns
      </t>        
<figure><artwork type="example">
    HTTP/1.1 206 Partial Content
    Content-Range: bytes 1230000-999999999999/*
</artwork></figure>
      <t>        
        from the server to indicate that the response will start at byte 1230000 and continues indefinitely to include all aggregated content, as it becomes available.
      </t>
      <t>
        A server that doesn't support or supply a continuously aggregating ("live") response will supply the currently satisfiable byte range, as it would with an open-ended byte request.
      </t>
      <t>
        For example:
      </t>
<figure><artwork type="example">
    GET /resource HTTP/1.1
    Range: bytes=1230000-999999999999
</artwork></figure>
      <t>
        will return
      </t>
<figure><artwork type="example">
    HTTP/1.1 206 Partial Content
    Content-Range: bytes 1230000-1234567/*
</artwork></figure>
      <t>      
        from the server to indicate that the response will start at byte 1230000 and end at byte 1234567 and will not include any aggregated content. This is the response expected from a typical HTTP server - one that doesn't support byte-range requests on aggregating content.
      </t>
      <t>
        A client that doesn't receive a response indicating it is continuously aggregating must use other means to access aggregated content (e.g. periodic byte-range polling).
          </t>
      <t>
        A server that does return a continuously aggregating ("live") response should return data using chunked transfer coding and not provide a Content-Length header. A 0-length chunk indicates the end of the transfer, per section 4.1 of <xref target="RFC7230"></xref>.
          </t>
    </section>
  </section>
    <section anchor="other-applications" title="Other Applications of Random-Access Aggregating Content">    
      <section anchor="starting-at-live" title="Requests Starting at the Aggregation (&quot;Live&quot;) Point">
      <t>
          A client that wishes to only receive newly-aggregated portions of a
          resource (i.e., start at the "live" point), can use a HEAD request to
          learn what range the server has currently available and initiate an
          indeterminate-length transfer. For example:
      </t>
<figure><artwork type="example">
    HEAD /resource HTTP/1.1
    Range: bytes=0-
</artwork></figure>
        <t>
            With the Content-Range response header indicating the (or ranges) available. For example:
        </t>
<figure><artwork type="example">
    206 Partial Content
    Content-Range: bytes 0-1234567/*
</artwork></figure>
        <t>
            The client can then issue a request for a range starting at the end
            value (using a very large value for the end of a range) and receive
            only new content.
        </t>
<figure><artwork type="example">
    GET /resource HTTP/1.1
    Range: bytes=1234567-999999999999
</artwork></figure>
        <t>
          with a server returning a Content-Range response indicating that an indeterminate-length response body will be provided
        </t>
<figure><artwork type="example">
    206 Partial Content
    Content-Range: bytes 1234567-999999999999/*
</artwork></figure>
      </section>
      <section anchor="shift-buffers" title="Shift Buffer Representations">
      <t>
        Some representations lend themselves to front-end content deletion in addition to aggregation. While still supporting random access, representations of this type have a portion at the beginning (the "0" end) of the randomly-accessible region that become inaccessible over time. Examples of this kind of representation would be an audio-video time-shift buffer or a rolling log file.
      </t>
      <t>
        For example a Range request containing:
      </t>
<figure><artwork type="example">
    HEAD /resource HTTP/1.1
    Range: bytes=0-
</artwork></figure>
      <t>
        returns
      </t>
<figure><artwork type="example">
    206 Partial Content
    Content-Range: bytes 1000000-1234567/*
</artwork></figure>
      <t>
        indicating that the first 1000000 bytes were not accessible at the time the HEAD request was processed. Subsequent HEAD requests could return:
      </t>
<figure><artwork type="example">
    Content-Range: bytes 1000000-1234567/*
</artwork></figure>
<figure><artwork type="example">
    Content-Range: bytes 1010000-1244567/*
</artwork></figure>
<figure><artwork type="example">
    Content-Range: bytes 1020000-1254567/*
</artwork></figure>
      <t>
        Note though that the difference between the first-byte-pos and last-byte-pos need not be constant.
      </t>
      <t>
        The client could then follow-up with a GET Range request containing
      </t>
<figure><artwork type="example">
    GET /resource HTTP/1.1
    Range: bytes=1020000-999999999999
</artwork></figure>
      <t>
        with the server returning
      </t>  
<figure><artwork type="example">
    206 Partial Content
    Content-Range: bytes 1020000-999999999999/*
</artwork></figure>
      <t>
        with the response body returning bytes 1020000-1254567 immediately and aggregated ("live") data being returned as the content is aggregated.
      </t>
      </section>
    </section>

<!-- Possibly a 'Contributors' section ... -->

    <section anchor="Security" title="Security Considerations">
        <t>
      One potential issue with this recommendation is related to the use of very-large last-byte-pos values. Some client and server implementations may not be prepared to deal with byte position values of 2^^63 and beyond. So in applications where there's no expectation that the representation will ever exceed 2^^63, a value smaller than this value should be used as the Very Large last-byte-pos in a byte-seek request or content-range response.
      
      Also, some implementations (e.g. JavaScript-based clients and servers) are not able to represent all values beyond 2^^53. So similarly, if there's no expectation that a representation will ever exceed 2^^53 bytes, values smaller than this limit should be used for the last-byte-pos in byte-range requests.
    </t>
    </section>
</middle>

<!--  *****BACK MATTER ***** -->
<back>
    <!-- References split to informative and normative -->
    <references title="Normative References">
        &RFC2119;
        &RFC7230;
        &RFC7233;
    </references>

    <references title="Informative References">
        <reference anchor="RANGE-UNIT-REGISTRY"
            target="http://www.iana.org/assignments/http-parameters/http-parameters.xhtml#range-units">
            <front>
                <title>Hypertext Transfer Protocol (HTTP) Parameters</title>
                <author>
                    <organization>IANA</organization>
                </author>
                <date year="2016"/>
            </front>
        </reference>
        &RFC4234;
    </references>
        
    <section anchor="Acknowledgements" title="Acknowledgements">
        <t>
      Mark Nottingham, Patrick McManus, Julian Reschke, Remy Lebeau, Rodger Combs, Thorsten Lohmar, Martin Thompson, Adrien de Croy, K. Morgan, Roy T. Fielding, Jeremy Poulter.
        </t>
    </section>
    
</back>

</rfc>
