forked from TrueCloudLab/frostfs-s3-gw
[#28] Implement HeadBucket
closes #28 Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
parent
fd2c6e372b
commit
079e7a9827
1 changed files with 33 additions and 0 deletions
|
@ -8,6 +8,8 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-s3-gate/api"
|
"github.com/nspcc-dev/neofs-s3-gate/api"
|
||||||
"github.com/nspcc-dev/neofs-s3-gate/api/layer"
|
"github.com/nspcc-dev/neofs-s3-gate/api/layer"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) {
|
func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -45,3 +47,34 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Last-Modified", inf.Created.Format(http.TimeFormat))
|
w.Header().Set("Last-Modified", inf.Created.Format(http.TimeFormat))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *handler) HeadBucketHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var (
|
||||||
|
req = mux.Vars(r)
|
||||||
|
bkt = req["bucket"]
|
||||||
|
rid = api.GetRequestID(r.Context())
|
||||||
|
)
|
||||||
|
|
||||||
|
if _, err := h.obj.GetBucketInfo(r.Context(), bkt); err != nil {
|
||||||
|
h.log.Error("could not fetch object info",
|
||||||
|
zap.String("request_id", rid),
|
||||||
|
zap.String("bucket_name", bkt),
|
||||||
|
zap.Error(err))
|
||||||
|
|
||||||
|
code := http.StatusBadRequest
|
||||||
|
if st, ok := status.FromError(err); ok && st != nil {
|
||||||
|
switch st.Code() {
|
||||||
|
case codes.NotFound:
|
||||||
|
code = http.StatusNotFound
|
||||||
|
case codes.PermissionDenied:
|
||||||
|
code = http.StatusForbidden
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
api.WriteResponse(w, code, nil, api.MimeNone)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
api.WriteResponse(w, http.StatusOK, nil, api.MimeNone)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue