Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/gleam/http.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include documentation for this new method please, matching the others 🙏

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/// Non-standard but valid HTTP methods.
Other(String)
Expand All @@ -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))
Expand Down Expand Up @@ -185,6 +189,7 @@ pub fn method_to_string(method: Method) -> String {
Post -> "POST"
Put -> "PUT"
Trace -> "TRACE"
Query -> "QUERY"
Other(method) -> method
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/gleam/http_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"
Expand Down