forked from TrueCloudLab/frostfs-s3-gw
[#180] api: Remove extra parses of url requests
Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
parent
a0fb14d91e
commit
afff616675
1 changed files with 28 additions and 24 deletions
|
@ -94,8 +94,9 @@ func encodeV2(p *layer.ListObjectsParamsV2, list *layer.ListObjectsInfoV2) *List
|
||||||
|
|
||||||
func parseListObjectsArgsV1(r *http.Request) (*layer.ListObjectsParamsV1, error) {
|
func parseListObjectsArgsV1(r *http.Request) (*layer.ListObjectsParamsV1, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
res layer.ListObjectsParamsV1
|
res layer.ListObjectsParamsV1
|
||||||
|
queryValues = r.URL.Query()
|
||||||
)
|
)
|
||||||
|
|
||||||
common, err := parseListObjectArgs(r)
|
common, err := parseListObjectArgs(r)
|
||||||
|
@ -104,15 +105,16 @@ func parseListObjectsArgsV1(r *http.Request) (*layer.ListObjectsParamsV1, error)
|
||||||
}
|
}
|
||||||
res.ListObjectsParamsCommon = *common
|
res.ListObjectsParamsCommon = *common
|
||||||
|
|
||||||
res.Marker = r.URL.Query().Get("marker")
|
res.Marker = queryValues.Get("marker")
|
||||||
|
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseListObjectsArgsV2(r *http.Request) (*layer.ListObjectsParamsV2, error) {
|
func parseListObjectsArgsV2(r *http.Request) (*layer.ListObjectsParamsV2, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
res layer.ListObjectsParamsV2
|
res layer.ListObjectsParamsV2
|
||||||
|
queryValues = r.URL.Query()
|
||||||
)
|
)
|
||||||
|
|
||||||
common, err := parseListObjectArgs(r)
|
common, err := parseListObjectArgs(r)
|
||||||
|
@ -121,32 +123,33 @@ func parseListObjectsArgsV2(r *http.Request) (*layer.ListObjectsParamsV2, error)
|
||||||
}
|
}
|
||||||
res.ListObjectsParamsCommon = *common
|
res.ListObjectsParamsCommon = *common
|
||||||
|
|
||||||
res.ContinuationToken = r.URL.Query().Get("continuation-token")
|
res.ContinuationToken = queryValues.Get("continuation-token")
|
||||||
res.StartAfter = r.URL.Query().Get("start-after")
|
res.StartAfter = queryValues.Get("start-after")
|
||||||
res.FetchOwner, _ = strconv.ParseBool(r.URL.Query().Get("fetch-owner"))
|
res.FetchOwner, _ = strconv.ParseBool(queryValues.Get("fetch-owner"))
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseListObjectArgs(r *http.Request) (*layer.ListObjectsParamsCommon, error) {
|
func parseListObjectArgs(r *http.Request) (*layer.ListObjectsParamsCommon, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
res layer.ListObjectsParamsCommon
|
res layer.ListObjectsParamsCommon
|
||||||
|
queryValues = r.URL.Query()
|
||||||
)
|
)
|
||||||
|
|
||||||
if info := api.GetReqInfo(r.Context()); info != nil {
|
if info := api.GetReqInfo(r.Context()); info != nil {
|
||||||
res.Bucket = info.BucketName
|
res.Bucket = info.BucketName
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Delimiter = r.URL.Query().Get("delimiter")
|
res.Delimiter = queryValues.Get("delimiter")
|
||||||
res.Encode = r.URL.Query().Get("encoding-type")
|
res.Encode = queryValues.Get("encoding-type")
|
||||||
|
|
||||||
if r.URL.Query().Get("max-keys") == "" {
|
if queryValues.Get("max-keys") == "" {
|
||||||
res.MaxKeys = maxObjectList
|
res.MaxKeys = maxObjectList
|
||||||
} else if res.MaxKeys, err = strconv.Atoi(r.URL.Query().Get("max-keys")); err != nil || res.MaxKeys < 0 {
|
} else if res.MaxKeys, err = strconv.Atoi(queryValues.Get("max-keys")); err != nil || res.MaxKeys < 0 {
|
||||||
return nil, api.GetAPIError(api.ErrInvalidMaxKeys)
|
return nil, api.GetAPIError(api.ErrInvalidMaxKeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Prefix = r.URL.Query().Get("prefix")
|
res.Prefix = queryValues.Get("prefix")
|
||||||
|
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
@ -208,21 +211,22 @@ func (h *handler) ListBucketObjectVersionsHandler(w http.ResponseWriter, r *http
|
||||||
|
|
||||||
func parseListObjectVersionsRequest(r *http.Request) (*layer.ListObjectVersionsParams, error) {
|
func parseListObjectVersionsRequest(r *http.Request) (*layer.ListObjectVersionsParams, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
res layer.ListObjectVersionsParams
|
res layer.ListObjectVersionsParams
|
||||||
|
queryValues = r.URL.Query()
|
||||||
)
|
)
|
||||||
|
|
||||||
if r.URL.Query().Get("max-keys") == "" {
|
if queryValues.Get("max-keys") == "" {
|
||||||
res.MaxKeys = maxObjectList
|
res.MaxKeys = maxObjectList
|
||||||
} else if res.MaxKeys, err = strconv.Atoi(r.URL.Query().Get("max-keys")); err != nil || res.MaxKeys <= 0 {
|
} else if res.MaxKeys, err = strconv.Atoi(queryValues.Get("max-keys")); err != nil || res.MaxKeys <= 0 {
|
||||||
return nil, api.GetAPIError(api.ErrInvalidMaxKeys)
|
return nil, api.GetAPIError(api.ErrInvalidMaxKeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Prefix = r.URL.Query().Get("prefix")
|
res.Prefix = queryValues.Get("prefix")
|
||||||
res.KeyMarker = r.URL.Query().Get("marker")
|
res.KeyMarker = queryValues.Get("marker")
|
||||||
res.Delimiter = r.URL.Query().Get("delimiter")
|
res.Delimiter = queryValues.Get("delimiter")
|
||||||
res.Encode = r.URL.Query().Get("encoding-type")
|
res.Encode = queryValues.Get("encoding-type")
|
||||||
res.VersionIDMarker = r.URL.Query().Get("version-id-marker")
|
res.VersionIDMarker = queryValues.Get("version-id-marker")
|
||||||
|
|
||||||
if info := api.GetReqInfo(r.Context()); info != nil {
|
if info := api.GetReqInfo(r.Context()); info != nil {
|
||||||
res.Bucket = info.BucketName
|
res.Bucket = info.BucketName
|
||||||
|
|
Loading…
Reference in a new issue