summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/http/http.hpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-12-24 02:54:39 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-12-24 02:54:39 +0000
commit74aef8947b7b72eca797a2f55d39997cc7af9c25 (patch)
tree60992d5a27fb7d10e2e6b280cad4dfde9256c043 /sca-cpp/trunk/modules/http/http.hpp
parente5f662ac57fa2c54882245e1c568e0982abab4fb (diff)
Fix roundtripping of JSON arrays, booleans and numbers, ATOM / RSS feed detection, and support REST-style JSON and XML payloads in server handler and client proxy.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1052432 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/http/http.hpp')
-rw-r--r--sca-cpp/trunk/modules/http/http.hpp42
1 files changed, 33 insertions, 9 deletions
diff --git a/sca-cpp/trunk/modules/http/http.hpp b/sca-cpp/trunk/modules/http/http.hpp
index ad3ae84821..95b904435d 100644
--- a/sca-cpp/trunk/modules/http/http.hpp
+++ b/sca-cpp/trunk/modules/http/http.hpp
@@ -399,10 +399,12 @@ const failable<value> get(const string& url, const CURLSession& cs) {
const failable<list<list<string> > > res = get<list<string> >(rcons<string>, list<string>(), url, cs);
if (!hasContent(res))
return mkfailure<value>(reason(res));
- const list<string> ls(reverse(cadr(content(res))));
-
const string ct(content(contentType(car(content(res)))));
debug(ct, "http::get::contentType");
+
+ const list<string> ls(reverse(cadr(content(res))));
+ debug(ls, "http::get::content");
+
if (contains(ct, "application/atom+xml;type=entry")) {
// Read an ATOM entry
const value val(atom::entryValue(content(atom::readATOMEntry(ls))));
@@ -421,15 +423,22 @@ const failable<value> get(const string& url, const CURLSession& cs) {
debug(val, "http::get::result");
return val;
}
- if (contains(ct, "text/javascript") || contains(ct, "application/json")) {
+ if (contains(ct, "text/javascript") || contains(ct, "application/json") || json::isJSON(ls)) {
+ // Read a JSON document
js::JSContext cx;
const value val(json::jsonValues(content(json::readJSON(ls, cx))));
debug(val, "http::get::result");
return val;
}
+ if (contains(ct, "text/xml") || contains(ct, "application/xml") || isXML(ls)) {
+ // Read an XML document
+ const value val(elementsToValues(readXML(ls)));
+ debug(val, "http::get::result");
+ return val;
+ }
- // Return the content as a list of values
- const value val(mkvalues(ls));
+ // Return the content type and a content list
+ const value val(mklist<value>(ct, mkvalues(ls)));
debug(val, "http::get::result");
return val;
}
@@ -617,11 +626,26 @@ const failable<size_t> recv(char* c, const size_t l, const CURLSession& cs) {
struct proxy {
proxy(const string& uri, const string& ca, const string& cert, const string& key, const gc_pool& p) : p(p), uri(uri), ca(ca), cert(cert), key(key), cs(*(new (gc_new<CURLSession>(p)) CURLSession(ca, cert, key))) {
}
-
+
const value operator()(const list<value>& args) const {
- failable<value> val = evalExpr(args, uri, cs);
- if (!hasContent(val))
- return value();
+ const value fun = car(args);
+ if (fun == "get") {
+ const failable<value> val = get(uri + path(cadr(args)), cs);
+ return content(val);
+ }
+ if (fun == "post") {
+ const failable<value> val = post(caddr(args), uri + path(cadr(args)), cs);
+ return content(val);
+ }
+ if (fun == "put") {
+ const failable<value> val = put(caddr(args), uri + path(cadr(args)), cs);
+ return content(val);
+ }
+ if (fun == "delete") {
+ const failable<value> val = del(uri + path(cadr(args)), cs);
+ return content(val);
+ }
+ const failable<value> val = evalExpr(args, uri, cs);
return content(val);
}