From 6019b939bfd364b01ec13653e846b9b309cd6275 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Fri, 2 Mar 2018 14:22:30 -0500 Subject: [PATCH] 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 (cherry picked from commit 8f7cbbce26c7fbccb7e9ae46040f3472d8762a88) --- src/rgw/rgw_rest_s3.cc | 19 +++++++++++++++---- src/rgw/rgw_rest_s3website.h | 3 +++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 9c7eabbaeeb1f..3b4318c0e573c 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3448,6 +3448,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; @@ -3597,16 +3608,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 abfe7b1984ad8..fa6416ee5db37 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; }; -- 2.39.5