From beba28f2f4da12bd572325d80469709037009d98 Mon Sep 17 00:00:00 2001 From: sungjoon-koh Date: Thu, 10 Jul 2025 16:05:31 +0900 Subject: [PATCH] rgw: add wildcard "*" support for conditional read - Enhanced If-Match and If-None-Match headers to support the wildcard "*". - Updated conditional read behavior: - If-Match: * now returns 200 instead of 412 when any object exists. - If-None-Match: * now returns 304 instead of 200 when any object exists. - If-Match: * + If-None-Match: * now returns 304 instead of 412. - Aligns with AWS S3 expected functionality for improved efficiency. Signed-off-by: sungjoon_koh --- src/rgw/driver/dbstore/common/dbstore.cc | 14 +++++++++++--- src/rgw/driver/rados/rgw_rados.cc | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/rgw/driver/dbstore/common/dbstore.cc b/src/rgw/driver/dbstore/common/dbstore.cc index 687b805c86bf..33ae4d9db80b 100644 --- a/src/rgw/driver/dbstore/common/dbstore.cc +++ b/src/rgw/driver/dbstore/common/dbstore.cc @@ -1381,14 +1381,22 @@ int DB::Object::Read::prepare(const DoutPrefixProvider *dpp) if (conds.if_match) { string if_match_str = rgw_string_unquote(conds.if_match); - ldpp_dout(dpp, 10) << "ETag: " << string(etag.c_str(), etag.length()) << " " << " If-Match: " << if_match_str << dendl; - if (if_match_str.compare(0, etag.length(), etag.c_str(), etag.length()) != 0) { - return -ERR_PRECONDITION_FAILED; + if (if_match_str.compare("*") != 0) { + ldpp_dout(dpp, 10) << "ETag: " << string(etag.c_str(), etag.length()) << " " << " If-Match: " << if_match_str << dendl; + if (if_match_str.compare(0, etag.length(), etag.c_str(), etag.length()) != 0) { + return -ERR_PRECONDITION_FAILED; + } + } else { + ldpp_dout(dpp, 10) << "If-Match: " << if_match_str << dendl; } } if (conds.if_nomatch) { string if_nomatch_str = rgw_string_unquote(conds.if_nomatch); + if (if_nomatch_str.compare("*") == 0) { + ldpp_dout(dpp, 10) << "If-NoMatch: " << if_nomatch_str << dendl; + return -ERR_NOT_MODIFIED; + } ldpp_dout(dpp, 10) << "ETag: " << string(etag.c_str(), etag.length()) << " " << " If-NoMatch: " << if_nomatch_str << dendl; if (if_nomatch_str.compare(0, etag.length(), etag.c_str(), etag.length()) == 0) { return -ERR_NOT_MODIFIED; diff --git a/src/rgw/driver/rados/rgw_rados.cc b/src/rgw/driver/rados/rgw_rados.cc index 02dfb31947c7..c293fce3d563 100644 --- a/src/rgw/driver/rados/rgw_rados.cc +++ b/src/rgw/driver/rados/rgw_rados.cc @@ -7745,14 +7745,22 @@ int RGWRados::Object::Read::prepare(optional_yield y, const DoutPrefixProvider * if (conds.if_match) { string if_match_str = rgw_string_unquote(conds.if_match); - ldpp_dout(dpp, 10) << "ETag: " << string(etag.c_str(), etag.length()) << " " << " If-Match: " << if_match_str << dendl; - if (if_match_str.compare(0, etag.length(), etag.c_str(), etag.length()) != 0) { - return -ERR_PRECONDITION_FAILED; + if (if_match_str.compare("*") != 0) { + ldpp_dout(dpp, 10) << "ETag: " << string(etag.c_str(), etag.length()) << " " << " If-Match: " << if_match_str << dendl; + if (if_match_str.compare(0, etag.length(), etag.c_str(), etag.length()) != 0) { + return -ERR_PRECONDITION_FAILED; + } + } else { + ldpp_dout(dpp, 10) << "If-Match: " << if_match_str << dendl; } } if (conds.if_nomatch) { string if_nomatch_str = rgw_string_unquote(conds.if_nomatch); + if (if_nomatch_str.compare("*") == 0) { + ldpp_dout(dpp, 10) << "If-NoMatch: " << if_nomatch_str << dendl; + return -ERR_NOT_MODIFIED; + } ldpp_dout(dpp, 10) << "ETag: " << string(etag.c_str(), etag.length()) << " " << " If-NoMatch: " << if_nomatch_str << dendl; if (if_nomatch_str.compare(0, etag.length(), etag.c_str(), etag.length()) == 0) { return -ERR_NOT_MODIFIED; -- 2.47.3