<?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.0.26 -->

<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
]>

<?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 ipr="trust200902" docName="draft-kerwin-http2-encoded-data-06" category="exp">

  <front>
    <title abbrev="http2-encoded-data">HTTP/2 Encoded Data</title>

    <author initials="M." surname="Kerwin" fullname="Matthew Kerwin">
      <organization></organization>
      <address>
        <email>matthew@kerwin.net.au</email>
        <uri>http://matthew.kerwin.net.au/</uri>
      </address>
    </author>

    <date year="2015"/>

    <area>General</area>
    
    <keyword>Internet-Draft</keyword>

    <abstract>


<t>This document introduces a new frame type for transporting gzip-encoded data between peers in the
Hypertext Transfer Protocol Version 2 (HTTP/2), and an associated error code for handling
invalid encoding.</t>



    </abstract>


  </front>

  <middle>


<section anchor="intro" title="Introduction">

<t>This document introduces a mechanism for applying gzip encoding <xref target="RFC1952"/> to data
transported between two endpoints in the Hypertext Transfer Protocol Version 2 (HTTP/2) <xref target="RFC7540"/>,
analogous to Transfer-Encoding in HTTP/1.1 <xref target="RFC7230"/>.</t>

<section anchor="notational-conventions" title="Notational Conventions">

<t>The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”,
“SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this
document are to be interpreted as described in <xref target="RFC2119"/>.</t>

</section>
</section>
<section anchor="additions" title="Additions to HTTP/2">

<t>This document introduces a new HTTP/2 frame type (<xref target="RFC7540"/>, Section 11.2),
a new HTTP/2 setting (<xref target="RFC7540"/>, Section 11.3),
and a new HTTP/2 error code (<xref target="RFC7540"/>, Section 7), to allow the compression
of data.</t>

<t>Note that while compressing some or all data in a stream might affect the total length of the
corresponding HTTP message body, the <spanx style="verb">content-length</spanx> header, if present, should continue to
reflect the total length of the <spanx style="emph">uncompressed</spanx> data. This is particularly relevant when detecting
malformed messages (<xref target="RFC7540"/>, Section 8.1.2.6).</t>

<section anchor="accept-gzipped-data" title="SETTINGS_ACCEPT_GZIPPED_DATA">

<t>SETTINGS_ACCEPT_GZIPPED_DATA (0xTBA) is used to indicate the sender’s ability and
willingness to receive GZIPPED_DATA frames. An endpoint MUST NOT send a GZIPPED_DATA
frame unless it receives this setting with a value of 1. </t>

<t>The initial value is 0, which indicates that GZIPPED_DATA frames are not supported. Any
value other than 0 or 1 MUST be treated as a connection error (<xref target="RFC7540"/>, Section 5.4.1)
of type PROTOCOL_ERROR.</t>

<t>An endpoint may advertise support for GZIPPED_DATA frames and later decide that it no longer
supports them.  After sending an ACCEPT_GZIPPED_DATA setting with the value 0, the endpoint
SHOULD continue to accept GZIPPED_DATA frames for a reasonable amount of time to account for
frames that may already be in flight.</t>

</section>
<section anchor="gzipped-data" title="GZIPPED_DATA">

<t>GZIPPED_DATA frames (type code=0xTBA) are semantically identical to DATA frames
(<xref target="RFC7540"/>, Section 6.1), but their payload is encoded using gzip compression.
Gzip compression is an LZ77 coding with a 32 bit CRC that is commonly produced
by the gzip file compression program <xref target="RFC1952"/>.
Significantly, GZIPPED_DATA frames are subject to flow control (<xref target="RFC7540"/>,
Section 5.2).</t>

<t>Any compression or decompression context for a GZIPPED_DATA frame is unique to that frame.</t>

<figure title="GZIPPED_DATA Frame Payload"><artwork><![CDATA[
  +---------------+
  |Pad Length? (8)|
  +---------------+-----------------------------------------------+
  |                            Data (*)                         ...
  +---------------------------------------------------------------+
  |                           Padding (*)                       ...
  +---------------------------------------------------------------+
]]></artwork></figure>

<t>The GZIPPED_DATA frame contains the following fields:</t>

<t><list style="symbols">
  <t>Pad Length:
An 8-bit field containing the length of the frame padding in units
of octets. This field is optional and is only present if the
PADDED flag is set.</t>
  <t>Data:
Encoded application data. The amount of compressed data is the remainder of the frame
payload after subtracting the length of the other fields that are
present.</t>
  <t>Padding:
Padding octets that contain no application semantic value. Padding
octets MUST be set to zero when sending and ignored when receiving.</t>
</list></t>

<t>The GZIPPED_DATA frame defines the following flags:</t>

<t><list style="symbols">
  <t><spanx style="verb">END_STREAM</spanx> (0x1):
Bit 1 being set indicates that this frame is the last that the
endpoint will send for the identified stream. Setting this flag
causes the stream to enter one of the “half closed” states or the
“closed” state (<xref target="RFC7540"/>, Section 5.1).</t>
  <t><spanx style="verb">PADDED</spanx> (0x8):
Bit 4 being set indicates that the Pad Length field is present.</t>
</list></t>

<t>A GZIPPED_DATA frame MUST NOT be sent if the ACCEPT_GZIPPED_DATA setting
of the peer is set to 0. </t>

<t>An intermediary, on receiving a GZIPPED_DATA frame, MAY decode the data and forward it to its
downstream peer in one or more DATA frames. If the downstream peer has not advertised support
for GZIPPED_DATA frames (by sending an ACCEPT_GZIPPED_DATA setting with the value 1) the
intermediary MUST decode the data before forwarding it.</t>

<t>If an endpoint detects that the payload of a GZIPPED_DATA frame is not encoded correctly,
for example with an incorrect checksum, the endpoint MUST
treat this as a stream error (see <xref target="RFC7540"/>, Section 5.4.2) of type
DATA_ENCODING_ERROR (<xref target="error"/>). The endpoint MAY then choose to immediately send an
ACCEPT_GZIPPED_DATA setting with the value 0.</t>

<t>If an intermediary propagates a GZIPPED_DATA frame from the source peer to the destination peer
without modifying the payload or its encoding, and receives a DATA_ENCODING_ERROR from the
receiving peer, it SHOULD pass the error on to the source peer.</t>

<t>GZIPPED_DATA frames MUST be associated with a stream. If a GZIPPED_DATA frame is received whose
stream identifier field is 0x0, the recipient MUST respond with a connection error
(<xref target="RFC7540"/>, Section 5.4.1) of type PROTOCOL_ERROR.</t>

<t>GZIPPED_DATA frames are subject to flow control and can only be sent when a stream is in the
“open” or “half closed (remote)” states. The entire GZIPPED_DATA frame payload is included in flow
control, including the Pad Length and Padding fields if present. If a
GZIPPED_DATA frame is received whose stream is not in “open” or “half closed (local)” state, the
recipient MUST respond with a stream error (<xref target="RFC7540"/>, Section 5.4.2) of type
STREAM_CLOSED.</t>

<t>The total number of padding octets is determined by the value of the Pad Length field. If the
length of the padding is greater than the length of the remainder of the frame payload, the
recipient MUST treat this as a connection error (<xref target="RFC7540"/>, Section 5.4.1) of type
PROTOCOL_ERROR.</t>

<t>Note: A frame can be increased in size by one octet by including a Pad Length field
  with a value of zero.</t>

<t>Padding is a security feature; see Section 10.7 of <xref target="RFC7540"/>.</t>

</section>
<section anchor="error" title="DATA_ENCODING_ERROR">

<t>The following new error code is defined:</t>

<t><list style="symbols">
  <t><spanx style="verb">DATA_ENCODING_ERROR</spanx> (0xTBA):
The endpoint detected that its peer sent a GZIPPED_DATA frame with an invalid encoding.</t>
</list></t>

</section>
</section>
<section anchor="fragmentation" title="Fragmentation">

<t>Traversing a network segment with small frame size limits introduces the risk of fragmenting an
encoded stream. </t>

</section>
<section anchor="security" title="Security Considerations">

<t>Further to the Use of Compression in HTTP/2 (<xref target="RFC7540"/>, Section 10.6),
intermediaries MUST NOT apply compression to DATA frames, or alter the compression of
GZIPPED_DATA frames other than decompressing, unless additional information is available
that allows the intermediary to identify the source of data. In particular, frames that
are not compressed cannot be compressed, and frames that are separately compressed cannot
be merged into a single compressed frame.</t>

</section>
<section anchor="iana" title="IANA Considerations">

<t>This document updates the registries for frame types and error codes in
the “Hypertext Transfer Protocol (HTTP) 2 Parameters” section.  This
document also establishes a new registry for HTTP/2 encoding scheme
codes.  This new registry is entered into the “Hypertext Transfer
Protocol (HTTP) 2 Parameters” section.</t>

<section anchor="http2-frame-type-registry-update" title="HTTP/2 Frame Type Registry Update">

<t>This document updates the “HTTP/2 Frame Type” registry
(<xref target="RFC7540"/>, Section 11.2).  The entries in the
following table are registered by this document.</t>

<texttable>
      <ttcol align='left'>Frame Type</ttcol>
      <ttcol align='left'>Code</ttcol>
      <ttcol align='left'>Section</ttcol>
      <c>GZIPPED_DATA</c>
      <c>TBD</c>
      <c><xref target="gzipped-data"/></c>
</texttable>

</section>
<section anchor="http2-settings-registry-update" title="HTTP/2 Settings Registry Update">

<t>This document updates the “HTTP/2 Settings” registry
(<xref target="RFC7540"/>, Section 11.3).  The entries in the
following table are registered by this document.</t>

<texttable>
      <ttcol align='left'>Frame Type</ttcol>
      <ttcol align='left'>Code</ttcol>
      <ttcol align='left'>Initial Value</ttcol>
      <ttcol align='left'>Specification</ttcol>
      <c>ACCEPT_GZIPPED_DATA</c>
      <c>TBD</c>
      <c>0</c>
      <c><xref target="accept-gzipped-data"/></c>
</texttable>

</section>
<section anchor="http2-error-code-registry-update" title="HTTP/2 Error Code Registry Update">

<t>This document updates the “HTTP/2 Error Code” registry
(<xref target="RFC7540"/>, Section 11.4).  The entries in the
following table are registered by this document.</t>

<texttable>
      <ttcol align='left'>Name</ttcol>
      <ttcol align='left'>Code</ttcol>
      <ttcol align='left'>Description</ttcol>
      <ttcol align='left'>Specification</ttcol>
      <c>DATA_ENCODING_ERROR</c>
      <c>TBD</c>
      <c>Invalid encoding detected</c>
      <c><xref target="error"/></c>
</texttable>

</section>
</section>
<section anchor="acknowledgements" title="Acknowledgements">

<t>Thanks to Keith Morgan for his advice, input, and editorial contributions.</t>

</section>


  </middle>

  <back>

    <references title='Normative References'>





<reference anchor='RFC1952'>

<front>
<title>GZIP file format specification version 4.3</title>
<author initials='P.' surname='Deutsch' fullname='L. Peter Deutsch'>
<organization>Aladdin Enterprises</organization>
<address>
<postal>
<street>203 Santa Margarita Ave.</street>
<city>Menlo Park</city>
<region>CA</region>
<code>94025</code>
<country>US</country></postal>
<phone>+1 415 322 0103</phone>
<facsimile>+1 415 322 1734</facsimile>
<email>ghost@aladdin.com</email></address></author>
<author initials='J-L.' surname='Gailly' fullname='Jean-Loup Gailly'>
<organization />
<address>
<email>gzip@prep.ai.mit.edu</email></address></author>
<author initials='M.' surname='Adler' fullname='Mark Adler'>
<organization />
<address>
<email>madler@alumni.caltech.edu</email></address></author>
<author initials='L.P.' surname='Deutsch' fullname='L. Peter Deutsch'>
<organization />
<address>
<email>ghost@aladdin.com</email></address></author>
<author initials='G.' surname='Randers-Pehrson' fullname='Glenn Randers-Pehrson'>
<organization />
<address>
<email>randeg@alumni.rpi.edu</email></address></author>
<date year='1996' month='May' />
<abstract>
<t>This specification defines a lossless compressed data format that is compatible with the widely used GZIP utility.  The format includes a cyclic redundancy check value for detecting data corruption.  The format presently uses the DEFLATE method of compression but can be easily extended to use other compression methods.  The format can be implemented readily in a manner not covered by patents.</t></abstract></front>

<seriesInfo name='RFC' value='1952' />
<format type='TXT' octets='25036' target='http://www.rfc-editor.org/rfc/rfc1952.txt' />
<format type='PS' octets='43337' target='http://www.rfc-editor.org/rfc/rfc1952.ps' />
<format type='PDF' octets='43211' target='http://www.rfc-editor.org/rfc/rfc1952.pdf' />
</reference>



<reference anchor='RFC2119'>

<front>
<title abbrev='RFC Key Words'>Key words for use in RFCs to Indicate Requirement Levels</title>
<author initials='S.' surname='Bradner' fullname='Scott Bradner'>
<organization>Harvard University</organization>
<address>
<postal>
<street>1350 Mass. Ave.</street>
<street>Cambridge</street>
<street>MA 02138</street></postal>
<phone>- +1 617 495 3864</phone>
<email>sob@harvard.edu</email></address></author>
<date year='1997' month='March' />
<area>General</area>
<keyword>keyword</keyword>
<abstract>
<t>
   In many standards track documents several words are used to signify
   the requirements in the specification.  These words are often
   capitalized.  This document defines these words as they should be
   interpreted in IETF documents.  Authors who follow these guidelines
   should incorporate this phrase near the beginning of their document:

<list>
<t>
      The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
      NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED",  "MAY", and
      "OPTIONAL" in this document are to be interpreted as described in
      RFC 2119.
</t></list></t>
<t>
   Note that the force of these words is modified by the requirement
   level of the document in which they are used.
</t></abstract></front>

<seriesInfo name='BCP' value='14' />
<seriesInfo name='RFC' value='2119' />
<format type='TXT' octets='4723' target='http://www.rfc-editor.org/rfc/rfc2119.txt' />
<format type='HTML' octets='17970' target='http://xml.resource.org/public/rfc/html/rfc2119.html' />
<format type='XML' octets='5777' target='http://xml.resource.org/public/rfc/xml/rfc2119.xml' />
</reference>



<reference anchor='RFC7540'>

<front>
<title>Hypertext Transfer Protocol Version 2 (HTTP/2)</title>
<author initials='M.' surname='Belshe' fullname='M. Belshe'>
<organization /></author>
<author initials='R.' surname='Peon' fullname='R. Peon'>
<organization /></author>
<author initials='M.' surname='Thomson' fullname='M. Thomson'>
<organization /></author>
<date year='2015' month='May' />
<abstract>
<t>This specification describes an optimized expression of the semantics of the Hypertext Transfer Protocol (HTTP), referred to as HTTP version 2 (HTTP/2). HTTP/2 enables a more efficient use of network resources and a reduced perception of latency by introducing header field compression and allowing multiple concurrent exchanges on the same connection. It also introduces unsolicited push of representations from servers to clients.&lt;/t>&lt;t> This specification is an alternative to, but does not obsolete, the HTTP/1.1 message syntax. HTTP's existing semantics remain unchanged.</t></abstract></front>

<seriesInfo name='RFC' value='7540' />
<format type='TXT' octets='209580' target='http://www.rfc-editor.org/rfc/rfc7540.txt' />
</reference>




    </references>

    <references title='Informative References'>





<reference anchor='RFC7230'>

<front>
<title>Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing</title>
<author initials='R.' surname='Fielding' fullname='R. Fielding'>
<organization /></author>
<author initials='J.' surname='Reschke' fullname='J. Reschke'>
<organization /></author>
<date year='2014' month='June' />
<abstract>
<t>The Hypertext Transfer Protocol (HTTP) is a stateless application-level protocol for distributed, collaborative, hypertext information systems.  This document provides an overview of HTTP architecture and its associated terminology, defines the "http" and "https" Uniform Resource Identifier (URI) schemes, defines the HTTP/1.1 message syntax and parsing requirements, and describes related security concerns for implementations.</t></abstract></front>

<seriesInfo name='RFC' value='7230' />
<format type='TXT' octets='205947' target='http://www.rfc-editor.org/rfc/rfc7230.txt' />
</reference>




    </references>


<section anchor="changelog" title="Changelog">

<t>Since -05:</t>

<t><list style="symbols">
  <t>changed ACCEPT_ENCODED_DATA back from a frame to a setting, since it
carries a single scalar value now</t>
</list></t>

<t>Since -04:</t>

<t><list style="symbols">
  <t>reduced encoding options to only gzip (suggested by Martin Thomson)</t>
  <t>remove fragmentation and segment stuff, including reference to ‘http2-segments’ I-D</t>
  <t>updated HTTP/2 reference from I-D to (freshly published) RFC7230</t>
</list></t>

<t>Since -03:</t>

<t><list style="symbols">
  <t>added ‘identity’ encoding; removed ‘compress’ and ‘zlib’ (suggested by PHK)</t>
  <t>added SEGMENT flag, for segments that don’t continue</t>
  <t>clarified that ACCEPT is for a connection, and ENCODED_DATA is for a stream</t>
  <t>copied “padding” text from HTTP/2 draft</t>
</list></t>

<t>Since -02:</t>

<t><list style="symbols">
  <t>moved all discussion of fragmentation and segments to its own section</t>
</list></t>

<t>Since -01:</t>

<t><list style="symbols">
  <t>referenced new draft-kerwin-http2-segments to handle fragmentation</t>
</list></t>

<t>Since -00:</t>

<t><list style="symbols">
  <t>changed ACCEPT_ENCODED_DATA from a complex setting to a frame</t>
  <t>improved IANA Considerations section (with lots of input from Keith Morgan)</t>
</list></t>

</section>


  </back>
</rfc>

