From e11e7850bba14c6a5a056185d7c12c374cf51301 Mon Sep 17 00:00:00 2001 From: ivamly Date: Tue, 22 Sep 2026 20:57:40 +0300 Subject: [PATCH] Add HTTP QUERY method --- CHANGELOG.md | 1 + src/gleam/http.gleam | 5 +++++ test/gleam/http_test.gleam | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e85747..9c84fa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ API, and for incorrect use it is inconsistent with other interactions with the headers collection, so it has been removed. Always use lowercase header names. +- Added HTTP QUERY method support. ## v4.4.0 - 2026-09-01 diff --git a/src/gleam/http.gleam b/src/gleam/http.gleam index 1f2d48a..9d138b3 100644 --- a/src/gleam/http.gleam +++ b/src/gleam/http.gleam @@ -38,6 +38,9 @@ pub type Method { /// Proxies that support this should only do so for known trustworthy /// clients. Connect + /// QUERY requests a resource from a server. It is safe, idempotent, + /// cacheable, and may have a request body. + Query /// Non-standard but valid HTTP methods. Other(String) @@ -54,6 +57,7 @@ pub fn parse_method(method: String) -> Result(Method, Nil) { "POST" -> Ok(Post) "PUT" -> Ok(Put) "TRACE" -> Ok(Trace) + "QUERY" -> Ok(Query) method -> case is_valid_token(method) { True -> Ok(Other(method)) @@ -185,6 +189,7 @@ pub fn method_to_string(method: Method) -> String { Post -> "POST" Put -> "PUT" Trace -> "TRACE" + Query -> "QUERY" Other(method) -> method } } diff --git a/test/gleam/http_test.gleam b/test/gleam/http_test.gleam index 0e51d96..625ff8e 100644 --- a/test/gleam/http_test.gleam +++ b/test/gleam/http_test.gleam @@ -55,6 +55,12 @@ pub fn parse_method_test() { assert http.parse_method("trace") == Ok(http.Other("trace")) + assert http.parse_method("Query") == Ok(http.Other("Query")) + + assert http.parse_method("QUERY") == Ok(http.Query) + + assert http.parse_method("query") == Ok(http.Other("query")) + assert http.parse_method("thingy") == Ok(http.Other("thingy")) assert http.parse_method("!#$%&'*+-.^_`|~abcABC123") @@ -82,6 +88,8 @@ pub fn method_to_string_test() { assert http.method_to_string(http.Trace) == "TRACE" + assert http.method_to_string(http.Query) == "QUERY" + assert http.method_to_string(http.Other("ok")) == "ok" assert http.method_to_string(http.Other("nope")) == "nope"