(w http.ResponseWriter, r *http.Request)
| 220 | } |
| 221 | |
| 222 | func (h *Handler) handleGetHeadPost(w http.ResponseWriter, r *http.Request) (status int, err error) { |
| 223 | reqPath, status, err := h.stripPrefix(r.URL.Path) |
| 224 | if err != nil { |
| 225 | return status, err |
| 226 | } |
| 227 | // TODO: check locks for read-only access?? |
| 228 | ctx := r.Context() |
| 229 | user := ctx.Value(conf.UserKey).(*model.User) |
| 230 | password, _ := ctx.Value(conf.MetaPassKey).(string) |
| 231 | reqPath, err = user.JoinPath(reqPath) |
| 232 | if err != nil { |
| 233 | return http.StatusForbidden, err |
| 234 | } |
| 235 | meta, err := op.GetNearestMeta(reqPath) |
| 236 | if err != nil && !errors.Is(errors.Cause(err), errs.MetaNotFound) { |
| 237 | return http.StatusInternalServerError, err |
| 238 | } |
| 239 | if !common.CanAccess(user, meta, reqPath, password) { |
| 240 | return http.StatusForbidden, errs.PermissionDenied |
| 241 | } |
| 242 | fi, err := fs.Get(ctx, reqPath, &fs.GetArgs{}) |
| 243 | if err != nil { |
| 244 | return http.StatusNotFound, err |
| 245 | } |
| 246 | if fi.IsDir() { |
| 247 | if r.Method == http.MethodHead { |
| 248 | w.Header().Set("Content-Type", "httpd/unix-directory") |
| 249 | w.Header().Set("Content-Length", "0") |
| 250 | return http.StatusOK, nil |
| 251 | } |
| 252 | return http.StatusMethodNotAllowed, nil |
| 253 | } |
| 254 | // Let ServeContent determine the Content-Type header. |
| 255 | storage, _ := fs.GetStorage(reqPath, &fs.GetStoragesArgs{}) |
| 256 | if storage.GetStorage().Webdav302() { |
| 257 | link, _, err := fs.Link(ctx, reqPath, model.LinkArgs{IP: utils.ClientIP(r), Header: r.Header, Redirect: true}) |
| 258 | if err != nil { |
| 259 | return http.StatusInternalServerError, err |
| 260 | } |
| 261 | defer link.Close() |
| 262 | http.Redirect(w, r, link.URL, http.StatusFound) |
| 263 | return 0, nil |
| 264 | } |
| 265 | |
| 266 | if storage.GetStorage().WebdavProxyURL() { |
| 267 | if url := common.GenerateDownProxyURL(storage.GetStorage(), reqPath); url != "" { |
| 268 | w.Header().Set("Cache-Control", "max-age=0, no-cache, no-store, must-revalidate") |
| 269 | http.Redirect(w, r, url, http.StatusFound) |
| 270 | return 0, nil |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | link, _, err := fs.Link(ctx, reqPath, model.LinkArgs{Header: r.Header}) |
| 275 | if err != nil { |
| 276 | return http.StatusInternalServerError, err |
| 277 | } |
| 278 | defer link.Close() |
| 279 |
no test coverage detected