diff options
Diffstat (limited to 'sca-cpp/trunk/modules/server')
-rw-r--r-- | sca-cpp/trunk/modules/server/mod-eval.hpp | 36 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/mod-wiring.cpp | 20 |
2 files changed, 27 insertions, 29 deletions
diff --git a/sca-cpp/trunk/modules/server/mod-eval.hpp b/sca-cpp/trunk/modules/server/mod-eval.hpp index aaf31f2b18..b622283fed 100644 --- a/sca-cpp/trunk/modules/server/mod-eval.hpp +++ b/sca-cpp/trunk/modules/server/mod-eval.hpp @@ -129,13 +129,18 @@ const failable<int> get(request_rec* r, const lambda<value(const list<value>&)>& * Handle an HTTP POST. */ const failable<int> post(request_rec* r, const lambda<value(const list<value>&)>& impl) { - const list<string> ls = httpd::read(r); debug(r->uri, "modeval::post::url"); - debug(ls, "modeval::post::input"); // Evaluate a JSON-RPC request and return a JSON result const string ct = httpd::contentType(r); if (contains(ct, "application/json-rpc") || contains(ct, "text/plain")) { + + // Read the JSON request + const int rc = httpd::setupReadPolicy(r); + if(rc != OK) + return rc; + const list<string> ls = httpd::read(r); + debug(ls, "modeval::post::input"); json::JSONContext cx; const list<value> json = elementsToValues(content(json::readJSON(ls, cx))); const list<list<value> > args = httpd::postArgs(json); @@ -157,8 +162,15 @@ const failable<int> post(request_rec* r, const lambda<value(const list<value>&)> // Evaluate an ATOM POST request and return the location of the corresponding created resource if (contains(ct, "application/atom+xml")) { - // Evaluate the request expression + // Read the ATOM entry + const int rc = httpd::setupReadPolicy(r); + if(rc != OK) + return rc; + const list<string> ls = httpd::read(r); + debug(ls, "modeval::post::input"); const value entry = atom::entryValue(content(atom::readEntry(ls))); + + // Evaluate the request expression const failable<value> val = failableResult(impl(cons<value>("post", mklist<value>(entry)))); if (!hasContent(val)) return mkfailure<int>(reason(val)); @@ -174,20 +186,25 @@ const failable<int> post(request_rec* r, const lambda<value(const list<value>&)> const failable<value> val = failableResult(impl(cons<value>("handle", mklist<value>(httpd::requestValue(r))))); if (!hasContent(val)) return mkfailure<int>(reason(val)); - return OK; + return (int)content(val); } /** * Handle an HTTP PUT. */ const failable<int> put(request_rec* r, const lambda<value(const list<value>&)>& impl) { - const list<string> ls = httpd::read(r); debug(r->uri, "modeval::put::url"); - debug(ls, "modeval::put::input"); - // Evaluate an ATOM PUT request and update the corresponding resource + // Read the ATOM entry const list<value> path(httpd::pathValues(r->uri)); + const int rc = httpd::setupReadPolicy(r); + if(rc != OK) + return rc; + const list<string> ls = httpd::read(r); + debug(ls, "modeval::put::input"); const value entry = atom::entryValue(content(atom::readEntry(ls))); + + // Evaluate the ATOM PUT request and update the corresponding resource const failable<value> val = failableResult(impl(cons<value>("put", mklist<value>(caddr(path), entry)))); if (!hasContent(val)) return mkfailure<int>(reason(val)); @@ -244,11 +261,6 @@ int handler(request_rec *r) { return DECLINED; httpdDebugRequest(r, "modeval::handler::input"); - // Set up the read policy - const int rc = httpd::setupReadPolicy(r); - if(rc != OK) - return rc; - // Get the component implementation lambda DirConf& dc = httpd::dirConf<DirConf>(r, &mod_tuscany_eval); const list<value> path(httpd::pathValues(r->uri)); diff --git a/sca-cpp/trunk/modules/server/mod-wiring.cpp b/sca-cpp/trunk/modules/server/mod-wiring.cpp index 88a57659ef..aef2f00c83 100644 --- a/sca-cpp/trunk/modules/server/mod-wiring.cpp +++ b/sca-cpp/trunk/modules/server/mod-wiring.cpp @@ -194,17 +194,6 @@ int translate(request_rec *r) { } /** - * Construct a redirect URI. - */ -const string redirect(const string& file, const string& pi) { - return file + pi; -} - -const string redirect(const string& file, const string& pi, const string& args) { - return file + pi + "?" + args; -} - -/** * HTTP request handler, redirect to a target component. */ int handler(request_rec *r) { @@ -220,12 +209,9 @@ int handler(request_rec *r) { debug(r->filename, "modwiring::handler::filename"); debug(r->path_info, "modwiring::handler::path info"); - if (r->args == NULL) { - ap_internal_redirect(apr_pstrdup(r->pool, c_str(redirect(string(r->filename + 10), string(r->path_info)))), r); - return OK; - } - ap_internal_redirect(apr_pstrdup(r->pool, c_str(redirect(string(r->filename + 10), string(r->path_info), string(r->args)))), r); - return OK; + if (r->args == NULL) + return httpd::internalRedirect(httpd::redirectURI(string(r->filename + 10), string(r->path_info)), r); + return httpd::internalRedirect(httpd::redirectURI(string(r->filename + 10), string(r->path_info), string(r->args)), r); } /** |