forked from httpwg/http-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraft-ietf-httpbis-safe-method-w-body.xml
More file actions
1513 lines (1445 loc) · 64 KB
/
draft-ietf-httpbis-safe-method-w-body.xml
File metadata and controls
1513 lines (1445 loc) · 64 KB
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"?>
<?rfc toc="yes"?>
<?rfc strict="yes"?>
<?rfc symrefs="yes" ?>
<?rfc sortrefs="yes"?>
<?rfc compact="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc-ext xml2rfc-backend="202007"?>
<?github-issue-label query-method?>
<!DOCTYPE rfc [
<!ENTITY MAY "<bcp14>MAY</bcp14>">
<!ENTITY MUST "<bcp14>MUST</bcp14>">
<!ENTITY MUST-NOT "<bcp14>MUST NOT</bcp14>">
<!ENTITY OPTIONAL "<bcp14>OPTIONAL</bcp14>">
<!ENTITY RECOMMENDED "<bcp14>RECOMMENDED</bcp14>">
<!ENTITY REQUIRED "<bcp14>REQUIRED</bcp14>">
<!ENTITY SHALL "<bcp14>SHALL</bcp14>">
<!ENTITY SHALL-NOT "<bcp14>SHALL NOT</bcp14>">
<!ENTITY SHOULD "<bcp14>SHOULD</bcp14>">
<!ENTITY SHOULD-NOT "<bcp14>SHOULD NOT</bcp14>">
]>
<rfc category="std" ipr="trust200902" docName="draft-ietf-httpbis-safe-method-w-body-latest" submissionType="IETF" consensus="true" version="3" xmlns:xi="http://www.w3.org/2001/XInclude">
<front>
<title>
The HTTP QUERY Method
</title>
<author initials="J." surname="Reschke" fullname="Julian Reschke">
<organization abbrev="greenbytes">greenbytes GmbH</organization>
<address>
<postal>
<street>Hafenweg 16</street>
<city>Münster</city><code>48155</code>
<country>Germany</country>
</postal>
<email>julian.reschke@greenbytes.de</email>
<uri>https://greenbytes.de/tech/webdav/</uri>
</address>
</author>
<author initials="J.M." surname="Snell" fullname="James M Snell">
<organization>Cloudflare</organization>
<address>
<email>jasnell@gmail.com</email>
</address>
</author>
<author initials="M." surname="Bishop" fullname="Mike Bishop">
<organization>Akamai</organization>
<address>
<email>mbishop@evequefou.be</email>
</address>
</author>
<date/>
<area>Web and Internet Transport</area>
<workgroup>HTTP</workgroup>
<keyword>http</keyword>
<keyword>query</keyword>
<keyword>method</keyword>
<abstract>
<t>
This specification defines the QUERY method for HTTP.
A QUERY requests that the request target process the enclosed
content in a safe/idempotent manner and then respond with the
result of that processing. This is similar to POST requests but
can be automatically repeated or restarted without concern for
partial state changes.
</t>
</abstract>
<note title="Editorial Note" removeInRFC="true">
<t>
Discussion of this draft takes place on the HTTP working group
mailing list (ietf-http-wg@w3.org), which is archived at
<eref target="https://lists.w3.org/Archives/Public/ietf-http-wg/"/>.
</t>
<t>
Working Group information can be found at <eref target="https://httpwg.org/"/>;
source code and issues list for this draft can be found at
<eref target="https://github.com/httpwg/http-extensions/labels/query-method"/>.
</t>
<t>
The changes in this draft are summarized in <xref target="changes.since.12"/>.
</t>
</note>
</front>
<middle>
<section title="Introduction" anchor="introduction">
<t>
This specification defines the HTTP QUERY request method as a means of
making a safe, idempotent request (<xref target="HTTP" section="9.2"/>) containing
content that describes how the request is to be processed by the target resource.
</t>
<t>
Most often, this is desirable when the data conveyed in a request is
too voluminous to be encoded into the request's URI. A common query pattern is:
</t>
<artwork type="http-message">
GET /feed?q=foo&limit=10&sort=-published HTTP/1.1
Host: example.org
</artwork>
<t>
However, when the data conveyed is too voluminous to be encoded in the request's URI,
this pattern becomes problematic:
</t>
<ul>
<li>often size limits are not known ahead of time because a request can pass through many uncoordinated
systems (but note that <xref section="4.1" target="HTTP"/> recommends senders and recipients to support at least 8000 octets),</li>
<li>expressing certain kinds of data in the target URI is inefficient because of the overhead of encoding that data into a valid URI,</li>
<li>request URIs are more likely to be logged than request content, and may also turn up in bookmarks,</li>
<li>encoding queries directly into the request URI effectively casts every possible combination of query inputs as distinct
resources.</li>
</ul>
<t>
As an alternative to using GET, many implementations make use of the
HTTP POST method to perform queries, as illustrated in the example
below. In this case, the input to the query operation is
passed as the request content as opposed to using the
request URI's query component.
</t>
<t>
A typical use of HTTP POST for requesting a query is:
</t>
<artwork type="http-message">
POST /feed HTTP/1.1
Host: example.org
Content-Type: application/x-www-form-urlencoded
q=foo&limit=10&sort=-published
</artwork>
<t>
This variation, however, suffers from the fact
that it is not readily apparent -- absent specific knowledge of the
resource and server to which the request is being sent -- that a safe,
idempotent query is being performed.
</t>
<t>
The QUERY method provides a solution that spans the gap between the use of GET and POST, with
the example above being expressed as:
</t>
<artwork type="http-message">
QUERY /feed HTTP/1.1
Host: example.org
Content-Type: application/x-www-form-urlencoded
q=foo&limit=10&sort=-published
</artwork>
<t>
As with POST, the input to the query operation is passed as the content of the request
rather than as part of the request URI. Unlike POST, however, the method is explicitly safe
and idempotent, allowing functions like caching and automatic retries to operate.
</t>
<t>
Recognizing the design principle that any important resource ought to be
identified by a URI, this specification describes how a server can assign URIs to both
the query itself or a specific query result, for later use in a GET request.
</t>
<t>Summarizing:</t>
<table>
<name>Summary of relevant method properties</name>
<thead>
<tr>
<th/>
<th>GET</th>
<th>QUERY</th>
<th>POST</th>
</tr>
</thead>
<tbody>
<tr>
<td>Safe</td>
<td>yes</td>
<td>yes</td>
<td>potentially no</td>
</tr>
<tr>
<td>Idempotent</td>
<td>yes</td>
<td>yes</td>
<td>potentially no</td>
</tr>
<tr>
<td>URI for query itself</td>
<td>yes (by definition)</td>
<td>optional (Location response field)</td>
<td>no</td>
</tr>
<tr>
<td>URI for query result</td>
<td>optional (Content-Location response field)</td>
<td>optional (Content-Location response field)</td>
<td>optional (Content-Location response field)</td>
</tr>
<tr>
<td>Cacheable</td>
<td>yes</td>
<td>yes</td>
<td>yes, but only for future GET or HEAD requests</td>
</tr>
<tr>
<td>Content (body)</td>
<td>"no defined semantics"</td>
<td>expected (semantics per target resource)</td>
<td>expected (semantics per target resource)</td>
</tr>
</tbody>
</table>
<section title="Terminology" anchor="terminology">
<t>
This document uses terminology defined in <xref section="3" target="HTTP"/>.
</t>
<t>
Furthermore, it uses the terms <em>URI query parameter</em> for parameters
in the query component of a URI (<xref target="HTTP" section="4.2.2"/>) and
<em>query content</em> for the request content (<xref target="HTTP" section="6.4"/>)
of a QUERY request.
</t>
</section>
<section title="Notational Conventions" anchor="notational.conventions">
<t>
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED",
"MAY", and "OPTIONAL" in this document are to be interpreted as
described in BCP 14 <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only when, they
appear in all capitals, as shown here.
</t>
</section>
</section>
<section title="QUERY" anchor="query">
<t>
The QUERY method is used to initiate a server-side query. Unlike
the GET method, which requests a
representation of the resource identified by the target URI
(as defined by <xref target="HTTP" section="7.1"/>), the QUERY
method is used to ask the target resource to perform a query operation
within the scope of that target resource.
The query operation is described by the request content.
The origin server determines the scope of the operation based on the target resource.
</t>
<t>
The content of the request and its media type define the query.
Servers <bcp14>MUST</bcp14> fail the request if the Content-Type
request field (<xref target="HTTP" sectionFormat="comma" section="8.3"/>)
is missing or is inconsistent with the request content.
</t>
<t>
As for all HTTP methods, the target URI's query part
takes part in identifying the resource being queried. Whether and how it
directly affects the result of the query is specific to the resource
and out of scope for this specification.
</t>
<t>
QUERY requests are safe with regard to the target resource
(<xref target="HTTP" sectionFormat="comma" section="9.2.1"/>) --
that is, the client does not request or expect any change to the
state of the target resource. This does not prevent the server
from creating additional HTTP resources through which additional
information can be retrieved (see Sections <xref target="content-location" format="counter"/>
and <xref target="location" format="counter"/>).
</t>
<t>
Furthermore, QUERY requests are idempotent
(<xref target="HTTP" sectionFormat="comma" section="9.2.2"/>) --
they can be retried or repeated when needed, for instance after
a connection failure.
</t>
<t>
As per <xref target="HTTP" section="15.3"/>, a 2xx (Successful) response code signals that
the request was successfully received, understood, and accepted.
</t>
<t>
In particular, a 200 (OK) response indicates that the query
was successfully processed and the results of that processing are
enclosed as the response content.
</t>
<section title="Media Types and Content Negotiation" anchor="media.types.and.conneg">
<t>
The semantics of a QUERY request depends both on the request content and the associated
metadata, such as the Media Type (<xref target="HTTP" sectionFormat="comma" section="8.3.1"/>).
In general, any problem with requests where content and metadata are inconsistent &MUST; be
rejected with a 4xx (Client Error) response (<xref target="HTTP" sectionFormat="comma" section="15.5"/>).
</t>
<t>
The list below describe various cases of failures and recommends specific status codes:
</t>
<ul>
<li>
A request lacking media type information by definition is incorrect and needs to fail
with a 4xx status code such as 400 (Client Error).
</li>
<li>
If a media type is specified, but not supported by the resource, a 415 (Unsupported Media Type)
is appropriate. This specifically includes the case where the media type is
known in principle, but lacks semantics specific to a QUERY to the target resource. In both cases,
the Accept-Query response field (<xref target="field.accept-query"/>) can be used to inform
the client of media types which are supported.
</li>
<li>
If a media type is specified, but is inconsistent with the actual request content,
a 400 (Bad Request) can be returned. That is, a server is not allowed to infer
a media type from the request content and then override a missing or "erroneous" value
("content sniffing").
</li>
<li>
If the media type is specified, is understood, and the content is indeed consistent with the
type, but the query can not be processed due to the actual contents of the query,
the status 422 (Unprocessable Content) can be used. An example would be a syntactically
correct SQL query that identifies a non-existent table.
</li>
<li>
Finally, if the client requests a specific response media type using the Accept
field (<xref target="HTTP" sectionFormat="comma" section="12.5.1"/>) which is not supported
by the resource, a status code of 406 (Not Acceptable) is appropriate.
</li>
</ul>
</section>
<section title="Equivalent Resource" anchor="equivalent-resource">
<t>
The <em>equivalent resource</em> for any given QUERY request is a resource
responding to GET requests, representing that QUERY request and its target, taking
both message content and metadata into account (<xref target="HTTP" section="6"/>).
In particular, this includes representation metadata (<xref target="HTTP" section="8"/>),
such as the content's media type.
</t>
<t>
In other words, the equivalent resource is derived from the resource
implementing QUERY by incorporating the request content.
</t>
<t>
The term <em>equivalent resource</em> is used as a means to define
behavior for other HTTP aspects, such as selected representations. Servers can
but do not have to assign URIs to these resources (see
<xref target="URI" section="1.1"/>). If they do so, these resources will become accessible
for GET requests.
</t>
</section>
<section title="Content-Location Response Field" anchor="content-location">
<t>
A successful response (2xx, <xref target="HTTP" section="15.3"/>)
can include a Content-Location
header field containing an
identifier for a resource corresponding to the results of the
operation; see <xref target="HTTP" section="8.7"/> for details. This represents a claim from the server that a client can send
a GET request for the indicated URI to retrieve the results of the query
operation just performed. The indicated resource might be temporary.
</t>
<t>
See <xref target="example.content-location"/> for an example.
</t>
</section>
<section title="Location Response Field" anchor="location">
<t>
A server can assign a URI to the equivalent resource (<xref target="equivalent-resource"/>)
of a QUERY request. If the server does so, the URI of that resource
can be included in the Location header field of the 2xx response (see <xref
target="HTTP" section="10.2.2"/>). This represents a claim that a client can
send a GET request to the indicated URI to repeat the query operation just
performed without resending the query content. This resource's URI might be
temporary; if a future request fails, the client can retry using the
original QUERY request target and the previously submitted content.
</t>
<t>
See <xref target="example.location"/> for an example.
</t>
</section>
<section title="Redirection" anchor="redirection">
<t>
In some cases, the server may choose to respond indirectly to the QUERY
request by redirecting the user agent to a different URI (see
<xref target="HTTP" section="15.4"/>).
</t>
<t>
A response with either of the status codes
301 (Moved Permanently, <xref target="HTTP" sectionFormat="comma" section="15.4.2"/>) or
308 (Permanent Redirect, <xref target="HTTP" sectionFormat="comma" section="15.4.9"/>)
indicates that the target resource has permanently moved to a different URI referenced by the
Location response field (<xref target="HTTP" sectionFormat="comma" section="10.2.2"/>).
Likewise, a response with either
302 (Found, <xref target="HTTP" sectionFormat="comma" section="15.4.3"/> or
307 (Temporary Redirect, <xref target="HTTP" sectionFormat="comma" section="15.4.8"/>)
indicates that the target resource has temporarily moved. In all four cases, the server is
suggesting that the user agent can accomplish its original QUERY request by sending a
similar QUERY request to the new target URI referenced by Location.
</t>
<t>
Note that the exceptions for redirecting a POST as a GET request after a 301 or 302 response
do not apply to QUERY requests.
</t>
<t>
A response to QUERY with the status code 303 (See Other, <xref target="HTTP" section="15.4.4"/>)
indicates that the original query can be accomplished via a normal retrieval request on the URI referenced
by the Location response field (<xref target="HTTP" sectionFormat="comma" section="10.2.2"/>).
For HTTP, this means sending a GET request to the new target URI, as illustrated by the example
in <xref target="example.indirect"/>.
</t>
</section>
<section title="Conditional Requests" anchor="conditional">
<t>
The selected representation (<xref target="HTTP" section="3.2"/>) of a QUERY
request is the same as for a GET request to the equivalent resource
(<xref target="equivalent-resource"/>) of that QUERY request.
</t>
<t>
A conditional QUERY requests that that selected representation
(i.e., the query results, after any content negotiation) be
returned in the response only under the circumstances described by the
conditional header field(s), as defined in
<xref target="HTTP" section="13"/>.
</t>
<t>
See <xref target="example.conditional"/> for examples.
</t>
</section>
<section title="Caching" anchor="caching">
<t>
The response to a QUERY method is cacheable; a cache &MAY; use it to satisfy subsequent
QUERY requests as per <xref target="HTTP-CACHING" section="4"/>).
</t>
<t>
The cache key for a QUERY request (see <xref target="HTTP-CACHING" section="2"/>) &MUST;
incorporate the request content (<xref target="HTTP-CACHING" section="6"/>) and related
metadata (<xref target="HTTP-CACHING" section="8"/>).
</t>
<t>
Caches <bcp14>MAY</bcp14> remove semantically insignificant differences first, thereby
improving cache efficiency.
</t>
<t>
For instance, by
</t>
<ul>
<li>removing content encoding(s) (<xref target="HTTP" section="8.4"/>).</li>
<li>normalizing based upon knowledge of format conventions, as indicated by any
media subtype suffix in the request's Content-Type field (e.g., "+json", see
<xref target="RFC6838" section="4.2.8"/>).</li>
<li>normalizing based upon knowledge of the semantics of the content itself, as indicated by
the request's Content-Type field.</li>
</ul>
<t>
Note that any such transformation is performed solely for the purpose of generating a cache key; it
does not change the request itself.
</t>
<t>
Clients can indicate, using the "no-transform" cache directive (<xref target="HTTP-CACHING" section="5.2.1.6"/>),
that they wish that no such transformation happens (but note that this directive is just
advisory).
</t>
<t>
Note that caching QUERY method responses is inherently more complex than caching responses
to GET, as complete reading of the request's content is needed in order to determine
the cache key. If a QUERY response supplies a Location response field (<xref target="location"/>)
to indicate a URI for an equivalent resource (<xref target="equivalent-resource"/>), clients
can switch to GET for subsequent requests, thereby simplifying processing.
</t>
</section>
<section title="Range Requests" anchor="range">
<t>
The semantics of Range Requests for QUERY are identical to those for GET,
as defined in <xref target="HTTP" section="14"/>.
Byte Range requests (the only range unit defined at the time of writing),
however, offer little value for the results of a QUERY request.
</t>
<t>
Query formats often define their own way for limiting or paging through result
sets, such as with "FETCH FIRST ... ROWS ONLY" in SQL. It is expected that these
built-in features will be used instead of HTTP Range Requests.
</t>
</section>
</section>
<section title="The "Accept-Query" Header Field" anchor="field.accept-query">
<t>
The "Accept-Query" response header field can be used by a resource to
directly signal support for the QUERY method while identifying
the specific query format media type(s) that may be used.
</t>
<t>
Accept-Query contains a list of media ranges (<xref target="HTTP" section="12.5.1"/>)
using "Structured Fields" syntax (<xref target="STRUCTURED-FIELDS"/>).
Media ranges are represented by a List Structured Header Field of either Tokens or
Strings, containing the media range value without parameters.
</t>
<t>
Media type parameters, if any, are mapped to Structured Field Parameters of type
String or Token. The choice of Token vs. String is semantically insignificant. That is,
recipients &MAY; convert Tokens to Strings, but &MUST-NOT; process them
differently based on the received type.
</t>
<t>
Media types do not exactly map to Tokens, for instance they
allow a leading digit. In cases like these, the String format needs to
be used.
</t>
<t>
The only supported uses of wildcards are "*/*", which matches any type,
or "xxxx/*", which matches any subtype of the indicated type.
</t>
<t>
The order of types listed in the field value is not significant.
</t>
<t>
The value of the Accept-Query field applies to every URI on the server that shares the same path; in
other words, the query component is ignored. If requests to the same resource return
different Accept-Query values, the most recently received fresh value (per
<xref target="HTTP-CACHING" section="4.2"/>) is used.
</t>
<t>
Example:
</t>
<artwork type="example">
Accept-Query: "application/jsonpath", application/sql;charset="UTF-8"</artwork>
<t>
Although the syntax for this field appears to be similar to other
fields, such as "Accept" (<xref target="HTTP" section="12.5.1"/>),
it is a Structured Field and thus &MUST; be processed as specified in
<xref target="STRUCTURED-FIELDS" section="4"/>.
</t>
</section>
<section title="Security Considerations">
<t>
The QUERY method is subject to the same general security
considerations as all HTTP methods as described in
<xref target="HTTP"/>.
</t>
<t>
It can be used as an alternative to passing request
information in the URI (e.g., in the query component). This is preferred in some
cases, as the URI is more likely to be logged or otherwise processed
by intermediaries than the request content. In other cases, where the query
contains sensitive information, the potential for logging of the URI might
motivate the use of QUERY over GET.
</t>
<t>
If a server creates a temporary resource to represent the results of a QUERY
request (e.g., for use in the Location or Content-Location field) and the request
contains sensitive information that cannot be logged, then the URI of this
resource &SHOULD; be chosen such that it does not include any sensitive
portions of the original request content.
</t>
<t>
Caches that normalize QUERY content incorrectly or in ways that are
significantly different from how the resource processes the content
can return an incorrect response if normalization results in a false positive.
</t>
<t>
A QUERY request from user agents implementing CORS (Cross-Origin Resource Sharing)
will require a "preflight" request,
as QUERY does not belong to the set of CORS-safelisted methods
(see "<eref target="https://fetch.spec.whatwg.org/#methods">Methods</eref>" in
<xref target="FETCH"/>).
</t>
</section>
<section title="IANA Considerations" anchor="iana.considerations">
<section title="Registration of QUERY method" anchor="method.registration">
<t>
IANA is requested to add the QUERY method to the HTTP
Method Registry at <eref brackets="angle" target="http://www.iana.org/assignments/http-methods"/>
(see <xref target="HTTP" section="16.3.1"/>).
</t>
<table>
<name>QUERY Method Definition</name>
<thead>
<tr>
<th>Method Name</th>
<th>Safe</th>
<th>Idempotent</th>
<th>Specification</th>
</tr>
</thead>
<tbody>
<tr>
<td>QUERY</td>
<td>Yes</td>
<td>Yes</td>
<td><xref target="query"/></td>
</tr>
</tbody>
</table>
</section>
<section title="Registration of Accept-Query field" anchor="field.registration">
<t>
IANA is requested to add the Accept-Query field to the HTTP Field Name
Registry at <eref brackets="angle" target="https://www.iana.org/assignments/http-fields"/>
(see <xref target="HTTP" section="16.1.1"/>).
</t>
<table>
<name>Accept-Query Field Definition</name>
<thead>
<tr>
<th>Field Name</th>
<th>Status</th>
<th>Structured Type</th>
<th>Reference</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td>Accept-Query</td>
<td>permanent</td>
<td>List</td>
<td><xref target="field.accept-query"/> of this document.</td>
<td></td>
</tr>
</tbody>
</table>
</section>
</section>
</middle>
<back>
<references title="Normative References">
<xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.2119.xml"/>
<xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8174.xml"/>
<reference anchor="HTTP">
<front>
<title>HTTP Semantics</title>
<author fullname="Roy T. Fielding" initials="R." surname="Fielding" role="editor"/>
<author fullname="Mark Nottingham" initials="M." surname="Nottingham" role="editor"/>
<author fullname="Julian Reschke" initials="J." surname="Reschke" role="editor"/>
<date year="2022" month="June"/>
</front>
<seriesInfo name="STD" value="97"/>
<seriesInfo name="RFC" value="9110"/>
</reference>
<reference anchor="HTTP-CACHING">
<front>
<title>HTTP Caching</title>
<author fullname="Roy T. Fielding" initials="R." surname="Fielding" role="editor"/>
<author fullname="Mark Nottingham" initials="M." surname="Nottingham" role="editor"/>
<author fullname="Julian Reschke" initials="J." surname="Reschke" role="editor"/>
<date year="2022" month="June"/>
</front>
<seriesInfo name="STD" value="98"/>
<seriesInfo name="RFC" value="9111"/>
</reference>
<reference anchor="STRUCTURED-FIELDS">
<front>
<title>Structured Field Values for HTTP</title>
<author initials="M." surname="Nottingham" fullname="Mark Nottingham">
<organization>Cloudflare</organization>
</author>
<author initials="P-H." surname="Kamp" fullname="Poul-Henning Kamp">
<organization>The Varnish Cache Project</organization>
</author>
<date year="2024" month="September"/>
</front>
<seriesInfo name="RFC" value="9651"/>
</reference>
</references>
<references title="Informative References">
<reference anchor="FETCH" target="https://fetch.spec.whatwg.org">
<front>
<title>FETCH</title>
<author><organization>WHATWG</organization></author>
</front>
</reference>
<xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.6838.xml"/>
<xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8259.xml"/>
<xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.9535.xml"/>
<reference anchor="URI">
<front>
<title abbrev="URI Generic Syntax">Uniform Resource Identifier (URI): Generic Syntax</title>
<author initials="T." surname="Berners-Lee" fullname="Tim Berners-Lee"/>
<author initials="R." surname="Fielding" fullname="Roy T. Fielding"/>
<author initials="L." surname="Masinter" fullname="Larry Masinter"/>
<date month="January" year="2005"/>
</front>
<seriesInfo name="STD" value="66"/>
<seriesInfo name="RFC" value="3986"/>
</reference>
<reference anchor="URL" target="https://url.spec.whatwg.org">
<front>
<title>URL</title>
<author><organization>WHATWG</organization></author>
</front>
</reference>
<reference anchor="XSLT" target='https://www.w3.org/TR/2017/REC-xslt-30-20170608/'>
<front>
<title>XSL Transformations (XSLT) Version 3.0</title>
<author fullname='Michael Kay' surname='Kay' initials='M.'/>
<date year='2017' month='June' day='08'/>
</front>
<seriesInfo name='W3C Recommendation' value='REC-xslt-30-20170608'/>
<annotation>
Latest version available at
<eref target='https://www.w3.org/TR/xslt-30/'/>.
</annotation>
</reference>
</references>
<section title="Examples" anchor="examples">
<t>
The examples below are for illustrative purposes only; if one needs to
send queries that are actually this short, it is likely better to use GET.
</t>
<t>
The media type used in most examples is "application/x-www-form-urlencoded"
(as used in POST requests from browser user clients, defined in
"<eref target="https://url.spec.whatwg.org/#application/x-www-form-urlencoded">application/x-www-form-urlencoded</eref>" in
<xref target="URL"/>).
The Content-Length fields have been omitted for brevity.
</t>
<section title="Simple Query" anchor="example.simple">
<t>A simple query with a direct response:</t>
<artwork type="http-message">
QUERY /contacts HTTP/1.1
Host: example.org
Content-Type: application/x-www-form-urlencoded
Accept: application/json
select=surname,givenname,email&limit=10&match=%22email=*@example.*%22
</artwork>
<t>Response:</t>
<artwork type="http-message">
HTTP/1.1 200 OK
Content-Type: application/json
[
{ "surname": "Smith",
"givenname": "John",
"email": "smith@example.org" },
{ "surname": "Jones",
"givenname": "Sally",
"email": "sally.jones@example.com" },
{ "surname": "Dubois",
"givenname": "Camille",
"email": "camille.dubois@example.net" }
]
</artwork>
</section>
<section title="Discovery of QUERY support" anchor="example.discovery.method">
<t>
A simple way to discover support for QUERY is provided by the OPTIONS
(<xref target="HTTP" section="9.3.7"/>) method:
</t>
<artwork type="http-message">
OPTIONS /contacts HTTP/1.1
Host: example.org
</artwork>
<t>Response:</t>
<artwork type="http-message">
HTTP/1.1 200 OK
Allow: GET, QUERY, OPTIONS, HEAD
</artwork>
<t>
The Allow response field (<xref target="HTTP" section="10.2.1"/>) denotes the set of
supported methods on the specified resource.
</t>
<t>
There are alternatives to the use of OPTIONS. For instance, a QUERY request
can be tried without prior knowledge of server support. The server would then
either process the request, or could respond with a 4xx status such as 405 (Method Not Allowed,
<xref target="HTTP" section="15.5.6"/>), including the Allow response field.
</t>
</section>
<section title="Discovery of QUERY Formats" anchor="example.discovery.formats">
<t>
Discovery of supported media types for QUERY is possible via the Accept-Query
(<xref target="field.accept-query"/>) response field:
</t>
<artwork type="http-message">
HEAD /contacts HTTP/1.1
Host: example.org
</artwork>
<t>Response:</t>
<artwork type="http-message">
HTTP/1.1 200 OK
Content-Type: application/xhtml
Accept-Query: application/x-www-form-urlencoded, application/sql
</artwork>
<t>
Responses to which request methods will contain Accept-Query will depend on
the resource being accessed.
</t>
<t>
An alternative to checking Accept-Query would be to make a QUERY request, and then
-- in case of a 4xx status such as 415 (Unsupported Media Type, <xref target="HTTP" section="15.5.16"/>) response --
to inspect the Accept (<xref target="HTTP" section="12.5.1"/>) response field:
</t>
<artwork type="http-message">
HTTP/1.1 415 Unsupported Media Type
Content-Type: application/xhtml
Accept: application/x-www-form-urlencoded, application/sql
</artwork>
</section>
<section title="Content-Location, Location, and Indirect Responses" anchor="example.content-location.location.indirect">
<t>
As described in Sections <xref format="counter" target="content-location"/> and
<xref format="counter" target="location"/>, the Content-Location and Location response fields in success responses
(2xx, <xref target="HTTP" section="15.3"/>) provide a way to identify alternate resources
that will respond to GET requests, either for the received result of the request, or for future
requests to perform the same operation. Going back to the example from <xref target="example.simple"/>:
</t>
<artwork type="http-message">
QUERY /contacts HTTP/1.1
Host: example.org
Content-Type: application/x-www-form-urlencoded
Accept: application/json
select=surname,givenname,email&limit=10&match=%22email=*@example.*%22
</artwork>
<t>Response:</t>
<artwork type="http-message">
HTTP/1.1 200 OK
Content-Type: application/json
Content-Location: /contacts/stored-results/17
Location: /contacts/stored-queries/42
Last-Modified: Sat, 25 Aug 2012 23:34:45 GMT
Date: Sun, 17 Nov 2024, 16:10:24 GMT
[
{ "surname": "Smith",
"givenname": "John",
"email": "smith@example.org" },
{ "surname": "Jones",
"givenname": "Sally",
"email": "sally.jones@example.com" },
{ "surname": "Dubois",
"givenname": "Camille",
"email": "camille.dubois@example.net" }
]
</artwork>
<section title="Using Content-Location" anchor="example.content-location">
<t>
The Content-Location response field received above identifies a resource holding
the result for the QUERY response it appeared on:
</t>
<artwork type="http-message">
GET /contacts/stored-results/17 HTTP/1.1
Host: example.org
Accept: application/json
</artwork>
<t>Response:</t>
<artwork type="http-message">
HTTP/1.1 200 OK
Last-Modified: Sat, 25 Aug 2012 23:34:45 GMT
Date: Sun, 17 Nov 2024, 16:10:25 GMT
[
{ "surname": "Smith",
"givenname": "John",
"email": "smith@example.org" },
{ "surname": "Jones",
"givenname": "Sally",
"email": "sally.jones@example.com" },
{ "surname": "Dubois",
"givenname": "Camille",
"email": "camille.dubois@example.net" }
]
</artwork>
<t>
Note that there's no guarantee that the server will implement this resource
indefinitely, so, after an error response, the client would need to redo
the original QUERY request in order to obtain a new alternative location.
</t>
</section>
<section title="Using Location" anchor="example.location">
<t>
The Location response field identifies a resource that will respond to GET
with a current result for the same process and parameters as the original
QUERY request.
</t>
<artwork type="http-message">
GET /contacts/stored-queries/42 HTTP/1.1
Host: example.org
Accept: application/json
</artwork>
<t>
In this example, one entry was removed at 2024-11-17T16:12:01Z (as indicated in
the Last-Modified field), so the response only contains two entries:
</t>
<artwork type="http-message">
HTTP/1.1 200 OK
Content-Type: application/json
Last-Modified: Sun, 17 November 2024, 16:12:01 GMT
ETag: "42-1"
Date: Sun, 17 Nov 2024, 16:13:17 GMT
[
{ "surname": "Smith",
"givenname": "John",
"email": "smith@example.org" },
{ "surname": "Dubois",
"givenname": "Camille",
"email": "camille.dubois@example.net" }
]
</artwork>
<t>
Assuming that the server still exposes the resource and that there was no change
in the query result, a subsequent conditional GET request with
</t>
<artwork type="http-message">
If-None-Match: "42-1"
</artwork>
<t>
would result in a 304 response (Not Modified, <xref target="HTTP" section="15.4.5"/>).
</t>
</section>
<section title="Indirect Responses" anchor="example.indirect">
<t>
Servers can send "indirect" responses (<xref target="redirection"/>) using the status code 303 (See Other,
<xref target="HTTP" section="15.4.4"/>).
</t>
<t>
Given the request at the beginning of <xref target="example.content-location.location.indirect"/>,
a server might respond with:
</t>
<artwork type="http-message">
HTTP/1.1 303 See Other
Content-Type: text/plain
Date: Sun, 17 Nov 2024, 16:13:17 GMT
Location: /contacts/stored-queries/42
See stored query at "/contacts/stored-queries/42".
</artwork>
<t>
This is similar to including Location on a direct response, except that no result
for the query is returned. This allows the server to only generate or reuse an alternative
resource. This resource could then be used as shown in
<xref target="example.location"/>.
</t>
</section>
</section>
<section title="Conditional Requests" anchor="example.conditional">
<t>
Consider a resource implementing QUERY that supports "application/sql" and
"application/xslt+xml" (<xref target="XSLT"/>) as request media types, and
which can generate responses as "text/csv" . The data set being queried contains RFC document
information, and the query returns information grouped by decade:
</t>
<artwork type="http-message">
QUERY /rfc-index.xml HTTP/1.1
Host: example.org
Date: Sun, 7 Sep 2025, 00:00:00 GMT
Content-Type: application/xslt+xml
Accept: text/csv
...Query content using XSLT...
</artwork>
<t>
Response:
</t>
<artwork type="http-message">
HTTP/1.1 200 OK
Date: Sun, 7 Sep 2025, 00:00:00 GMT
Location: /stored-queries/4815162342
Content-Type: text/csv
Accept-Query: "application/sql", "application/xslt+xml"
Last-Modified: Sun, 31 Aug 2025, 08:44:00 GMT
Vary: Accept-Query, Content-Encoding, Content-Type
decade, total, with errata, % with errata, average page count
1960, 26, 5, 19.2, 5.3
1970, 666, 18, 2.7, 6.1
1980, 376, 44, 11.7, 23.4
1990, 1593, 269, 16.9, 25.5
2000, 2888, 1048, 36.3, 27.3
2010, 2954, 895, 30.3, 26.1
2020, 1133, 230, 20.3, 26.2
</artwork>
<t>
Here, the server has assigned the path "/stored-queries/4815162342" to the equivalent
resource (<xref target="location"/>) for subsequent use with GET.
</t>
<t>