mirror of https://github.com/Xhofe/alist
fix(webdav): optimize `HEAD` request (close #5182)
parent
623c7dcea5
commit
d5b68a91d2
|
@ -51,6 +51,7 @@ func WebDAVAuth(c *gin.Context) {
|
|||
username, password, ok := c.Request.BasicAuth()
|
||||
if !ok {
|
||||
bt := c.GetHeader("Authorization")
|
||||
log.Debugf("[webdav auth] token: %s", bt)
|
||||
if strings.HasPrefix(bt, "Bearer") {
|
||||
bt = strings.TrimPrefix(bt, "Bearer ")
|
||||
token := setting.GetStr(conf.Token)
|
||||
|
|
|
@ -460,7 +460,7 @@ type ETager interface {
|
|||
func findETag(ctx context.Context, ls LockSystem, name string, fi model.Obj) (string, error) {
|
||||
if do, ok := fi.(ETager); ok {
|
||||
etag, err := do.ETag(ctx)
|
||||
if err != ErrNotImplemented {
|
||||
if !errors.Is(err, ErrNotImplemented) {
|
||||
return etag, err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ package webdav // import "golang.org/x/net/webdav"
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/alist-org/alist/v3/internal/stream"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -16,6 +15,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/stream"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/errs"
|
||||
"github.com/alist-org/alist/v3/internal/fs"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
|
@ -219,20 +220,24 @@ func (h *Handler) handleGetHeadPost(w http.ResponseWriter, r *http.Request) (sta
|
|||
user := ctx.Value("user").(*model.User)
|
||||
reqPath, err = user.JoinPath(reqPath)
|
||||
if err != nil {
|
||||
return 403, err
|
||||
return http.StatusForbidden, err
|
||||
}
|
||||
fi, err := fs.Get(ctx, reqPath, &fs.GetArgs{})
|
||||
if err != nil {
|
||||
return http.StatusNotFound, err
|
||||
}
|
||||
if fi.IsDir() {
|
||||
return http.StatusMethodNotAllowed, nil
|
||||
}
|
||||
etag, err := findETag(ctx, h.LockSystem, reqPath, fi)
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
w.Header().Set("ETag", etag)
|
||||
if r.Method == http.MethodHead {
|
||||
w.Header().Set("Content-Length", fmt.Sprintf("%d", fi.GetSize()))
|
||||
return http.StatusOK, nil
|
||||
}
|
||||
if fi.IsDir() {
|
||||
return http.StatusMethodNotAllowed, nil
|
||||
}
|
||||
// Let ServeContent determine the Content-Type header.
|
||||
storage, _ := fs.GetStorage(reqPath, &fs.GetStoragesArgs{})
|
||||
downProxyUrl := storage.GetStorage().DownProxyUrl
|
||||
|
|
Loading…
Reference in New Issue