From: Casey Bodley Date: Fri, 2 Mar 2018 19:22:30 +0000 (-0500) Subject: rgw: s3website error handler uses original object name X-Git-Tag: v13.0.2~67^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8f7cbbce26c7fbccb7e9ae46040f3472d8762a88;p=ceph.git rgw: s3website error handler uses original object name the s3website error handler needs to use the same object name for redirect handling that retarget() does, but s->object.name may be modified based on get_effective_key() Fixes: http://tracker.ceph.com/issues/23201 Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 973576109a10..e2054a741220 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3445,6 +3445,17 @@ bool RGWHandler_REST_S3Website::web_dir() const { return state->exists; } +int RGWHandler_REST_S3Website::init(RGWRados *store, req_state *s, + rgw::io::BasicClient* cio) +{ + // save the original object name before retarget() replaces it with the + // result of get_effective_key(). the error_handler() needs the original + // object name for redirect handling + original_object_name = s->object.name; + + return RGWHandler_REST_S3::init(store, s, cio); +} + int RGWHandler_REST_S3Website::retarget(RGWOp* op, RGWOp** new_op) { *new_op = op; ldout(s->cct, 10) << __func__ << "Starting retarget" << dendl; @@ -3594,16 +3605,16 @@ int RGWHandler_REST_S3Website::error_handler(int err_no, RGWBWRoutingRule rrule; bool should_redirect = - s->bucket_info.website_conf.should_redirect(s->object.name, http_error_code, - &rrule); + s->bucket_info.website_conf.should_redirect(original_object_name, + http_error_code, &rrule); if (should_redirect) { const string& hostname = s->info.env->get("HTTP_HOST", ""); const string& protocol = (s->info.env->get("SERVER_PORT_SECURE") ? "https" : "http"); int redirect_code = 0; - rrule.apply_rule(protocol, hostname, s->object.name, &s->redirect, - &redirect_code); + rrule.apply_rule(protocol, hostname, original_object_name, + &s->redirect, &redirect_code); // Apply a custom HTTP response code if (redirect_code > 0) s->err.http_ret = redirect_code; // Apply a custom HTTP response code diff --git a/src/rgw/rgw_rest_s3website.h b/src/rgw/rgw_rest_s3website.h index abfe7b1984ad..fa6416ee5db3 100644 --- a/src/rgw/rgw_rest_s3website.h +++ b/src/rgw/rgw_rest_s3website.h @@ -17,6 +17,7 @@ #include "rgw_rest_s3.h" class RGWHandler_REST_S3Website : public RGWHandler_REST_S3 { + std::string original_object_name; // object name before retarget() bool web_dir() const; protected: int retarget(RGWOp *op, RGWOp **new_op) override; @@ -37,6 +38,8 @@ protected: public: using RGWHandler_REST_S3::RGWHandler_REST_S3; ~RGWHandler_REST_S3Website() override = default; + + int init(RGWRados *store, req_state *s, rgw::io::BasicClient* cio) override; int error_handler(int err_no, string *error_content) override; };