-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrfc7232.xml
executable file
·1553 lines (1482 loc) · 69.4 KB
/
rfc7232.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='rfc2629.xslt'?>
<!DOCTYPE rfc [
<!ENTITY MAY "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>MAY</bcp14>">
<!ENTITY MUST "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>MUST</bcp14>">
<!ENTITY MUST-NOT "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>MUST NOT</bcp14>">
<!ENTITY OPTIONAL "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>OPTIONAL</bcp14>">
<!ENTITY RECOMMENDED "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>RECOMMENDED</bcp14>">
<!ENTITY REQUIRED "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>REQUIRED</bcp14>">
<!ENTITY SHALL "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>SHALL</bcp14>">
<!ENTITY SHALL-NOT "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>SHALL NOT</bcp14>">
<!ENTITY SHOULD "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>SHOULD</bcp14>">
<!ENTITY SHOULD-NOT "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>SHOULD NOT</bcp14>">
<!ENTITY mdash "—">
<!ENTITY Note "<x:h xmlns:x='http://purl.org/net/xml2rfc/ext'>Note:</x:h>">
<!ENTITY architecture "<xref target='RFC7230' x:rel='#architecture' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY conformance "<xref target='RFC7230' x:rel='#conformance' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY notation "<xref target='RFC7230' x:rel='#notation' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY abnf-extension "<xref target='RFC7230' x:rel='#abnf.extension' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY acks "<xref target='RFC7230' x:rel='#acks' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY whitespace "<xref target='RFC7230' x:rel='#whitespace' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY field-components "<xref target='RFC7230' x:rel='#field.components' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY header-date "<xref target='RFC7231' x:rel='#header.date' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY safe-methods "<xref target='RFC7231' x:rel='#safe.methods' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY representation "<xref target='RFC7231' x:rel='#representations' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY messaging "<xref target='RFC7230' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY semantics "<xref target='RFC7231' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY caching "<xref target='RFC7234' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY cache-key "<xref target='RFC7234' x:rel='#constructing.responses.from.caches' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY cache-validation-received "<xref target='RFC7234' x:rel='#validation.received' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY freshening-responses "<xref target='RFC7234' x:rel='#freshening.responses' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY header-accept-encoding "<xref target='RFC7231' x:rel='#header.accept-encoding' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY header-if-range "<xref target='RFC7233' x:rel='#header.if-range' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY header-range "<xref target='RFC7233' x:rel='#header.range' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY header-vary "<xref target='RFC7231' x:rel='#header.vary' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY http-date "<xref target='RFC7231' x:rel='#http.date' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY transfer-codings "<xref target='RFC7230' x:rel='#transfer.codings' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
<!ENTITY content-negotiation "<xref target='RFC7231' x:rel='#content.negotiation' xmlns:x='http://purl.org/net/xml2rfc/ext'/>">
]>
<?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-references-in-index="yes" ?>
<rfc obsoletes="2616" category="std" x:maturity-level="proposed"
ipr="pre5378Trust200902" number="7232" consensus="yes"
xmlns:x='http://purl.org/net/xml2rfc/ext'>
<x:link rel="prev" basename="rfc7231"/>
<x:link rel="next" basename="rfc7233"/>
<!--<x:feedback template="mailto:[email protected]?subject={docname},%20%22{section}%22&body=<{ref}>:"/>-->
<front>
<title abbrev="HTTP/1.1 Conditional Requests">Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests</title>
<author initials="R." surname="Fielding" fullname="Roy T. Fielding" role="editor">
<organization abbrev="Adobe">Adobe Systems Incorporated</organization>
<address>
<postal>
<street>345 Park Ave</street>
<city>San Jose</city>
<region>CA</region>
<code>95110</code>
<country>USA</country>
</postal>
<email>[email protected]</email>
<uri>http://roy.gbiv.com/</uri>
</address>
</author>
<author initials="J. F." surname="Reschke" fullname="Julian F. Reschke" role="editor">
<organization abbrev="greenbytes">greenbytes GmbH</organization>
<address>
<postal>
<street>Hafenweg 16</street>
<city>Muenster</city><region>NW</region><code>48155</code>
<country>Germany</country>
</postal>
<email>[email protected]</email>
<uri>http://greenbytes.de/tech/webdav/</uri>
</address>
</author>
<date month="June" year="2014"/>
<area>Applications</area>
<workgroup>HTTPbis</workgroup>
<keyword>Hypertext Transfer Protocol</keyword>
<keyword>HTTP</keyword>
<keyword>HTTP conditional requests</keyword>
<abstract>
<t>
The Hypertext Transfer Protocol (HTTP) is a stateless application-level protocol for
distributed, collaborative, hypertext information systems. This document
defines HTTP/1.1 conditional requests, including metadata header fields
for indicating state changes, request header fields for making
preconditions on such state, and rules for constructing the responses to a
conditional request when one or more preconditions evaluate to false.
</t>
</abstract>
</front>
<middle>
<section title="Introduction" anchor="introduction">
<t>
Conditional requests are HTTP requests <xref target="RFC7231"/> that include
one or more header fields indicating a precondition to be tested before
applying the method semantics to the target resource.
This document defines the HTTP/1.1 conditional request mechanisms in terms
of the architecture, syntax notation, and conformance criteria defined in
<xref target="RFC7230"/>.
</t>
<t>
Conditional GET requests are the most efficient mechanism for HTTP
cache updates &caching;. Conditionals can also be
applied to state-changing methods, such as PUT and DELETE, to prevent
the "lost update" problem: one client accidentally overwriting
the work of another client that has been acting in parallel.
</t>
<t><iref primary="true" item="selected representation"/>
Conditional request preconditions are based on the state of the target
resource as a whole (its current value set) or the state as observed
in a previously obtained representation (one value in that set).
A resource might have multiple current representations, each with its
own observable state. The conditional request mechanisms assume that
the mapping of requests to a "selected representation" (&representation;)
will be consistent over time if the server intends to take advantage of
conditionals. Regardless, if the mapping is inconsistent and the server is
unable to select the appropriate representation, then no harm will result
when the precondition evaluates to false.
</t>
<t>
The conditional request preconditions defined by this specification
(<xref target="preconditions"/>) are evaluated when applicable to the
recipient (<xref target="evaluation"/>) according to their order of
precedence (<xref target="precedence"/>).
</t>
<section title="Conformance and Error Handling" anchor="conformance">
<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>
<t>
Conformance criteria and considerations regarding error handling
are defined in &conformance;.
</t>
</section>
<section title="Syntax Notation" anchor="notation">
<t>
This specification uses the Augmented Backus-Naur Form (ABNF) notation of
<xref target="RFC5234"/> with a list extension, defined in
&abnf-extension;, that allows for compact definition of
comma-separated lists using a '#' operator (similar to how the '*' operator
indicates repetition).
<xref target="imported.abnf"/> describes rules imported from
other documents.
<xref target="collected.abnf"/> shows the collected grammar with all list
operators expanded to standard ABNF notation.
</t>
</section>
</section>
<section title="Validators" anchor="validators">
<iref primary="true" item="metadata"/>
<iref primary="true" item="validator"/>
<t>
This specification defines two forms of metadata that are commonly used
to observe resource state and test for preconditions: modification dates
(<xref target="header.last-modified"/>) and opaque entity tags
(<xref target="header.etag"/>). Additional metadata that reflects resource state
has been defined by various extensions of HTTP, such as Web Distributed
Authoring and Versioning (WebDAV, <xref target="RFC4918"/>), that are beyond the scope of this specification.
A resource metadata value is referred to as a "<x:dfn>validator</x:dfn>"
when it is used within a precondition.
</t>
<section title="Weak versus Strong" anchor="weak.and.strong.validators">
<iref primary="true" item="validator" subitem="weak"/>
<iref primary="true" item="validator" subitem="strong"/>
<t>
Validators come in two flavors: strong or weak. Weak validators are easy
to generate but are far less useful for comparisons. Strong validators
are ideal for comparisons but can be very difficult (and occasionally
impossible) to generate efficiently. Rather than impose that all forms
of resource adhere to the same strength of validator, HTTP exposes the
type of validator in use and imposes restrictions on when weak validators
can be used as preconditions.
</t>
<t>
A "strong validator" is representation metadata that changes value whenever
a change occurs to the representation data that would be observable in the
payload body of a <x:ref>200 (OK)</x:ref> response to GET.
</t>
<t>
A strong validator might change for reasons other than a change to the
representation data, such as when a
semantically significant part of the representation metadata is changed
(e.g., <x:ref>Content-Type</x:ref>), but it is in the best interests of the
origin server to only change the value when it is necessary to invalidate
the stored responses held by remote caches and authoring tools.
</t>
<t>
Cache entries might persist for arbitrarily long periods, regardless
of expiration times. Thus, a cache might attempt to validate an
entry using a validator that it obtained in the distant past.
A strong validator is unique across all versions of all
representations associated with a particular resource over time.
However, there is no implication of uniqueness across representations
of different resources (i.e., the same strong validator might be
in use for representations of multiple resources at the same time
and does not imply that those representations are equivalent).
</t>
<t>
There are a variety of strong validators used in practice. The best are
based on strict revision control, wherein each change to a representation
always results in a unique node name and revision identifier being assigned
before the representation is made accessible to GET. A collision-resistant hash
function applied to the representation data is also sufficient if the data
is available prior to the response header fields being sent and the digest
does not need to be recalculated every time a validation request is
received. However, if a resource has distinct representations that differ
only in their metadata, such as might occur with content negotiation over
media types that happen to share the same data format, then the origin
server needs to incorporate additional information in the validator to
distinguish those representations.
</t>
<t>
In contrast, a "weak validator" is representation metadata that
might not change for every change to the representation data. This
weakness might be due to limitations in how the value is calculated, such
as clock resolution, an inability to ensure uniqueness for all possible
representations of the resource, or a desire of the resource owner
to group representations by some self-determined set of equivalency
rather than unique sequences of data. An origin server &SHOULD; change a
weak entity-tag whenever it considers prior representations to be
unacceptable as a substitute for the current representation. In other words,
a weak entity-tag ought to change whenever the origin server wants caches to
invalidate old responses.
</t>
<t>
For example, the representation of a weather report that changes in
content every second, based on dynamic measurements, might be grouped
into sets of equivalent representations (from the origin server's
perspective) with the same weak validator in order to allow cached
representations to be valid for a reasonable period of time (perhaps
adjusted dynamically based on server load or weather quality).
Likewise, a representation's modification time, if defined with only
one-second resolution, might be a weak validator if it is possible
for the representation to be modified twice during a single second and
retrieved between those modifications.
</t>
<t>
Likewise, a validator is weak if it is shared by two or more
representations of a given resource at the same time, unless those
representations have identical representation data. For example, if the
origin server sends the same validator for a representation with a gzip
content coding applied as it does for a representation with no content
coding, then that validator is weak. However, two simultaneous
representations might share the same strong validator if they differ only
in the representation metadata, such as when two different media types are
available for the same representation data.
</t>
<t>
Strong validators are usable for all conditional requests, including cache
validation, partial content ranges, and "lost update" avoidance.
Weak validators are only usable when the client does not require exact
equality with previously obtained representation data, such as when
validating a cache entry or limiting a web traversal to recent changes.
</t>
</section>
<section title="Last-Modified" anchor="header.last-modified">
<iref primary="true" item="Last-Modified header field" x:for-anchor=""/>
<x:anchor-alias value="Last-Modified"/>
<t>
The "Last-Modified" header field in a response provides a timestamp
indicating the date and time at which the origin server believes the
selected representation was last modified, as determined at the conclusion
of handling the request.
</t>
<figure><artwork type="abnf2616"><iref primary="true" item="Grammar" subitem="Last-Modified"/>
<x:ref>Last-Modified</x:ref> = <x:ref>HTTP-date</x:ref>
</artwork></figure>
<t>
An example of its use is
</t>
<figure><artwork type="example">
Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT
</artwork></figure>
<section title="Generation" anchor="lastmod.generation">
<t>
An origin server &SHOULD; send Last-Modified for any selected
representation for which a last modification date can be reasonably
and consistently determined, since its use in conditional requests
and evaluating cache freshness (&caching;) results in a substantial
reduction of HTTP traffic on the Internet and can be a significant
factor in improving service scalability and reliability.
</t>
<t>
A representation is typically the sum of many parts behind the
resource interface. The last-modified time would usually be
the most recent time that any of those parts were changed.
How that value is determined for any given resource is an
implementation detail beyond the scope of this specification.
What matters to HTTP is how recipients of the Last-Modified
header field can use its value to make conditional requests
and test the validity of locally cached responses.
</t>
<t>
An origin server &SHOULD; obtain the Last-Modified value of the
representation as close as possible to the time that it generates the
<x:ref>Date</x:ref> field value for its response. This allows a recipient to
make an accurate assessment of the representation's modification time,
especially if the representation changes near the time that the
response is generated.
</t>
<t>
An origin server with a clock &MUST-NOT; send a Last-Modified date
that is later than the server's time of message origination (<x:ref>Date</x:ref>).
If the last modification time is derived from implementation-specific
metadata that evaluates to some time in the future, according to the
origin server's clock, then the origin server &MUST; replace that
value with the message origination date. This prevents a future
modification date from having an adverse impact on cache validation.
</t>
<t>
An origin server without a clock &MUST-NOT; assign Last-Modified
values to a response unless these values were associated
with the resource by some other system or user with a reliable clock.
</t>
</section>
<section title="Comparison" anchor="lastmod.comparison">
<t>
A Last-Modified time, when used as a validator in a request, is
implicitly weak unless it is possible to deduce that it is strong,
using the following rules:
<list style="symbols">
<t>The validator is being compared by an origin server to the
actual current validator for the representation and,</t>
<t>That origin server reliably knows that the associated representation did
not change twice during the second covered by the presented
validator.</t>
</list>
</t>
<t>
or
<list style="symbols">
<t>The validator is about to be used by a client in an <x:ref>If-Modified-Since</x:ref>,
<x:ref>If-Unmodified-Since</x:ref>, or <x:ref>If-Range</x:ref> header
field, because the client has a cache entry for the associated
representation, and</t>
<t>That cache entry includes a <x:ref>Date</x:ref> value, which gives the
time when the origin server sent the original response, and</t>
<t>The presented Last-Modified time is at least 60 seconds before
the Date value.</t>
</list>
</t>
<t>
or
<list style="symbols">
<t>The validator is being compared by an intermediate cache to the
validator stored in its cache entry for the representation, and</t>
<t>That cache entry includes a <x:ref>Date</x:ref> value, which gives the
time when the origin server sent the original response, and</t>
<t>The presented Last-Modified time is at least 60 seconds before
the Date value.</t>
</list>
</t>
<t>
This method relies on the fact that if two different responses were
sent by the origin server during the same second, but both had the
same Last-Modified time, then at least one of those responses would
have a <x:ref>Date</x:ref> value equal to its Last-Modified time. The
arbitrary 60-second limit guards against the possibility that the Date and
Last-Modified values are generated from different clocks or at somewhat
different times during the preparation of the response. An
implementation &MAY; use a value larger than 60 seconds, if it is
believed that 60 seconds is too short.
</t>
</section>
</section>
<section title="ETag" anchor="header.etag">
<iref primary="true" item="ETag header field" x:for-anchor=""/>
<x:anchor-alias value="ETag"/>
<x:anchor-alias value="entity-tag"/>
<x:anchor-alias value="opaque-tag"/>
<x:anchor-alias value="weak"/>
<x:anchor-alias value="etagc"/>
<t>
The "ETag" header field in a response provides the current entity-tag for
the selected representation, as determined at the conclusion of handling
the request.
An entity-tag is an opaque validator for differentiating between
multiple representations of the same resource, regardless of whether
those multiple representations are due to resource state changes over
time, content negotiation resulting in multiple representations being
valid at the same time, or both. An entity-tag consists of an opaque
quoted string, possibly prefixed by a weakness indicator.
</t>
<figure><artwork type="abnf2616"><iref primary="true" item="Grammar" subitem="ETag"/><iref primary="true" item="Grammar" subitem="entity-tag"/><iref primary="true" item="Grammar" subitem="weak"/><iref primary="true" item="Grammar" subitem="opaque-tag"/><iref primary="true" item="Grammar" subitem="etagc"/>
<x:ref>ETag</x:ref> = <x:ref>entity-tag</x:ref>
<x:ref>entity-tag</x:ref> = [ <x:ref>weak</x:ref> ] <x:ref>opaque-tag</x:ref>
<x:ref>weak</x:ref> = <x:abnf-char-sequence>"W/"</x:abnf-char-sequence> ; "W/", case-sensitive
<x:ref>opaque-tag</x:ref> = <x:ref>DQUOTE</x:ref> *<x:ref>etagc</x:ref> <x:ref>DQUOTE</x:ref>
<x:ref>etagc</x:ref> = %x21 / %x23-7E / <x:ref>obs-text</x:ref>
; <x:ref>VCHAR</x:ref> except double quotes, plus obs-text
</artwork></figure>
<x:note>
<t>
&Note; Previously, opaque-tag was defined to be a quoted-string
(<xref target="RFC2616" x:fmt="," x:sec="3.11"/>); thus, some recipients
might perform backslash unescaping. Servers therefore ought to avoid
backslash characters in entity tags.
</t>
</x:note>
<t>
An entity-tag can be more reliable for validation than a modification
date in situations where it is inconvenient to store modification
dates, where the one-second resolution of HTTP date values is not
sufficient, or where modification dates are not consistently maintained.
</t>
<figure><preamble>
Examples:
</preamble>
<artwork type="example">
ETag: "xyzzy"
ETag: W/"xyzzy"
ETag: ""
</artwork></figure>
<t>
An entity-tag can be either a weak or strong validator, with
strong being the default. If an origin server provides an entity-tag
for a representation and the generation of that entity-tag does not satisfy
all of the characteristics of a strong validator
(<xref target="weak.and.strong.validators"/>), then the origin server
&MUST; mark the entity-tag as weak by prefixing its opaque value
with "W/" (case-sensitive).
</t>
<section title="Generation" anchor="entity.tag.generation">
<t>
The principle behind entity-tags is that only the service author
knows the implementation of a resource well enough to select the
most accurate and efficient validation mechanism for that resource,
and that any such mechanism can be mapped to a simple sequence of
octets for easy comparison. Since the value is opaque, there is no
need for the client to be aware of how each entity-tag is constructed.
</t>
<t>
For example, a resource that has implementation-specific versioning
applied to all changes might use an internal revision number, perhaps
combined with a variance identifier for content negotiation, to
accurately differentiate between representations.
Other implementations might use a collision-resistant hash of
representation content, a combination of various file attributes, or
a modification timestamp that has sub-second resolution.
</t>
<t>
An origin server &SHOULD; send an ETag for any selected representation
for which detection of changes can be reasonably and consistently
determined, since the entity-tag's use in conditional requests and
evaluating cache freshness (&caching;) can result in a substantial
reduction of HTTP network traffic and can be a significant factor in
improving service scalability and reliability.
</t>
</section>
<section title="Comparison" anchor="entity.tag.comparison">
<x:anchor-alias value="validator.comparison"/>
<x:anchor-alias value="strong comparison"/>
<x:anchor-alias value="weak comparison"/>
<t>
There are two entity-tag comparison functions, depending on whether or not
the comparison context allows the use of weak validators:
<list style="symbols">
<t><x:dfn>Strong comparison</x:dfn>: two entity-tags are equivalent if both
are not weak and their opaque-tags match character-by-character.</t>
<t><x:dfn>Weak comparison</x:dfn>: two entity-tags are equivalent if their opaque-tags
match character-by-character, regardless of either or both
being tagged as "weak".</t>
</list>
</t>
<t>
The example below shows the results for a set of entity-tag pairs and both
the weak and strong comparison function results:
</t>
<texttable align="left">
<ttcol>ETag 1</ttcol>
<ttcol>ETag 2</ttcol>
<ttcol>Strong Comparison</ttcol>
<ttcol>Weak Comparison</ttcol>
<c>W/"1"</c>
<c>W/"1"</c>
<c>no match</c>
<c>match</c>
<c>W/"1"</c>
<c>W/"2"</c>
<c>no match</c>
<c>no match</c>
<c>W/"1"</c>
<c>"1"</c>
<c>no match</c>
<c>match</c>
<c>"1"</c>
<c>"1"</c>
<c>match</c>
<c>match</c>
</texttable>
</section>
<section title="Example: Entity-Tags Varying on Content-Negotiated Resources" anchor="example.entity.tag.vs.conneg">
<t>
Consider a resource that is subject to content negotiation
(&content-negotiation;), and where the representations sent in response to
a GET request vary based on the <x:ref>Accept-Encoding</x:ref> request
header field (&header-accept-encoding;):
</t>
<figure><preamble>>> Request:</preamble><artwork type="message/http; msgtype="request"" x:indent-with=" ">
GET /index HTTP/1.1
Host: www.example.com
Accept-Encoding: gzip
</artwork></figure>
<t>
In this case, the response might or might not use the gzip content coding.
If it does not, the response might look like:
</t>
<figure><preamble>>> Response:</preamble><artwork type="message/http; msgtype="response"" x:indent-with=" ">
HTTP/1.1 200 OK
Date: Fri, 26 Mar 2010 00:05:00 GMT
ETag: "123-a"
Content-Length: <x:length-of target="exbody"/>
Vary: Accept-Encoding
Content-Type: text/plain
<x:span anchor="exbody">Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
</x:span></artwork></figure>
<t>
An alternative representation that does use gzip content coding would be:
</t>
<figure><preamble>>> Response:</preamble><artwork type="message/http; msgtype="response"" x:indent-with=" ">
HTTP/1.1 200 OK
Date: Fri, 26 Mar 2010 00:05:00 GMT
ETag: "123-b"
Content-Length: 43
Vary: Accept-Encoding
Content-Type: text/plain
Content-Encoding: gzip
<spanx>...binary data...</spanx></artwork></figure>
<x:note>
<t>
&Note; Content codings are a property of the representation data,
so a strong entity-tag for a content-encoded representation has to be
distinct from the entity tag of an unencoded representation to prevent
potential conflicts during cache updates and range requests. In contrast,
transfer codings (&transfer-codings;) apply only during message transfer
and do not result in distinct entity-tags.
</t>
</x:note>
</section>
</section>
<section title="When to Use Entity-Tags and Last-Modified Dates" anchor="when.to.use.entity.tags.and.last-modified.dates">
<t>
In <x:ref>200 (OK)</x:ref> responses to GET or HEAD, an origin server:
<list style="symbols">
<t>&SHOULD; send an entity-tag validator unless it is not feasible to
generate one.</t>
<t>&MAY; send a weak entity-tag instead of a strong entity-tag, if
performance considerations support the use of weak entity-tags,
or if it is unfeasible to send a strong entity-tag.</t>
<t>&SHOULD; send a <x:ref>Last-Modified</x:ref> value if it is feasible to
send one.</t>
</list>
</t>
<t>
In other words, the preferred behavior for an origin server
is to send both a strong entity-tag and a <x:ref>Last-Modified</x:ref>
value in successful responses to a retrieval request.
</t>
<t>
A client:
<list style="symbols">
<t>&MUST; send that entity-tag in any cache validation request (using
<x:ref>If-Match</x:ref> or <x:ref>If-None-Match</x:ref>) if an
entity-tag has been provided by the origin server.</t>
<t>&SHOULD; send the <x:ref>Last-Modified</x:ref> value in non-subrange
cache validation requests (using <x:ref>If-Modified-Since</x:ref>)
if only a Last-Modified value has been provided by the origin server.</t>
<t>&MAY; send the <x:ref>Last-Modified</x:ref> value in subrange
cache validation requests (using <x:ref>If-Unmodified-Since</x:ref>)
if only a Last-Modified value has been provided by an HTTP/1.0 origin
server. The user agent &SHOULD; provide a way to disable this, in case
of difficulty.</t>
<t>&SHOULD; send both validators in cache validation requests if both an
entity-tag and a <x:ref>Last-Modified</x:ref> value have been provided
by the origin server. This allows both HTTP/1.0 and HTTP/1.1 caches to
respond appropriately.</t>
</list>
</t>
</section>
</section>
<section title="Precondition Header Fields" anchor="preconditions">
<t>
This section defines the syntax and semantics of HTTP/1.1 header fields
for applying preconditions on requests.
<xref target="evaluation"/> defines when the preconditions are applied.
<xref target="precedence"/> defines the order of evaluation when more than
one precondition is present.
</t>
<section title="If-Match" anchor="header.if-match">
<iref primary="true" item="If-Match header field" x:for-anchor=""/>
<x:anchor-alias value="If-Match"/>
<t>
The "If-Match" header field makes the request method conditional on the
recipient origin server either having at least one current
representation of the target resource, when the field-value is "*", or
having a current representation of the target resource that has an
entity-tag matching a member of the list of entity-tags provided in the
field-value.
</t>
<t>
An origin server &MUST; use the strong comparison function when comparing
entity-tags for If-Match (<xref target="entity.tag.comparison"/>), since
the client intends this precondition to prevent the method from being
applied if there have been any changes to the representation data.
</t>
<figure><artwork type="abnf2616"><iref primary="true" item="Grammar" subitem="If-Match"/>
<x:ref>If-Match</x:ref> = "*" / 1#<x:ref>entity-tag</x:ref>
</artwork></figure>
<t>
Examples:
</t>
<figure><artwork type="example">
If-Match: "xyzzy"
If-Match: "xyzzy", "r2d2xxxx", "c3piozzzz"
If-Match: *
</artwork></figure>
<t>
If-Match is most often used with state-changing methods (e.g., POST, PUT,
DELETE) to prevent accidental overwrites when multiple user agents might be
acting in parallel on the same resource (i.e., to prevent the "lost update"
problem). It can also be used with safe methods to abort a request if the
<x:ref>selected representation</x:ref> does not match one already stored
(or partially stored) from a prior request.
</t>
<t>
An origin server that receives an If-Match header field &MUST; evaluate the
condition prior to performing the method (<xref target="evaluation"/>).
If the field-value is "*", the condition is false if the origin server
does not have a current representation for the target resource.
If the field-value is a list of entity-tags, the condition is false if
none of the listed tags match the entity-tag of the selected representation.
</t>
<t>
An origin server &MUST-NOT; perform the requested method if a received
If-Match condition evaluates to false; instead, the origin server &MUST;
respond with either
a) the <x:ref>412 (Precondition Failed)</x:ref> status code or
b) one of the <x:ref>2xx (Successful)</x:ref> status codes if the origin
server has verified that a state change is being requested and the final
state is already reflected in the current state of the target resource
(i.e., the change requested by the user agent has already succeeded, but
the user agent might not be aware of it, perhaps because the prior response
was lost or a compatible change was made by some other user agent).
In the latter case, the origin server &MUST-NOT; send a validator header
field in the response unless it can verify that the request is a duplicate
of an immediately prior change made by the same user agent.
</t>
<t>
The If-Match header field can be ignored by caches and intermediaries
because it is not applicable to a stored response.
</t>
</section>
<section title="If-None-Match" anchor="header.if-none-match">
<iref primary="true" item="If-None-Match header field" x:for-anchor=""/>
<x:anchor-alias value="If-None-Match"/>
<t>
The "If-None-Match" header field makes the request method conditional on
a recipient cache or origin server either not having any current
representation of the target resource, when the field-value is "*", or
having a selected representation with an entity-tag that does not match any
of those listed in the field-value.
</t>
<t>
A recipient &MUST; use the weak comparison function when comparing
entity-tags for If-None-Match (<xref target="entity.tag.comparison"/>),
since weak entity-tags can be used for cache validation even if there have
been changes to the representation data.
</t>
<figure><artwork type="abnf2616"><iref primary="true" item="Grammar" subitem="If-None-Match"/>
<x:ref>If-None-Match</x:ref> = "*" / 1#<x:ref>entity-tag</x:ref>
</artwork></figure>
<t>
Examples:
</t>
<figure><artwork type="example">
If-None-Match: "xyzzy"
If-None-Match: W/"xyzzy"
If-None-Match: "xyzzy", "r2d2xxxx", "c3piozzzz"
If-None-Match: W/"xyzzy", W/"r2d2xxxx", W/"c3piozzzz"
If-None-Match: *
</artwork></figure>
<t>
If-None-Match is primarily used in conditional GET requests to enable
efficient updates of cached information with a minimum amount of
transaction overhead. When a client desires to update one or more stored
responses that have entity-tags, the client &SHOULD; generate an
If-None-Match header field containing a list of those entity-tags when
making a GET request; this allows recipient servers to send a
<x:ref>304 (Not Modified)</x:ref> response to indicate when one of those
stored responses matches the selected representation.
</t>
<t>
If-None-Match can also be used with a value of "*" to prevent an unsafe
request method (e.g., PUT) from inadvertently modifying an existing
representation of the target resource when the client believes that
the resource does not have a current representation (&safe-methods;).
This is a variation on the "lost update" problem that might arise if more
than one client attempts to create an initial representation for the target
resource.
</t>
<t>
An origin server that receives an If-None-Match header field &MUST;
evaluate the condition prior to performing the method
(<xref target="evaluation"/>).
If the field-value is "*", the condition is false if the origin server
has a current representation for the target resource.
If the field-value is a list of entity-tags, the condition is false if
one of the listed tags match the entity-tag of the selected representation.
</t>
<t>
An origin server &MUST-NOT; perform the requested method if the condition
evaluates to false; instead, the origin server &MUST; respond with either
a) the <x:ref>304 (Not Modified)</x:ref> status code if the request method
is GET or HEAD or b) the <x:ref>412 (Precondition Failed)</x:ref> status
code for all other request methods.
</t>
<t>
Requirements on cache handling of a received If-None-Match header field
are defined in &cache-validation-received;.
</t>
</section>
<section title="If-Modified-Since" anchor="header.if-modified-since">
<iref primary="true" item="If-Modified-Since header field" x:for-anchor=""/>
<x:anchor-alias value="If-Modified-Since"/>
<t>
The "If-Modified-Since" header field makes a GET or HEAD request method
conditional on the selected representation's modification date being more
recent than the date provided in the field-value. Transfer of the selected
representation's data is avoided if that data has not changed.
</t>
<figure><artwork type="abnf2616"><iref primary="true" item="Grammar" subitem="If-Modified-Since"/>
<x:ref>If-Modified-Since</x:ref> = <x:ref>HTTP-date</x:ref>
</artwork></figure>
<t>
An example of the field is:
</t>
<figure><artwork type="example">
If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT
</artwork></figure>
<t>
A recipient &MUST; ignore If-Modified-Since if the request contains an
<x:ref>If-None-Match</x:ref> header field; the condition in
<x:ref>If-None-Match</x:ref> is considered to be a more accurate
replacement for the condition in If-Modified-Since, and the two are only
combined for the sake of interoperating with older intermediaries that
might not implement <x:ref>If-None-Match</x:ref>.
</t>
<t>
A recipient &MUST; ignore the If-Modified-Since header field if the
received field-value is not a valid HTTP-date, or if the request method
is neither GET nor HEAD.
</t>
<t>
A recipient &MUST; interpret an If-Modified-Since field-value's timestamp
in terms of the origin server's clock.
</t>
<t>
If-Modified-Since is typically used for two distinct purposes:
1) to allow efficient updates of a cached representation that does not
have an entity-tag and 2) to limit the scope of a web traversal to resources
that have recently changed.
</t>
<t>
When used for cache updates, a cache will typically use the value of the
cached message's <x:ref>Last-Modified</x:ref> field to generate the field
value of If-Modified-Since. This behavior is most interoperable for cases
where clocks are poorly synchronized or when the server has chosen to only
honor exact timestamp matches (due to a problem with Last-Modified dates
that appear to go "back in time" when the origin server's clock is
corrected or a representation is restored from an archived backup).
However, caches occasionally generate the field value based on other data,
such as the <x:ref>Date</x:ref> header field of the cached message or the
local clock time that the message was received, particularly when the
cached message does not contain a <x:ref>Last-Modified</x:ref> field.
</t>
<t>
When used for limiting the scope of retrieval to a recent time window, a
user agent will generate an If-Modified-Since field value based on either
its own local clock or a <x:ref>Date</x:ref> header field received from the
server in a prior response. Origin servers that choose an exact timestamp
match based on the selected representation's <x:ref>Last-Modified</x:ref>
field will not be able to help the user agent limit its data transfers to
only those changed during the specified window.
</t>
<t>
An origin server that receives an If-Modified-Since header field &SHOULD;
evaluate the condition prior to performing the method
(<xref target="evaluation"/>).
The origin server &SHOULD-NOT; perform the requested method if the selected
representation's last modification date is earlier than or equal to the
date provided in the field-value; instead, the origin server &SHOULD;
generate a <x:ref>304 (Not Modified)</x:ref> response, including only those
metadata that are useful for identifying or updating a previously cached
response.
</t>
<t>
Requirements on cache handling of a received If-Modified-Since header field
are defined in &cache-validation-received;.
</t>
</section>
<section title="If-Unmodified-Since" anchor="header.if-unmodified-since">
<iref primary="true" item="If-Unmodified-Since header field" x:for-anchor=""/>
<x:anchor-alias value="If-Unmodified-Since"/>
<t>
The "If-Unmodified-Since" header field makes the request method conditional
on the selected representation's last modification date being earlier than or
equal to the date provided in the field-value. This field accomplishes the
same purpose as <x:ref>If-Match</x:ref> for cases where the user agent does
not have an entity-tag for the representation.
</t>
<figure><artwork type="abnf2616"><iref primary="true" item="Grammar" subitem="If-Unmodified-Since"/>
<x:ref>If-Unmodified-Since</x:ref> = <x:ref>HTTP-date</x:ref>
</artwork></figure>
<t>
An example of the field is:
</t>
<figure><artwork type="example">
If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT
</artwork></figure>
<t>
A recipient &MUST; ignore If-Unmodified-Since if the request contains an
<x:ref>If-Match</x:ref> header field; the condition in
<x:ref>If-Match</x:ref> is considered to be a more accurate replacement for
the condition in If-Unmodified-Since, and the two are only combined for the
sake of interoperating with older intermediaries that might not implement
<x:ref>If-Match</x:ref>.
</t>
<t>
A recipient &MUST; ignore the If-Unmodified-Since header field if the
received field-value is not a valid HTTP-date.
</t>
<t>
A recipient &MUST; interpret an If-Unmodified-Since field-value's timestamp
in terms of the origin server's clock.
</t>
<t>
If-Unmodified-Since is most often used with state-changing methods
(e.g., POST, PUT, DELETE) to prevent accidental overwrites when multiple
user agents might be acting in parallel on a resource that does
not supply entity-tags with its representations (i.e., to prevent the
"lost update" problem). It can also be used with safe methods to abort a
request if the <x:ref>selected representation</x:ref> does not match one
already stored (or partially stored) from a prior request.
</t>
<t>
An origin server that receives an If-Unmodified-Since header field &MUST;
evaluate the condition prior to performing the method
(<xref target="evaluation"/>).
The origin server &MUST-NOT; perform the requested method if the selected
representation's last modification date is more recent than the date
provided in the field-value; instead the origin server &MUST; respond with either
a) the <x:ref>412 (Precondition Failed)</x:ref> status code or
b) one of the <x:ref>2xx (Successful)</x:ref> status codes if the origin
server has verified that a state change is being requested and the final
state is already reflected in the current state of the target resource
(i.e., the change requested by the user agent has already succeeded, but
the user agent might not be aware of that because the prior response message
was lost or a compatible change was made by some other user agent).
In the latter case, the origin server &MUST-NOT; send a validator header
field in the response unless it can verify that the request is a duplicate
of an immediately prior change made by the same user agent.
</t>
<t>
The If-Unmodified-Since header field can be ignored by caches and
intermediaries because it is not applicable to a stored response.
</t>
</section>
<section title="If-Range" anchor="header.if-range">
<t>
The "If-Range" header field provides a special conditional request
mechanism that is similar to the <x:ref>If-Match</x:ref> and
<x:ref>If-Unmodified-Since</x:ref> header fields but that instructs the
recipient to ignore the <x:ref>Range</x:ref> header field if the validator
doesn't match, resulting in transfer of the new selected representation
instead of a <x:ref>412 (Precondition Failed)</x:ref> response. If-Range is
defined in &header-if-range;.
</t>
</section>
</section>
<section title="Status Code Definitions" anchor="status.code.definitions">
<section title="304 Not Modified" anchor="status.304">
<iref primary="true" item="304 Not Modified (status code)" x:for-anchor=""/>
<x:anchor-alias value="304"/>
<x:anchor-alias value="304 (Not Modified)"/>
<t>
The <x:dfn>304 (Not Modified)</x:dfn> status code indicates that a
conditional GET or HEAD request has been
received and would have resulted in a <x:ref>200 (OK)</x:ref> response
if it were not for the fact that the condition evaluated to false.
In other words, there is no need for the server to transfer a
representation of the target resource because the request indicates that
the client, which made the request conditional, already has a valid
representation; the server is therefore redirecting the client to make
use of that stored representation as if it were the payload of a
<x:ref>200 (OK)</x:ref> response.
</t>
<t>
The server generating a 304 response &MUST; generate any of the following
header fields that would have been sent in a <x:ref>200 (OK)</x:ref>
response to the same request:
<x:ref>Cache-Control</x:ref>,
<x:ref>Content-Location</x:ref>,
<x:ref>Date</x:ref>,
<x:ref>ETag</x:ref>,
<x:ref>Expires</x:ref>, and
<x:ref>Vary</x:ref>.
</t>
<t>
Since the goal of a 304 response is to minimize information transfer
when the recipient already has one or more cached representations,
a sender &SHOULD-NOT; generate representation metadata other
than the above listed fields unless said metadata exists for the
purpose of guiding cache updates (e.g., <x:ref>Last-Modified</x:ref> might
be useful if the response does not have an <x:ref>ETag</x:ref> field).
</t>
<t>
Requirements on a cache that receives a 304 response are defined in
&freshening-responses;. If the conditional request originated with an
outbound client, such as a user agent with its own cache sending a
conditional GET to a shared proxy, then the proxy &SHOULD; forward the
304 response to that client.
</t>
<t>
A 304 response cannot contain a message-body; it is always
terminated by the first empty line after the header fields.
</t>
</section>
<section title="412 Precondition Failed" anchor="status.412">
<iref primary="true" item="412 Precondition Failed (status code)" x:for-anchor=""/>
<x:anchor-alias value="412 (Precondition Failed)"/>
<t>
The <x:dfn>412 (Precondition Failed)</x:dfn> status code indicates that one
or more conditions given in the request header fields evaluated to false
when tested on the server. This response code allows the client to place
preconditions on the current resource state (its current representations
and metadata) and, thus, prevent the request method from being applied if the
target resource is in an unexpected state.
</t>
</section>
</section>