aboutsummaryrefslogtreecommitdiff
path: root/weed/util/http_util.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-02-10 09:13:29 -0800
committerChris Lu <chris.lu@gmail.com>2020-02-10 09:13:29 -0800
commit58f126fd27bb2f366f76f42223b93ba3b31a0bd8 (patch)
treec4f784566db4689691c6824cde08a32a798cb5d5 /weed/util/http_util.go
parent29945fad51320deb7c72f57d1c7a84bcc51429da (diff)
downloadseaweedfs-58f126fd27bb2f366f76f42223b93ba3b31a0bd8.tar.xz
seaweedfs-58f126fd27bb2f366f76f42223b93ba3b31a0bd8.zip
HEAD operation changes to fasthttp
Diffstat (limited to 'weed/util/http_util.go')
-rw-r--r--weed/util/http_util.go25
1 files changed, 17 insertions, 8 deletions
diff --git a/weed/util/http_util.go b/weed/util/http_util.go
index 08007a038..b74e30ad7 100644
--- a/weed/util/http_util.go
+++ b/weed/util/http_util.go
@@ -12,6 +12,8 @@ import (
"net/url"
"strings"
+ "github.com/valyala/fasthttp"
+
"github.com/chrislusf/seaweedfs/weed/glog"
)
@@ -83,16 +85,23 @@ func Get(url string) ([]byte, error) {
return b, nil
}
-func Head(url string) (http.Header, error) {
- r, err := client.Head(url)
- if err != nil {
- return nil, err
+func Head(url string, fn func(header fasthttp.ResponseHeader)) error {
+ req := fasthttp.AcquireRequest()
+ resp := fasthttp.AcquireResponse()
+ defer fasthttp.ReleaseRequest(req) // <- do not forget to release
+ defer fasthttp.ReleaseResponse(resp) // <- do not forget to release
+
+ c := fasthttp.Client{}
+ req.SetRequestURI(url)
+ req.Header.SetMethod(fasthttp.MethodHead)
+ if err := c.Do(req, resp); err != nil {
+ return err
}
- defer r.Body.Close()
- if r.StatusCode >= 400 {
- return nil, fmt.Errorf("%s: %s", url, r.Status)
+ if resp.StatusCode() >= 400 {
+ return fmt.Errorf("%s: %d", url, resp.StatusCode())
}
- return r.Header, nil
+ fn(resp.Header)
+ return nil
}
func Delete(url string, jwt string) error {