authorgravatar for hkupty@noreply.codeberg.orgHenry Kupty <hkupty@noreply.codeberg.org> 2026-08-07 16:45:28+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-07 16:45:28+02:00
log9d27b6289b592d312618d87819d533dc6e140ccd
tree3bc42be46cd560d1e7164514809b64bcf6039554
parentce02115365759a9b7f9ccfdd8577bee20da54b84

std.http: add QUERY method (#35956)

as per [rfc10008](https://datatracker.ietf.org/doc/html/rfc10008), QUERY is a safe, cacheable and idempotent method with body ref: ziglang/zig#35955 Co-authored-by: Henry Kupty <hkuty@gmail.com> Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35956

1 files changed, 8 insertions(+), 5 deletions(-)

lib/std/http.zig+8-5
...@@ -20,6 +20,8 @@ pub const Version = enum {...@@ -20,6 +20,8 @@ pub const Version = enum {
20/// https://datatracker.ietf.org/doc/html/rfc7231#section-4 Initial definition20/// https://datatracker.ietf.org/doc/html/rfc7231#section-4 Initial definition
21///21///
22/// https://datatracker.ietf.org/doc/html/rfc5789#section-2 PATCH22/// https://datatracker.ietf.org/doc/html/rfc5789#section-2 PATCH
23///
24/// https://datatracker.ietf.org/doc/html/rfc10008#name-query-method QUERY
23pub const Method = enum {25pub const Method = enum {
24 GET,26 GET,
25 HEAD,27 HEAD,
...@@ -30,12 +32,13 @@ pub const Method = enum {...@@ -30,12 +32,13 @@ pub const Method = enum {
30 OPTIONS,32 OPTIONS,
31 TRACE,33 TRACE,
32 PATCH,34 PATCH,
35 QUERY,
3336
34 /// Returns true if a request of this method is allowed to have a body37 /// Returns true if a request of this method is allowed to have a body
35 /// Actual behavior from servers may vary and should still be checked38 /// Actual behavior from servers may vary and should still be checked
36 pub fn requestHasBody(m: Method) bool {39 pub fn requestHasBody(m: Method) bool {
37 return switch (m) {40 return switch (m) {
38 .POST, .PUT, .PATCH => true,41 .POST, .PUT, .PATCH, .QUERY => true,
39 .GET, .HEAD, .DELETE, .CONNECT, .OPTIONS, .TRACE => false,42 .GET, .HEAD, .DELETE, .CONNECT, .OPTIONS, .TRACE => false,
40 };43 };
41 }44 }
...@@ -44,7 +47,7 @@ pub const Method = enum {...@@ -44,7 +47,7 @@ pub const Method = enum {
44 /// Actual behavior from clients may vary and should still be checked47 /// Actual behavior from clients may vary and should still be checked
45 pub fn responseHasBody(m: Method) bool {48 pub fn responseHasBody(m: Method) bool {
46 return switch (m) {49 return switch (m) {
47 .GET, .POST, .PUT, .DELETE, .CONNECT, .OPTIONS, .PATCH => true,50 .GET, .POST, .PUT, .DELETE, .CONNECT, .OPTIONS, .PATCH, .QUERY => true,
48 .HEAD, .TRACE => false,51 .HEAD, .TRACE => false,
49 };52 };
50 }53 }
...@@ -56,7 +59,7 @@ pub const Method = enum {...@@ -56,7 +59,7 @@ pub const Method = enum {
56 /// https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.159 /// https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.1
57 pub fn safe(m: Method) bool {60 pub fn safe(m: Method) bool {
58 return switch (m) {61 return switch (m) {
59 .GET, .HEAD, .OPTIONS, .TRACE => true,62 .GET, .HEAD, .OPTIONS, .TRACE, .QUERY => true,
60 .POST, .PUT, .DELETE, .CONNECT, .PATCH => false,63 .POST, .PUT, .DELETE, .CONNECT, .PATCH => false,
61 };64 };
62 }65 }
...@@ -70,7 +73,7 @@ pub const Method = enum {...@@ -70,7 +73,7 @@ pub const Method = enum {
70 /// https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.273 /// https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.2
71 pub fn idempotent(m: Method) bool {74 pub fn idempotent(m: Method) bool {
72 return switch (m) {75 return switch (m) {
73 .GET, .HEAD, .PUT, .DELETE, .OPTIONS, .TRACE => true,76 .GET, .HEAD, .PUT, .DELETE, .OPTIONS, .TRACE, .QUERY => true,
74 .CONNECT, .POST, .PATCH => false,77 .CONNECT, .POST, .PATCH => false,
75 };78 };
76 }79 }
...@@ -83,7 +86,7 @@ pub const Method = enum {...@@ -83,7 +86,7 @@ pub const Method = enum {
83 /// https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.386 /// https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.3
84 pub fn cacheable(m: Method) bool {87 pub fn cacheable(m: Method) bool {
85 return switch (m) {88 return switch (m) {
86 .GET, .HEAD => true,89 .GET, .HEAD, .QUERY => true,
87 .POST, .PUT, .DELETE, .CONNECT, .OPTIONS, .TRACE, .PATCH => false,90 .POST, .PUT, .DELETE, .CONNECT, .OPTIONS, .TRACE, .PATCH => false,
88 };91 };
89 }92 }