forked from TrueCloudLab/frostfs-s3-gw
Migrate to SDK 0.3.0 and fixes
- fix displaying list objects - simplify `ListObjects` - simplify `GetObjectHandler` - simplify `HeadObjectHandler` - add method for `GetBucketVersioningHandler` - add method for `ListMultipartUploadsHandler` - improvements for `HeadObjectHandler`, to display folders meta - update dependencies - github.com/aws/aws-sdk-go v1.36.26 - github.com/google/uuid v1.1.4 - github.com/gorilla/mux v1.8.0 - github.com/nspcc-dev/cdn-sdk v0.3.0 - github.com/nspcc-dev/neofs-api-go v1.22.0 - github.com/prometheus/client_golang v1.9.0 - github.com/stretchr/testify v1.7.0 - google.golang.org/grpc v1.35.0 Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
parent
ef7b480493
commit
2a93a216f8
16 changed files with 592 additions and 178 deletions
|
@ -1,8 +1,8 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/nspcc-dev/neofs-s3-gate/api"
|
||||
|
@ -12,6 +12,35 @@ import (
|
|||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type devNull int
|
||||
|
||||
func (d devNull) Write(p []byte) (n int, err error) {
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func (h *handler) checkIsFolder(ctx context.Context, bucket, object string) *layer.ObjectInfo {
|
||||
if ln := len(object); ln > 0 && object[ln-1:] != layer.PathSeparator {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, dirname := layer.NameFromString(object)
|
||||
params := &layer.ListObjectsParams{Bucket: bucket, Prefix: dirname, Delimiter: layer.PathSeparator}
|
||||
|
||||
if list, err := h.obj.ListObjects(ctx, params); err == nil && len(list.Objects) > 0 {
|
||||
return &layer.ObjectInfo{
|
||||
Bucket: bucket,
|
||||
Name: object,
|
||||
|
||||
ContentType: "text/directory",
|
||||
|
||||
Owner: list.Objects[0].Owner,
|
||||
Created: list.Objects[0].Created,
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
err error
|
||||
|
@ -23,7 +52,14 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) {
|
|||
rid = api.GetRequestID(r.Context())
|
||||
)
|
||||
|
||||
if inf, err = h.obj.GetObjectInfo(r.Context(), bkt, obj); err != nil {
|
||||
if inf = h.checkIsFolder(r.Context(), bkt, obj); inf != nil {
|
||||
// do nothing for folders
|
||||
|
||||
// h.log.Debug("found folder",
|
||||
// zap.String("request_id", rid),
|
||||
// zap.String("bucket_name", bkt),
|
||||
// zap.String("object_name", obj))
|
||||
} else if inf, err = h.obj.GetObjectInfo(r.Context(), bkt, obj); err != nil {
|
||||
h.log.Error("could not fetch object info",
|
||||
zap.String("request_id", rid),
|
||||
zap.String("bucket_name", bkt),
|
||||
|
@ -36,13 +72,25 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) {
|
|||
HTTPStatusCode: http.StatusInternalServerError,
|
||||
}, r.URL)
|
||||
|
||||
return
|
||||
} else if inf.ContentType, err = h.contentTypeFetcher(r.Context(), devNull(0), inf); err != nil {
|
||||
h.log.Error("could not get object",
|
||||
zap.String("request_id", rid),
|
||||
zap.String("bucket_name", bkt),
|
||||
zap.String("object_name", obj),
|
||||
zap.Stringer("oid", inf.ID()),
|
||||
zap.Error(err))
|
||||
|
||||
api.WriteErrorResponse(r.Context(), w, api.Error{
|
||||
Code: api.GetAPIError(api.ErrInternalError).Code,
|
||||
Description: err.Error(),
|
||||
HTTPStatusCode: http.StatusInternalServerError,
|
||||
}, r.URL)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", inf.ContentType)
|
||||
w.Header().Set("Content-Length", strconv.FormatInt(inf.Size, 10))
|
||||
w.Header().Set("Last-Modified", inf.Created.Format(http.TimeFormat))
|
||||
|
||||
writeHeaders(w.Header(), inf)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue