From 8f1cc90869d3b089a505533d5118b26bd4c8b676 Mon Sep 17 00:00:00 2001 From: thatwasyahya Date: Tue, 21 Jul 2026 11:49:11 +0200 Subject: [PATCH] feat: add Query and MustQuery for the HTTP QUERY method (RFC 10008) RFC 10008 defines QUERY, a safe and idempotent method that carries the query as request content. Query mirrors Get/Post and MustQuery mirrors MustGet. req already sends a body for non-GET/HEAD/OPTIONS methods, so SetBody(...).Query(url) works as-is. Extends TestSendMethods with a QUERY case. --- request.go | 17 +++++++++++++++++ request_test.go | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/request.go b/request.go index 7435d1f..9049bc1 100644 --- a/request.go +++ b/request.go @@ -897,6 +897,23 @@ func (r *Request) Head(url string) (*Response, error) { return r.Send(http.MethodHead, url) } +// MustQuery like Query, panic if error happens, should only be used +// to test without error handling. +func (r *Request) MustQuery(url string) *Response { + resp, err := r.Query(url) + if err != nil { + panic(err) + } + return resp +} + +// Query fires http request with QUERY method and the specified URL. QUERY is a +// safe, idempotent method that carries the query as request content, defined in +// RFC 10008. +func (r *Request) Query(url string) (*Response, error) { + return r.Send("QUERY", url) +} + // SetBody set the request Body, accepts string, []byte, io.Reader, map and struct. func (r *Request) SetBody(body any) *Request { if body == nil { diff --git a/request_test.go b/request_test.go index 2937a5d..da7d4de 100644 --- a/request_test.go +++ b/request_test.go @@ -130,6 +130,12 @@ func TestSendMethods(t *testing.T) { }, ExpectMethod: "HEAD", }, + { + SendReq: func(req *Request) (resp *Response, err error) { + return req.Query("/") + }, + ExpectMethod: "QUERY", + }, { SendReq: func(req *Request) (resp *Response, err error) { return req.Send("GET", "/")