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 {
2020/// https://datatracker.ietf.org/doc/html/rfc7231#section-4 Initial definition
2121///
2222/// https://datatracker.ietf.org/doc/html/rfc5789#section-2 PATCH
23///
24/// https://datatracker.ietf.org/doc/html/rfc10008#name-query-method QUERY
2325pub const Method = enum {
2426 GET,
2527 HEAD,
......@@ -30,12 +32,13 @@ pub const Method = enum {
3032 OPTIONS,
3133 TRACE,
3234 PATCH,
35 QUERY,
3336
3437 /// Returns true if a request of this method is allowed to have a body
3538 /// Actual behavior from servers may vary and should still be checked
3639 pub fn requestHasBody(m: Method) bool {
3740 return switch (m) {
38 .POST, .PUT, .PATCH => true,
41 .POST, .PUT, .PATCH, .QUERY => true,
3942 .GET, .HEAD, .DELETE, .CONNECT, .OPTIONS, .TRACE => false,
4043 };
4144 }
......@@ -44,7 +47,7 @@ pub const Method = enum {
4447 /// Actual behavior from clients may vary and should still be checked
4548 pub fn responseHasBody(m: Method) bool {
4649 return switch (m) {
47 .GET, .POST, .PUT, .DELETE, .CONNECT, .OPTIONS, .PATCH => true,
50 .GET, .POST, .PUT, .DELETE, .CONNECT, .OPTIONS, .PATCH, .QUERY => true,
4851 .HEAD, .TRACE => false,
4952 };
5053 }
......@@ -56,7 +59,7 @@ pub const Method = enum {
5659 /// https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.1
5760 pub fn safe(m: Method) bool {
5861 return switch (m) {
59 .GET, .HEAD, .OPTIONS, .TRACE => true,
62 .GET, .HEAD, .OPTIONS, .TRACE, .QUERY => true,
6063 .POST, .PUT, .DELETE, .CONNECT, .PATCH => false,
6164 };
6265 }
......@@ -70,7 +73,7 @@ pub const Method = enum {
7073 /// https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.2
7174 pub fn idempotent(m: Method) bool {
7275 return switch (m) {
73 .GET, .HEAD, .PUT, .DELETE, .OPTIONS, .TRACE => true,
76 .GET, .HEAD, .PUT, .DELETE, .OPTIONS, .TRACE, .QUERY => true,
7477 .CONNECT, .POST, .PATCH => false,
7578 };
7679 }
......@@ -83,7 +86,7 @@ pub const Method = enum {
8386 /// https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.3
8487 pub fn cacheable(m: Method) bool {
8588 return switch (m) {
86 .GET, .HEAD => true,
89 .GET, .HEAD, .QUERY => true,
8790 .POST, .PUT, .DELETE, .CONNECT, .OPTIONS, .TRACE, .PATCH => false,
8891 };
8992 }