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
17 changes: 17 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "/")
Expand Down