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", "/")