]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: remove trailing :port from host for purposes of subdomain matching
authorSage Weil <sage@redhat.com>
Tue, 9 Jun 2015 18:15:10 +0000 (14:15 -0400)
committerRobin H. Johnson <robin.johnson@dreamhost.com>
Thu, 24 Sep 2015 21:02:33 +0000 (14:02 -0700)
Some clients (ahem, CrossFTP) include the :port in the HTTP_HOST header.
Strip it out.

Switch req_info field to a std::string and avoid copying it in preprocess.

Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit abe4ec293d08b0314bf5c081ace2456073f3a22c)

src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_rest.cc

index c270c6fdb0855a1008ca60fca58e1e944f14e7bc..6f75561b971a3d1f194511e2336482c736b9788c 100644 (file)
@@ -110,6 +110,21 @@ req_info::req_info(CephContext *cct, class RGWEnv *e) : env(e) {
     request_params = env->get("QUERY_STRING", "");
   }
   host = env->get("HTTP_HOST");
+
+  // strip off any trailing :port from host (added by CrossFTP and maybe others)
+  size_t colon_offset = host.find_last_of(':');
+  if (colon_offset != string::npos) {
+    bool all_digits = true;
+    for (unsigned i = colon_offset + 1; i < host.size(); ++i) {
+      if (!isdigit(host[i])) {
+       all_digits = false;
+       break;
+      }
+    }
+    if (all_digits) {
+      host.resize(colon_offset);
+    }
+  }
 }
 
 void req_info::rebuild_from(req_info& src)
index a7d2465c8beab3d107fa04934f2cda36c4840a41..5b4e39b0113c60d41c5d9d447e1b426e1898c169 100644 (file)
@@ -909,7 +909,7 @@ struct req_info {
   RGWHTTPArgs args;
   map<string, string> x_meta_map;
 
-  const char *host;
+  string host;
   const char *method;
   string script_uri;
   string request_uri;
index 5f4c40043118e1c7968c235ef2d7ca74a583209c..d3e464da7907305f0fbd5689fa8f569d14fed355 100644 (file)
@@ -1334,26 +1334,28 @@ int RGWREST::preprocess(struct req_state *s, RGWClientIO *cio)
   req_info& info = s->info;
 
   s->cio = cio;
-  if (info.host) {
-    string h(s->info.host);
-
-    ldout(s->cct, 10) << "host=" << s->info.host << dendl;
+  if (info.host.size()) {
+    ldout(s->cct, 10) << "host=" << info.host << dendl;
     string domain;
     string subdomain;
-    bool in_hosted_domain = rgw_find_host_in_domains(h, &domain, &subdomain);
-    ldout(s->cct, 20) << "subdomain=" << subdomain << " domain=" << domain << " in_hosted_domain=" << in_hosted_domain << dendl;
+    bool in_hosted_domain = rgw_find_host_in_domains(info.host, &domain,
+                                                    &subdomain);
+    ldout(s->cct, 20) << "subdomain=" << subdomain << " domain=" << domain
+                     << " in_hosted_domain=" << in_hosted_domain << dendl;
 
     if (g_conf->rgw_resolve_cname && !in_hosted_domain) {
       string cname;
       bool found;
-      int r = rgw_resolver->resolve_cname(h, cname, &found);
+      int r = rgw_resolver->resolve_cname(info.host, cname, &found);
       if (r < 0) {
        ldout(s->cct, 0) << "WARNING: rgw_resolver->resolve_cname() returned r=" << r << dendl;
       }
       if (found) {
-        ldout(s->cct, 5) << "resolved host cname " << h << " -> " << cname << dendl;
+        ldout(s->cct, 5) << "resolved host cname " << info.host << " -> "
+                        << cname << dendl;
         in_hosted_domain = rgw_find_host_in_domains(cname, &domain, &subdomain);
-        ldout(s->cct, 20) << "subdomain=" << subdomain << " domain=" << domain << " in_hosted_domain=" << in_hosted_domain << dendl;
+        ldout(s->cct, 20) << "subdomain=" << subdomain << " domain=" << domain
+                         << " in_hosted_domain=" << in_hosted_domain << dendl;
       }
     }