[#233] get/head: Middleware refactor
Add: * search index.html * fallback by leading slash Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
ee628617a3
commit
9cb9d14146
11 changed files with 311 additions and 121 deletions
|
@ -12,7 +12,6 @@ import (
|
|||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/data"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/logs"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/utils"
|
||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||
|
@ -161,6 +160,7 @@ func urlencode(path string) string {
|
|||
type GetObjectsResponse struct {
|
||||
objects []ResponseObject
|
||||
hasErrors bool
|
||||
isNative bool
|
||||
}
|
||||
|
||||
func (h *Handler) getDirObjectsS3(ctx context.Context, bucketInfo *data.BucketInfo, prefix string) (*GetObjectsResponse, error) {
|
||||
|
@ -226,7 +226,8 @@ func (h *Handler) getDirObjectsNative(ctx context.Context, bucketInfo *data.Buck
|
|||
log := h.reqLogger(ctx)
|
||||
dirs := make(map[string]struct{})
|
||||
result := &GetObjectsResponse{
|
||||
objects: make([]ResponseObject, 0, 100),
|
||||
objects: make([]ResponseObject, 0, 100),
|
||||
isNative: true,
|
||||
}
|
||||
for objExt := range resp {
|
||||
if objExt.Error != nil {
|
||||
|
@ -322,28 +323,16 @@ func (h *Handler) headDirObject(ctx context.Context, cnrID cid.ID, objID oid.ID,
|
|||
}
|
||||
|
||||
type browseParams struct {
|
||||
bucketInfo *data.BucketInfo
|
||||
prefix string
|
||||
isNative bool
|
||||
listObjects func(ctx context.Context, bucketName *data.BucketInfo, prefix string) (*GetObjectsResponse, error)
|
||||
bucketInfo *data.BucketInfo
|
||||
prefix string
|
||||
objects *GetObjectsResponse
|
||||
}
|
||||
|
||||
func (h *Handler) browseObjects(ctx context.Context, req *fasthttp.RequestCtx, p browseParams) {
|
||||
const S3Protocol = "s3"
|
||||
const FrostfsProtocol = "frostfs"
|
||||
|
||||
ctx = utils.SetReqLog(ctx, h.reqLogger(ctx).With(
|
||||
zap.String("bucket", p.bucketInfo.Name),
|
||||
zap.String("container", p.bucketInfo.CID.EncodeToString()),
|
||||
zap.String("prefix", p.prefix),
|
||||
))
|
||||
resp, err := p.listObjects(ctx, p.bucketInfo, p.prefix)
|
||||
if err != nil {
|
||||
h.logAndSendError(ctx, req, logs.FailedToListObjects, err)
|
||||
return
|
||||
}
|
||||
|
||||
objects := resp.objects
|
||||
objects := p.objects.objects
|
||||
sort.Slice(objects, func(i, j int) bool {
|
||||
if objects[i].IsDir == objects[j].IsDir {
|
||||
return objects[i].FileName < objects[j].FileName
|
||||
|
@ -363,7 +352,7 @@ func (h *Handler) browseObjects(ctx context.Context, req *fasthttp.RequestCtx, p
|
|||
}
|
||||
bucketName := p.bucketInfo.Name
|
||||
protocol := S3Protocol
|
||||
if p.isNative {
|
||||
if p.objects.isNative {
|
||||
bucketName = p.bucketInfo.CID.EncodeToString()
|
||||
protocol = FrostfsProtocol
|
||||
}
|
||||
|
@ -372,7 +361,7 @@ func (h *Handler) browseObjects(ctx context.Context, req *fasthttp.RequestCtx, p
|
|||
Prefix: p.prefix,
|
||||
Objects: objects,
|
||||
Protocol: protocol,
|
||||
HasErrors: resp.hasErrors,
|
||||
HasErrors: p.objects.hasErrors,
|
||||
}); err != nil {
|
||||
h.logAndSendError(ctx, req, logs.FailedToExecuteTemplate, err)
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue