From: wenjunhuang Date: Wed, 17 Feb 2016 06:47:24 +0000 (+0800) Subject: rgw: adjust the request_uri to support absoluteURI of http request X-Git-Tag: v10.1.0~171^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=70f32f99850be3c05de4f50e5350f7e4c7ad3162;p=ceph.git rgw: adjust the request_uri to support absoluteURI of http request http://tracker.ceph.com/issues/12917 Fixes: #12917 The requestURI transferred from the frontend can be abs_path or absoluteURI If it is absoluteURI, we should adjust it to abs_path for the following S3 authorization and some other processes depending on the requestURI The absoluteURI can start with "http://", "https://", "ws://" or "wss://" Signed-off-by: Wenjun Huang --- diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index fec4ad7857d0..1a372f2d9a06 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -97,11 +97,48 @@ is_err() const return !(http_ret >= 200 && http_ret <= 399); } +static bool starts_with(const string& s, const string& prefix) { + if (s.size() < prefix.size()) { + return false; + } + for (unsigned int i = 0; i < prefix.size(); ++i) { + if (prefix[i] != s[i]) { + return false; + } + } + return true; +} + +// The requestURI transferred from the frontend can be abs_path or absoluteURI +// If it is absoluteURI, we should adjust it to abs_path for the following +// S3 authorization and some other processes depending on the requestURI +// The absoluteURI can start with "http://", "https://", "ws://" or "wss://" +static string get_abs_path(const string& request_uri) { + const static string ABS_PREFIXS[] = {"http://", "https://", "ws://", "wss://"}; + bool isAbs = false; + for (int i = 0; i < 4; ++i) { + if (starts_with(request_uri, ABS_PREFIXS[i])) { + isAbs = true; + break; + } + } + if (!isAbs) { // it is not a valid absolute uri + return request_uri; + } + size_t beg_pos = request_uri.find("://") + 3; + size_t len = request_uri.size(); + beg_pos = request_uri.find('/', beg_pos); + if (beg_pos == string::npos) return request_uri; + return request_uri.substr(beg_pos, len - beg_pos); +} req_info::req_info(CephContext *cct, class RGWEnv *e) : env(e) { method = env->get("REQUEST_METHOD", ""); script_uri = env->get("SCRIPT_URI", cct->_conf->rgw_script_uri.c_str()); request_uri = env->get("REQUEST_URI", cct->_conf->rgw_request_uri.c_str()); + if (request_uri[0] != '/') { + request_uri = get_abs_path(request_uri); + } int pos = request_uri.find('?'); if (pos >= 0) { request_params = request_uri.substr(pos + 1);