[#484] Handle conditional headers
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
ee0f3fb196
commit
f282e877e2
3 changed files with 24 additions and 9 deletions
|
@ -38,6 +38,7 @@ type (
|
||||||
PartNumberMarker int
|
PartNumberMarker int
|
||||||
Attributes []string
|
Attributes []string
|
||||||
VersionID string
|
VersionID string
|
||||||
|
Conditional *conditionalArgs
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -90,6 +91,11 @@ func (h *handler) GetObjectAttributesHandler(w http.ResponseWriter, r *http.Requ
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = checkPreconditions(info, params.Conditional); err != nil {
|
||||||
|
h.logAndSendError(w, "precondition failed", reqInfo, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
response, err := encodeToObjectAttributesResponse(info, params)
|
response, err := encodeToObjectAttributesResponse(info, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.logAndSendError(w, "couldn't encode object info to response", reqInfo, err)
|
h.logAndSendError(w, "couldn't encode object info to response", reqInfo, err)
|
||||||
|
@ -152,7 +158,8 @@ func parseGetObjectAttributeArgs(r *http.Request) (*GetObjectAttributesArgs, err
|
||||||
|
|
||||||
res.VersionID = queryValues.Get(api.QueryVersionID)
|
res.VersionID = queryValues.Get(api.QueryVersionID)
|
||||||
|
|
||||||
return res, nil
|
res.Conditional, err = parseConditionalHeaders(r.Header)
|
||||||
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeToObjectAttributesResponse(info *data.ObjectInfo, p *GetObjectAttributesArgs) (*GetObjectAttributesResponse, error) {
|
func encodeToObjectAttributesResponse(info *data.ObjectInfo, p *GetObjectAttributesArgs) (*GetObjectAttributesResponse, error) {
|
||||||
|
|
|
@ -21,10 +21,6 @@ type conditionalArgs struct {
|
||||||
IfNoneMatch string
|
IfNoneMatch string
|
||||||
}
|
}
|
||||||
|
|
||||||
type getObjectArgs struct {
|
|
||||||
Conditional *conditionalArgs
|
|
||||||
}
|
|
||||||
|
|
||||||
func fetchRangeHeader(headers http.Header, fullSize uint64) (*layer.RangeParams, error) {
|
func fetchRangeHeader(headers http.Header, fullSize uint64) (*layer.RangeParams, error) {
|
||||||
const prefix = "bytes="
|
const prefix = "bytes="
|
||||||
rangeHeader := headers.Get("Range")
|
rangeHeader := headers.Get("Range")
|
||||||
|
@ -109,7 +105,7 @@ func (h *handler) GetObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
reqInfo = api.GetReqInfo(r.Context())
|
reqInfo = api.GetReqInfo(r.Context())
|
||||||
)
|
)
|
||||||
|
|
||||||
args, err := parseGetObjectArgs(r.Header)
|
conditional, err := parseConditionalHeaders(r.Header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.logAndSendError(w, "could not parse request params", reqInfo, err)
|
h.logAndSendError(w, "could not parse request params", reqInfo, err)
|
||||||
return
|
return
|
||||||
|
@ -132,7 +128,7 @@ func (h *handler) GetObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = checkPreconditions(info, args.Conditional); err != nil {
|
if err = checkPreconditions(info, conditional); err != nil {
|
||||||
h.logAndSendError(w, "precondition failed", reqInfo, err)
|
h.logAndSendError(w, "precondition failed", reqInfo, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -194,7 +190,7 @@ func checkPreconditions(info *data.ObjectInfo, args *conditionalArgs) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseGetObjectArgs(headers http.Header) (*getObjectArgs, error) {
|
func parseConditionalHeaders(headers http.Header) (*conditionalArgs, error) {
|
||||||
var err error
|
var err error
|
||||||
args := &conditionalArgs{
|
args := &conditionalArgs{
|
||||||
IfMatch: headers.Get(api.IfMatch),
|
IfMatch: headers.Get(api.IfMatch),
|
||||||
|
@ -208,7 +204,7 @@ func parseGetObjectArgs(headers http.Header) (*getObjectArgs, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &getObjectArgs{Conditional: args}, nil
|
return args, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseHTTPTime(data string) (*time.Time, error) {
|
func parseHTTPTime(data string) (*time.Time, error) {
|
||||||
|
|
|
@ -40,6 +40,12 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conditional, err := parseConditionalHeaders(r.Header)
|
||||||
|
if err != nil {
|
||||||
|
h.logAndSendError(w, "could not parse request params", reqInfo, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
p := &layer.HeadObjectParams{
|
p := &layer.HeadObjectParams{
|
||||||
BktInfo: bktInfo,
|
BktInfo: bktInfo,
|
||||||
Object: reqInfo.ObjectName,
|
Object: reqInfo.ObjectName,
|
||||||
|
@ -50,6 +56,12 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
h.logAndSendError(w, "could not fetch object info", reqInfo, err)
|
h.logAndSendError(w, "could not fetch object info", reqInfo, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err = checkPreconditions(info, conditional); err != nil {
|
||||||
|
h.logAndSendError(w, "precondition failed", reqInfo, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
tagSet, err := h.obj.GetObjectTagging(r.Context(), info)
|
tagSet, err := h.obj.GetObjectTagging(r.Context(), info)
|
||||||
if err != nil && !errors.IsS3Error(err, errors.ErrNoSuchKey) {
|
if err != nil && !errors.IsS3Error(err, errors.ErrNoSuchKey) {
|
||||||
h.logAndSendError(w, "could not get object tag set", reqInfo, err)
|
h.logAndSendError(w, "could not get object tag set", reqInfo, err)
|
||||||
|
|
Loading…
Reference in a new issue