diff options
Diffstat (limited to 'sca-cpp/trunk/modules/http')
-rw-r--r-- | sca-cpp/trunk/modules/http/http.hpp | 41 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/http/httpd.hpp | 18 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/http/openauth.hpp | 2 |
3 files changed, 41 insertions, 20 deletions
diff --git a/sca-cpp/trunk/modules/http/http.hpp b/sca-cpp/trunk/modules/http/http.hpp index 26a2e0cf0c..e2327be40a 100644 --- a/sca-cpp/trunk/modules/http/http.hpp +++ b/sca-cpp/trunk/modules/http/http.hpp @@ -620,6 +620,39 @@ const failable<size_t> recv(char* c, const size_t l, const CURLSession& cs) { return recv(c, l, cs); } + +/** + * Filter path segment in a list of arguments. + */ +const bool filterPath(const value& arg) { + return isString(arg); +} + +/** + * Filter query string arguments in a list of arguments. + */ +const bool filterQuery(const value& arg) { + return isList(arg); +} + +/** + * Converts a list of key value pairs to a query string. + */ +ostringstream& queryString(const list<list<value> > args, ostringstream& os) { + if (isNil(args)) + return os; + debug(car(args), "http::queryString::arg"); + os << car(car(args)) << "=" << c_str(cadr(car(args))); + if (!isNil(cdr(args))) + os << "&"; + return queryString(cdr(args), os); +} + +const string queryString(const list<list<value> > args) { + ostringstream os; + return str(queryString(args, os)); +} + /** * HTTP client proxy function. */ @@ -630,7 +663,13 @@ struct proxy { const value operator()(const list<value>& args) const { const value fun = car(args); if (fun == "get") { - const failable<value> val = get(uri + path(cadr(args)), cs); + const list<value> lp = filter<value>(filterPath, cadr(args)); + debug(lp, "http::queryString::arg"); + const list<value> lq = filter<value>(filterQuery, cadr(args)); + debug(lq, "http::get::query"); + const value p = path(lp); + const value q = queryString(lq); + const failable<value> val = get(uri + p + (q != ""? string("?") + q : string("")), cs); return content(val); } if (fun == "post") { diff --git a/sca-cpp/trunk/modules/http/httpd.hpp b/sca-cpp/trunk/modules/http/httpd.hpp index b6756c51e3..768537aa03 100644 --- a/sca-cpp/trunk/modules/http/httpd.hpp +++ b/sca-cpp/trunk/modules/http/httpd.hpp @@ -283,24 +283,6 @@ const list<list<value> > queryArgs(const request_rec* r) { } /** - * Converts a list of key value pairs to a query string. - */ -ostringstream& queryString(const list<list<value> > args, ostringstream& os) { - if (isNil(args)) - return os; - debug(car(args), "httpd::queryString::arg"); - os << car(car(args)) << "=" << c_str(cadr(car(args))); - if (!isNil(cdr(args))) - os << "&"; - return queryString(cdr(args), os); -} - -const string queryString(const list<list<value> > args) { - ostringstream os; - return str(queryString(args, os)); -} - -/** * Converts the args received in a POST to a list of key value pairs. */ const list<list<value> > postArgs(const list<value>& a) { diff --git a/sca-cpp/trunk/modules/http/openauth.hpp b/sca-cpp/trunk/modules/http/openauth.hpp index ff69a9732f..9023848305 100644 --- a/sca-cpp/trunk/modules/http/openauth.hpp +++ b/sca-cpp/trunk/modules/http/openauth.hpp @@ -87,7 +87,7 @@ const string cookie(const string& sid) { */ const failable<int> login(const string& page, request_rec* r) { const list<list<value> > largs = mklist<list<value> >(mklist<value>("openauth_referrer", httpd::escape(httpd::url(r->uri, r)))); - const string loc = httpd::url(page, r) + string("?") + httpd::queryString(largs); + const string loc = httpd::url(page, r) + string("?") + http::queryString(largs); debug(loc, "openauth::login::uri"); return httpd::externalRedirect(loc, r); } |