forked from httpwg/http2-spec
-
Notifications
You must be signed in to change notification settings - Fork 273
/
draft-ietf-httpbis-header-compression.xml
executable file
·3163 lines (3098 loc) · 144 KB
/
draft-ietf-httpbis-header-compression.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='lib/rfc2629.xslt' ?>
<?rfc toc="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc linkmailto="no"?>
<?rfc editing="no"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc rfcedstyle="yes"?>
<?rfc-ext allow-markup-in-artwork="yes" ?>
<?rfc-ext include-index="no" ?>
<rfc category="std"
ipr="trust200902"
docName="draft-ietf-httpbis-header-compression-latest"
x:maturity-level="proposed"
xmlns:x="http://purl.org/net/xml2rfc/ext">
<x:feedback template="mailto:[email protected]?subject={docname},%20%22{section}%22&body=<{ref}>:"/>
<front>
<title abbrev="HPACK">HPACK - Header Compression for HTTP/2</title>
<author initials="R." surname="Peon" fullname="Roberto Peon">
<organization>Google, Inc</organization>
<address>
<email>[email protected]</email>
</address>
</author>
<author initials="H." surname="Ruellan" fullname="Hervé Ruellan">
<organization>Canon CRF</organization>
<address>
<email>[email protected]</email>
</address>
</author>
<date year="2014"/>
<area>Applications</area>
<workgroup>HTTPbis</workgroup>
<keyword>HTTP</keyword>
<keyword>Header</keyword>
<abstract>
<t>
This specification defines HPACK, a compression format for
efficiently representing HTTP header fields in the context
of HTTP/2.
</t>
</abstract>
<note title="Editorial Note (To be removed by RFC Editor)">
<t>
Discussion of this draft takes place on the HTTPBIS working group
mailing list ([email protected]), which is archived at <eref
target="http://lists.w3.org/Archives/Public/ietf-http-wg/"/>.
</t>
<t>
Working Group information can be found at
<eref target="http://tools.ietf.org/wg/httpbis/"/>; that specific to
HTTP/2 are at <eref target="http://http2.github.io/"/>.
</t>
<t>
The changes in this draft are summarized in <xref
target="changes.since.draft-ietf-httpbis-header-compression-06"/>.
</t>
</note>
</front>
<middle>
<section title="Introduction">
<t>
This specification defines HPACK, a compression format for
efficiently representing HTTP header fields in the context
of HTTP/2 (see <xref target="HTTP2"/>).
</t>
</section>
<section title="Overview" anchor="overview">
<t>
In HTTP/1.1 (see <xref target="HTTP-p1"/>), header fields are
encoded without any form of compression. As web pages have grown
to include dozens to hundreds of requests, the redundant
header fields in these requests now measurably increase
latency and unnecessarily consume bandwidth (see <xref
target="PERF1"/> and <xref target="PERF2"/>).
</t>
<t>
SPDY <xref target="SPDY"/> initially addressed this
redundancy by compressing header fields using the DEFLATE
format <xref target="DEFLATE"/>, which proved
very effective at efficiently representing the redundant header
fields. However, that approach exposed a security risk as
demonstrated by the CRIME attack (see <xref target="CRIME"/>).
</t>
<t>
This document describes HPACK, a new compressor for header
fields which eliminates redundant header fields, is not
vulnerable to known security attacks, and which also has a
bounded memory requirement for use in constrained environments.
</t>
<section title="Outline">
<t>
The HTTP header field encoding defined in this document
is based on a header table that maps name-value pairs to
index values. The header table is incrementally updated
during the HTTP/2 connection.
</t>
<t>
A set of header fields is treated as an unordered collection
of name-value pairs. Names and values are considered to be
opaque sequences of octets. The order of header fields is
not guaranteed to be preserved after being compressed and
decompressed.
</t>
<t>
As two consecutive sets of header fields often have header
fields in common, each set is coded as a difference from
the previous set. The goal is to only encode the changes
(header fields present in one of the sets that are absent
from the other) between the two sets of header fields.
</t>
<t>
A header field is represented either literally or as a
reference to a name-value pair in the header table. A set
of header fields is stored as a set of references to
entries in the header table (possibly keeping only a
subset of it, as some header fields may be missing a
corresponding entry in the header table). Differences
between consecutive sets of header fields are encoded as
changes to the set of references.
</t>
<t>
The encoder is responsible for deciding which header
fields to insert as new entries in the header table. The
decoder executes the modifications to the header table and
reference set prescribed by the encoder, reconstructing
the set of header fields in the process. This enables
decoders to remain simple and understand a wide variety of
encoders.
</t>
<t>
Examples illustrating the use of these different
mechanisms to represent header fields are available in
<xref target="examples"/>.
</t>
</section>
</section>
<section title="Header Field Encoding" anchor="header.encoding">
<section title="Encoding Concepts" anchor="encoding.concepts">
<t>
The encoding and decoding of header fields relies on some
components and concepts:
<list style="hanging">
<t hangText="Header Field:">
A name-value pair. Both the name and value are
treated as opaque sequences of octets.
</t>
<t hangText="Header Table:">
The header table (see <xref
target="header.table"/>) is a component used
to associate stored header fields to index values.
</t>
<t hangText="Static Table:">
The static table (see <xref
target="static.table"/>) is a component used
to associate static header fields to index values.
This data is ordered, read-only, always
accessible, and may be shared amongst all encoding
contexts.
</t>
<t hangText="Reference Set:">
The reference set (see <xref
target="reference.set"/>) is a component
containing an unordered set of references to
entries in the header table. This is used for the
differential encoding of a new header set.
</t>
<t hangText="Header Set:">
A header set is an unordered group of
header fields that are encoded jointly. A complete
set of key-value pairs contained in a HTTP
request or response is a header set.
</t>
<t hangText="Header Field Representation:">
A header field can be represented in encoded form
either as a literal or as an index (see <xref
target="header.representation"/>).
</t>
<t hangText="Header Block:">
The entire set of encoded header field
representations which, when decoded, yield a
complete header set.
</t>
<t hangText="Header Field Emission:">
When decoding a set of header field
representations, some operations emit a header
field (see <xref target="header.emission"/>).
Emitted header fields are added to the current
header set and cannot be removed.
</t>
</list>
</t>
<section title="Encoding Context" anchor="encoding.context">
<t>
The set of mutable structures used within an encoding
context include a header table and a reference set.
Everything else is either immutable or conceptual.
</t>
<t>
HTTP messages are exchanged between a client and a
server in both directions. The encoding of header
fields in each direction is independent from the
other direction. There is a single encoding context
for each direction used to encode all header fields
sent in that direction.
</t>
</section>
<section title="Header Table" anchor="header.table">
<t>
A header table consists of a list of header fields
maintained in first-in, first-out order.
The first and newest entry in a header table is always
at index 1, and the oldest entry of a header table is
at the index len(header table).
</t>
<t>
The header table is initially empty.
</t>
<t>
There is typically no need for the header table to
contain duplicate entries. However, duplicate entries
MUST NOT be treated as an error by a decoder.
</t>
<t>
The encoder decides how to update the header table and
as such can control how much memory is used by the
header table. To limit the memory requirements of
the decoder, the header table size is strictly
bounded (see <xref target="maximum.table.size"/>).
</t>
<t>
The header table is updated during the processing of
a set of header field representations (see <xref
target="header.representation.processing"/>).
</t>
</section>
<section title="Reference Set" anchor="reference.set">
<t>
A reference set is an unordered set of references to
entries of the header table.
</t>
<t>
The reference set is initially empty.
</t>
<t>
The reference set is updated during the processing of
a set of header field representations (see <xref
target="header.representation.processing"/>).
</t>
<t>
The reference set enables differential encoding,
whereby only differences between the previous header
set and the current header set need to be encoded. The
use of differential encoding is optional for any
header set.
</t>
<t>
When an entry is evicted from the header table, if it
was referenced from the reference set, its reference
is removed from the reference set.
</t>
<t>
To limit the memory requirements on the decoder side
for handling the reference set, only entries within
the header table can be contained in the reference
set. To still allow entries from the static table to
take advantage of the differential encoding, when a
header field is represented as a reference to an entry
of the static table, this entry is inserted into the
header table (see <xref
target="header.representation.processing"/>).
</t>
</section>
<section title="Header Field Representation"
anchor="header.representation">
<t>
An encoded header field can be represented either as a
literal or as an index.
</t>
<t>
<list style="hanging">
<t hangText="Literal Representation:">
A literal representation defines a new header
field. The header field name is represented
either literally or as a reference to an entry
of the header table. The header field value is
represented literally.
</t>
<t>
Two different literal representations are
provided:
<list style="symbols">
<t>
A literal representation that does not
add the header field to the header
table (see <xref
target="literal.header.without.indexing"/>).
</t>
<t>
A literal representation that adds the
header field as a new entry at the
beginning of the header table (see
<xref
target="literal.header.with.incremental.indexing"/>).
</t>
</list>
</t>
<t hangText="Indexed Representation:">
The indexed representation defines a header
field as a reference to an entry in either the
header table or the static table (see <xref
target="indexed.header.representation"/>).
<figure title="Index Address Space">
<artwork type="drawing"><![CDATA[
<---------- Index Address Space ---------->
<-- Header Table --> <-- Static Table -->
+---+-----------+---+ +---+-----------+---+
| 1 | ... | k | |k+1| ... | n |
+---+-----------+---+ +---+-----------+---+
^ |
| V
Insertion Point Drop Point
]]></artwork>
</figure>
<list>
<t>
Indices between 1 and len(header
table), inclusive, refer to elements
in the header table, with index 1
referring to the beginning of the
table.
</t>
<t>
Indices between len(header table)+1 and
len(header table)+len(static table),
inclusive, refer to elements in the
static table, where the index
len(header table)+1 refers to the first
entry in the static table.
</t>
<t>
Index 0 signals a modification of the
encoding context: either the reference
set is emptied, or the maximum size of
the header table is updated (see <xref
target="encoding.context.update"/>).
</t>
<t>
Any other indices MUST be treated as
erroneous, and the compression context
considered corrupt and unusable.
</t>
</list>
</t>
</list>
</t>
</section>
<section title="Header Field Emission" anchor="header.emission">
<t>
The emission of a header field is the process of
marking a header field as belonging to the current
header set. Once a header has been emitted, it cannot
be removed from the current header set.
</t>
<t>
On the decoding side, an emitted header field can be
safely passed to the upper processing layer as part of
the current header set. The decoder MAY pass the
emitted header fields to the upper processing layer in
any order.
</t>
<t>
By emitting header fields instead of emitting header
sets, the decoder can be implemented in a streaming
way, and as such has only to keep in memory the header
table and the reference set. This bounds the amount of
memory used by the decoder, even in presence of a very
large set of header fields. The management of memory
for handling very large sets of header fields can
therefore be deferred to the upper processing layers.
</t>
</section>
</section>
<section title="Header Block Decoding"
anchor="header.block.decoding">
<t>
The processing of a header block to obtain a header set is
defined in this section. To ensure that the decoding will
successfully produce a header set, a decoder MUST obey the
following rules.
</t>
<section title="Header Field Representation Processing"
anchor="header.representation.processing">
<t>
All the header field representations contained in a
header block are processed in the order in which they
are presented, as specified below.
</t>
<t>
An <spanx>indexed representation</spanx> with an index
value of 0 entails one of the following actions,
depending on what is encoded next:
<list style="symbols">
<t>The reference set is emptied.</t>
<t>The maximum size of the header table is
updated.</t>
</list>
</t>
<t>
An <spanx>indexed representation</spanx> corresponding
to an entry <spanx>present</spanx> in the
reference set entails the following actions:
<list style="symbols">
<t>The entry is removed from the reference
set.</t>
</list>
</t>
<t>
An <spanx>indexed representation</spanx> corresponding
to an entry <spanx>not present</spanx> in the
reference set entails the following actions:
<list style="symbols">
<t>If referencing an element of the static table:
<list style="symbols">
<t>The header field corresponding to the
referenced entry is emitted.</t>
<t>The referenced static entry is inserted
at the beginning of the header
table.</t>
<t>A reference to this new header table
entry is added to the reference set
(except if this new entry didn't fit
in the header table).</t>
</list>
</t>
<t>If referencing an element of the header table:
<list style="symbols">
<t>The header field corresponding to the
referenced entry is emitted.</t>
<t>The referenced header table entry is
added to the reference set.</t>
</list>
</t>
</list>
</t>
<t>
A <spanx>literal representation</spanx> that is
<spanx>not added</spanx> to the header table entails
the following action:
<list style="symbols">
<t>The header field is emitted.</t>
</list>
</t>
<t>
A <spanx>literal representation</spanx> that is
<spanx>added</spanx> to the header table entails
the following actions:
<list style="symbols">
<t>The header field is emitted.</t>
<t>The header field is inserted at the beginning
of the header table.</t>
<t>A reference to the new entry is added to the
reference set (except if this new entry didn't
fit in the header table).</t>
</list>
</t>
</section>
<section title="Reference Set Emission"
anchor="reference.set.emission">
<t>
Once all the representations contained in a header
block have been processed, the header fields
referenced in the reference set which have not
previously been emitted during this processing are
emitted.
</t>
</section>
<section title="Header Set Completion"
anchor="header.set.completion">
<t>
Once all of the header field representations have been
processed, and the remaining items in the reference
set have been emitted, the header set is complete.
</t>
</section>
</section>
<section title="Header Table Management"
anchor="header.table.management">
<section title="Maximum Table Size"
anchor="maximum.table.size">
<t>
To limit the memory requirements on the decoder side,
the size of the header table is bounded. The size
of the header table MUST stay lower than or equal to its
maximum size.
</t>
<t>
By default, the maximum size of the header table is
equal to the value of the HTTP/2 setting
SETTINGS_HEADER_TABLE_SIZE defined by the decoder (see
<xref target="HTTP2"/>). The encoder can change this
maximum size (see <xref
target="encoding.context.update"/>), but it must
stay lower than or equal to the value of
SETTINGS_HEADER_TABLE_SIZE.
</t>
<t>
The size of the header table is the sum of the
size of its entries.
</t>
<t>
The size of an entry is the sum of its name's length
in octets (as defined in <xref
target="string.literal.representation" />), of its
value's length in octets (<xref
target="string.literal.representation" />) and of
32 octets.
</t>
<t>
The lengths are measured on the non-encoded entry
name and entry value (for the case when a Huffman
encoding is used to transmit string values).
</t>
<t>
The 32 octets are an accounting for the entry
structure overhead. For example, an entry structure
using two 64-bits pointers to reference the name and
the value and the entry, and two 64-bits integer for
counting the number of references to these name and
value would use 32 octets.
</t>
</section>
<section title="Entry Eviction When Header Table Size Changes"
anchor="entry.eviction">
<t>
Whenever an entry is evicted from the header table,
any reference to that entry contained by the reference
set is removed.
</t>
<t>
Whenever the maximum size for the header table is made
smaller, entries are evicted from the end of the
header table until the size of the header table is
less than or equal to the maximum size.
</t>
<t>
The eviction of an entry from the header
table causes the index of the entries in the static
table to be reduced by one.
</t>
</section>
<section title="Entry Eviction when Adding New Entries"
anchor="entry.addition">
<t>
Whenever a new entry is to be added to the table, any
name referenced by the representation of this new
entry is cached, and then entries are evicted from the
end of the header table until the size of the header
table is less than or equal to (maximum size - new
entry size), or until the table is empty.
</t>
<t>
If the size of the new entry is less than or equal to
the maximum size, that entry is added to the table. It
is not an error to attempt to add an entry
that is larger than the maximum size.
</t>
</section>
</section>
</section>
<section title="Detailed Format" anchor="detailed.format">
<section title="Low-level representations"
anchor="low-level.representation">
<section title="Integer representation"
anchor="integer.representation">
<t>
Integers are used to represent name indexes, pair
indexes or string lengths. To allow for optimized
processing, an integer representation always finishes
at the end of an octet.
</t>
<t>
An integer is represented in two parts: a prefix that
fills the current octet and an optional list of octets
that are used if the integer value does not fit within
the prefix. The number of bits of the prefix (called
N) is a parameter of the integer representation.
</t>
<t>
The N-bit prefix allows filling the current octet. If
the value is small enough (strictly less than
2<x:sup>N</x:sup>-1), it is encoded within the N-bit
prefix. Otherwise all the bits of the prefix are set
to 1 and the value is encoded using an <eref
target="http://en.wikipedia.org/wiki/Variable-length_quantity">
unsigned variable length integer</eref>
representation. N is always between 1 and 8 bits. An
integer starting at an octet-boundary will have an 8-bit
prefix.
</t>
<t>
The algorithm to represent an integer I is as follows:
<figure><artwork type = "inline"><![CDATA[
if I < 2^N - 1, encode I on N bits
else
encode (2^N - 1) on N bits
I = I - (2^N - 1)
while I >= 128
encode (I % 128 + 128) on 8 bits
I = I / 128
encode I on 8 bits
]]></artwork></figure>
</t>
<t>
For informational purpose, the algorithm to decode an
integer I is as follows:
<figure><artwork type="inline"><![CDATA[
decode I from the next N bits
if I < 2^N - 1, return I
else
M = 0
repeat
B = next octet
I = I + (B & 127) * 2^M
M = M + 7
while B & 128 == 128
return I
]]></artwork></figure>
</t>
<t>
This integer representation allows for values of
indefinite size. It is also possible for an encoder to
send a large number of zero values, which can waste
octets and could be used to overflow integer values.
Excessively large integer encodings - in value or octet
length - MUST be treated as a decoding error. Different
limits can be set for each of the different uses of
integers, based on implementation constraints.
</t>
<section title="Example 1: Encoding 10 using a 5-bit prefix"
anchor="integer.representation.example1">
<t>
The value 10 is to be encoded with a 5-bit prefix.
<list style="symbols">
<t>
10 is less than 31 (= 2<x:sup>5</x:sup> -
1) and is represented using the 5-bit
prefix.
</t>
</list>
</t>
<figure>
<artwork type="inline"><![CDATA[
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| X | X | X | 0 | 1 | 0 | 1 | 0 | 10 stored on 5 bits
+---+---+---+---+---+---+---+---+
]]></artwork>
</figure>
</section>
<section title="Example 2: Encoding 1337 using a 5-bit prefix"
anchor="integer.representation.example2">
<t>
The value I=1337 is to be encoded with a 5-bit
prefix.
<list>
<t>
1337 is greater than 31 (=
2<x:sup>5</x:sup> - 1).
</t>
<t>
<list>
<t>The 5-bit prefix is filled with its
max value (31).</t>
</list>
</t>
<t>I = 1337 - (2<x:sup>5</x:sup> - 1) =
1306.</t>
<t>
<list>
<t>I (1306) is greater than or equal
to 128, the while loop body
executes:</t>
<t>
<list>
<t>I % 128 == 26</t>
<t>26 + 128 == 154</t>
<t>154 is encoded in 8 bits as:
10011010</t>
<t>I is set to 10 (1306 / 128 ==
10)</t>
<t>I is no longer greater than
or equal to 128, the while
loop terminates.</t>
</list>
</t>
<t>
I, now 10, is encoded on 8 bits
as: 00001010
</t>
</list>
</t>
<t>The process ends.</t>
</list>
</t>
<figure>
<artwork type="inline"><![CDATA[
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| X | X | X | 1 | 1 | 1 | 1 | 1 | Prefix = 31, I = 1306
| 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1306>=128, encode(154), I=1306/128
| 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 10<128, encode(10), done
+---+---+---+---+---+---+---+---+
]]></artwork>
</figure>
</section>
<section title="Example 3: Encoding 42 starting at an
octet-boundary"
anchor="integer.representation.example3">
<t>
The value 42 is to be encoded starting at an
octet-boundary. This implies that a 8-bit prefix is
used.
<list style="symbols">
<t>
42 is less than 255 (= 2<x:sup>8</x:sup> -
1) and is represented using the 8-bit
prefix.
</t>
</list>
</t>
<figure>
<artwork type="inline"><![CDATA[
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 42 stored on 8 bits
+---+---+---+---+---+---+---+---+
]]></artwork>
</figure>
</section>
</section>
<section title="String Literal Representation"
anchor="string.literal.representation">
<t>
Header field names and header field values are
encoded as sequences of octets. A header field name or
a header field value is encoded in three parts:
<list style="numbers">
<t>
One bit, H, indicating whether or not
the octets are Huffman encoded.
</t>
<t>
The number of octets required to hold the
result of the next step, represented as an
integer with a 7-bit prefix (see <xref
target="integer.representation"/>),
immediately following the first bit.
</t>
<t>
The encoded data of the string:
<list style="symbols">
<t>
If H is '1', then the encoded
string data is the bitwise
concatenation of the canonical <xref
target="CANON"/> Huffman code
<xref target="HUFF"/> corresponding to
each octet of the data, followed by
between 0-7 bits of padding.
</t>
<t>
If H is '0', then the encoded string
is the octets of the field value
without modification.
</t>
</list>
</t>
</list>
</t>
<t>
Padding is necessary when doing Huffman encoding to
ensure that the remaining bits between the actual end of
the data and the next octet boundary are not
misinterpreted as part of the input data.
</t>
<t>
When padding for Huffman encoding, the bits from the
EOS (end-of-string) entry in the Huffman table are
used, starting with the MSB (most significant bit).
This entry is guaranteed to be at least 8 bits long.
</t>
<t>
String literals which use Huffman encoding
are encoded with the Huffman Codes <xref
target="huffman.codes"/> (see examples in Request
Examples with Huffman <xref
target="request.examples.with.huffman"/> and in
Response Examples with Huffman <xref
target="response.examples.with.huffman"/>).
</t>
<t>
The EOS symbol is represented with value 256, and is
used solely to signal the end of the Huffman-encoded
key data or the end of the Huffman-encoded value data.
Given that only between 0-7 bits of the EOS symbol is
included in any Huffman-encoded string, and given that
the EOS symbol is at least 8 bits long, it is expected
that it should never be successfully decoded.
</t>
<figure title="String Literal with Huffman Encoding">
<artwork type="inline"><![CDATA[
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| 1 | Value Length Prefix (7) |
+---+---+---+---+---+---+---+---+
| Value Length (0-N octets) |
+---+---+---+---+---+---+---+---+
...
+---+---+---+---+---+---+---+---+
| Huffman Encoded Data |Padding|
+---+---+---+---+---+---+---+---+
]]></artwork>
</figure>
<figure title="String Literal without Huffman Encoding">
<artwork type="inline"><![CDATA[
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| 0 | Value Length Prefix (7) |
+---+---+---+---+---+---+---+---+
| Value Length (0-N octets) |
+---+---+---+---+---+---+---+---+
...
+---+---+---+---+---+---+---+---+
| Field Bytes without Encoding |
+---+---+---+---+---+---+---+---+
]]></artwork>
</figure>
</section>
</section>
<section title="Indexed Header Field Representation"
anchor="indexed.header.representation">
<t>
An indexed header field representation either identifies an
entry in the header table or static table. The processing
of an indexed header field representation is described in
<xref target="header.representation.processing"/>.
</t>
<figure title="Indexed Header Field">
<artwork type="inline"><![CDATA[
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| 1 | Index (7+) |
+---+---------------------------+
]]></artwork>
</figure>
<t>
This representation starts with the '1' 1-bit pattern,
followed by the index of the matching pair, represented as
an integer with a 7-bit prefix.
</t>
<t>
The index value of 0 is reserved for signalling changes in
the encoding context (see <xref
target="encoding.context.update" />).
</t>
</section>
<section title="Literal Header Field Representation"
anchor="literal.header.representation">
<t>
Literal header field representations contain a literal
header field value. Header field names are either
provided as a literal or by reference to an existing
header table or static table entry.
</t>
<t>
Literal representations all result in the emission of a
header field when decoded.
</t>
<section title="Literal Header Field without Indexing"
anchor="literal.header.without.indexing">
<t>
A literal header field without indexing causes the
emission of a header field without altering the header
table.
</t>
<figure title="Literal Header Field without Indexing - Indexed Name">
<artwork type="inline"><![CDATA[
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| 0 | 1 | Index (6+) |
+---+---+---+-------------------+
| H | Value Length (7+) |
+---+---------------------------+
| Value String (Length octets) |
+-------------------------------+
]]></artwork>
</figure>
<figure title="Literal Header Field without Indexing - New Name">
<artwork type="inline"><![CDATA[
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| 0 | 1 | 0 |
+---+---+---+-------------------+
| H | Name Length (7+) |
+---+---------------------------+
| Name String (Length octets) |
+---+---------------------------+
| H | Value Length (7+) |
+---+---------------------------+
| Value String (Length octets) |
+-------------------------------+
]]></artwork>
</figure>
<t>
This representation starts with the '01' 2-bit pattern.
</t>
<t>
If the header field name matches the header field name
of a (name, value) pair stored in the Header Table or
Static Table, the header field name can be represented
using the index of that entry. In this case, the index
of the entry, index (which is strictly greater than 0),
is represented as an integer with a 6-bit prefix (see
<xref target="integer.representation"/>).
</t>
<t>
Otherwise, the header field name is represented as a
literal. The value 0 is represented on 6 bits followed
by the header field name (see <xref
target="string.literal.representation" />).
</t>
<t>
The header field name representation is followed by
the header field value represented as a literal string
as described in <xref
target="string.literal.representation" />.
</t>
</section>
<section title="Literal Header Field with Incremental Indexing"
anchor="literal.header.with.incremental.indexing">
<t>
A literal header field with incremental indexing adds
a new entry to the header table.
</t>
<figure title="Literal Header Field with Incremental Indexing -
Indexed Name">
<artwork type="inline"><![CDATA[
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| 0 | 0 | Index (6+) |
+---+---+---+-------------------+
| H | Value Length (7+) |
+---+---------------------------+
| Value String (Length octets) |
+-------------------------------+
]]></artwork>
</figure>
<figure title="Literal Header Field with Incremental Indexing -
New Name">
<artwork type="inline"><![CDATA[
0 1 2 3 4 5 6 7