]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: adjust the request_uri to support absoluteURI of http request 7675/head
authorwenjunhuang <wenjunhuang@tencent.com>
Wed, 17 Feb 2016 06:47:24 +0000 (14:47 +0800)
committerwenjunhuang <wenjunhuang@tencent.com>
Mon, 29 Feb 2016 08:03:45 +0000 (16:03 +0800)
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 <wenjunhuang@tencent.com>
src/rgw/rgw_common.cc

index fec4ad7857d0d2ccfd44a2a1142634222c86a632..1a372f2d9a067bd24703e24209e81fdb38b821cd 100644 (file)
@@ -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);