From 1b10f18fce6baeb721a725661ded630614831304 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 30 Jan 2012 15:54:15 +0000 Subject: Add an app property which can be used to retrieve the current app name. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1237738 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/server/mod-eval.hpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'sca-cpp') diff --git a/sca-cpp/trunk/modules/server/mod-eval.hpp b/sca-cpp/trunk/modules/server/mod-eval.hpp index 2de2f3d6fe..62d91c6236 100644 --- a/sca-cpp/trunk/modules/server/mod-eval.hpp +++ b/sca-cpp/trunk/modules/server/mod-eval.hpp @@ -568,6 +568,18 @@ struct hostPropProxy { } }; +struct appPropProxy { + const value v; + appPropProxy(const value& v) : v(v) { + } + const value operator()(unused const list& params) const { + const char* n = apr_table_get(currentRequest->headers_in, "X-Request-AppName"); + const value a = n != NULL? value(string(n)) : v; + debug(a, "modeval::appPropProxy::value"); + return a; + } +}; + struct pathPropProxy { pathPropProxy(unused const value& v) { } @@ -616,6 +628,8 @@ struct userPropProxy { const value mkpropProxy(const value& prop) { const value n = scdl::name(prop); const value v = elementHasValue(prop)? elementValue(prop):value(string("")); + if (n == "app") + return lambda&)>(appPropProxy(v)); if (n == "host") return lambda&)>(hostPropProxy(v)); if (n == "path") @@ -821,7 +835,12 @@ const int handleRequest(const ServerConf& sc, const list& rpath, request_ // Handle a request targeting a virtual host or virtual app if (hasVirtualCompositeConf(sc)) { if (hasVirtualDomainConf(sc) && httpd::isVirtualHostRequest(sc.server, sc.virtualHostDomain, r)) { - ServerConf vsc(r->pool, sc, http::subDomain(httpd::hostName(r))); + + // Determine the app name from the host sub-domain name, and + // store it in a header + const string app = http::subDomain(httpd::hostName(r)); + apr_table_setn(r->headers_in, "X-Request-AppName", apr_pstrdup(r->pool, c_str(app))); + ServerConf vsc(r->pool, sc, app); if (!hasContent(virtualHostConfig(vsc, sc, r))) return HTTP_INTERNAL_SERVER_ERROR; const int rc = handleRequest(vsc, rpath, r); @@ -831,11 +850,16 @@ const int handleRequest(const ServerConf& sc, const list& rpath, request_ const value c = car(rpath); if (c != string("components") && c != string("c")) { - const string cp = sc.virtualHostContributionPath + string(c) + "/" + sc.virtualHostCompositeName; + + // Determine the app name from the request URI path + const string app = string(c); + const string cp = sc.virtualHostContributionPath + app + "/" + sc.virtualHostCompositeName; struct stat st; const int s = stat(c_str(cp), &st); if (s != -1) { - ServerConf vsc(r->pool, sc, string(c)); + // Store the app name in a header + apr_table_setn(r->headers_in, "X-Request-AppName", apr_pstrdup(r->pool, c_str(app))); + ServerConf vsc(r->pool, sc, app); if (!hasContent(virtualHostConfig(vsc, sc, r))) return HTTP_INTERNAL_SERVER_ERROR; const int rc = handleRequest(vsc, cdr(rpath), r); -- cgit v1.2.3