summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-01-18 23:46:35 +0700
committerShulhan <ms@kilabit.info>2024-01-18 23:46:35 +0700
commitdbfc1583d77d300f8da8e2d3714fa1592dde09a0 (patch)
treede82b832b9710b09890d85f691afd66a890d5195
parent3f26ff7582515fb13c27b366ebebcae0f88551f9 (diff)
downloadpakakeh.go-dbfc1583d77d300f8da8e2d3714fa1592dde09a0.tar.xz
lib/http: add method Head to Client
The Head method send the HEAD request to path, with optional headers, and params in query parameters.
-rw-r--r--lib/http/client.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/http/client.go b/lib/http/client.go
index 8243bc05..b404b3c4 100644
--- a/lib/http/client.go
+++ b/lib/http/client.go
@@ -291,6 +291,18 @@ func (client *Client) Get(requestPath string, headers http.Header, params url.Va
return client.doRequest(http.MethodGet, headers, requestPath, ``, nil)
}
+// Head send the HEAD request to path, with optional headers and params in
+// query parameters.
+// The returned resBody shoule be always nil.
+func (client *Client) Head(path string, headers http.Header, params url.Values) (
+ httpRes *http.Response, resBody []byte, err error,
+) {
+ if params != nil {
+ path += `?` + params.Encode()
+ }
+ return client.doRequest(http.MethodHead, headers, path, ``, nil)
+}
+
// Post send the POST request to path without setting "Content-Type".
// If the params is not nil, it will send as query parameters in the path.
func (client *Client) Post(requestPath string, headers http.Header, params url.Values) (