summaryrefslogtreecommitdiffstats
path: root/sca-cpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2012-01-30 15:54:15 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2012-01-30 15:54:15 +0000
commit1b10f18fce6baeb721a725661ded630614831304 (patch)
treeafd3073e37939a1dfba9cac1b181504f66699f0c /sca-cpp
parent32ae33c773765d51c83aedd0d3770a44ec351dc4 (diff)
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
Diffstat (limited to 'sca-cpp')
-rw-r--r--sca-cpp/trunk/modules/server/mod-eval.hpp30
1 files changed, 27 insertions, 3 deletions
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<value>& 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<value(const list<value>&)>(appPropProxy(v));
if (n == "host")
return lambda<value(const list<value>&)>(hostPropProxy(v));
if (n == "path")
@@ -821,7 +835,12 @@ const int handleRequest(const ServerConf& sc, const list<value>& 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<value>& 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);