Support cookies over outgoing HTTP calls and a shorter component URL addressing scheme.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1126336 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8f252e970a
commit
2faafb7106
23 changed files with 190 additions and 90 deletions
|
|
@ -36,7 +36,7 @@ namespace http {
|
|||
const bool testConnect(const string& url, const string& ca = "", const string& cert = "", const string& key = "") {
|
||||
gc_scoped_pool p;
|
||||
|
||||
CURLSession cs(ca, cert, key);
|
||||
CURLSession cs(ca, cert, key, "");
|
||||
const failable<bool> crc = connect(url, cs);
|
||||
assert(hasContent(crc));
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace tuscany {
|
|||
namespace http {
|
||||
|
||||
const bool testGet(const string& url, const string& ca = "", const string& cert = "", const string& key = "") {
|
||||
CURLSession ch(ca, cert, key);
|
||||
CURLSession ch(ca, cert, key, "");
|
||||
const failable<value> val = get(url, ch);
|
||||
assert(hasContent(val));
|
||||
cout << content(val) << endl;
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ ostream* curlWriter(const string& s, ostream* os) {
|
|||
}
|
||||
|
||||
const bool testGet() {
|
||||
CURLSession ch("", "", "");
|
||||
CURLSession ch("", "", "", "");
|
||||
{
|
||||
ostringstream os;
|
||||
const failable<list<ostream*> > r = get<ostream*>(curlWriter, &os, testURI, ch);
|
||||
|
|
@ -69,7 +69,7 @@ struct getLoop {
|
|||
};
|
||||
|
||||
const bool testGetPerf() {
|
||||
CURLSession ch("", "", "");
|
||||
CURLSession ch("", "", "", "");
|
||||
lambda<bool()> gl = getLoop(ch);
|
||||
cout << "Static GET test " << time(gl, 5, 200) << " ms" << endl;
|
||||
return true;
|
||||
|
|
@ -80,7 +80,7 @@ const bool testGetPerf() {
|
|||
|
||||
int main() {
|
||||
tuscany::cout << "Testing..." << tuscany::endl;
|
||||
tuscany::http::testURI = tuscany::string("http://") + tuscany::http::hostname() + ":8090";
|
||||
tuscany::http::testURI = tuscany::string("http://") + tuscany::http::hostName() + ":8090";
|
||||
|
||||
tuscany::http::testGet();
|
||||
tuscany::http::testGetPerf();
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include <apr_network_io.h>
|
||||
#include <apr_portable.h>
|
||||
#include <apr_poll.h>
|
||||
#include <apr_uri.h>
|
||||
|
||||
#include "string.hpp"
|
||||
#include "gc.hpp"
|
||||
|
|
@ -65,13 +66,13 @@ public:
|
|||
*/
|
||||
class CURLSession {
|
||||
public:
|
||||
CURLSession() : h(NULL), p(NULL), sock(NULL), wpollset(NULL), wpollfd(NULL), rpollset(NULL), rpollfd(NULL), owner(false), ca(""), cert(""), key("") {
|
||||
CURLSession() : h(NULL), p(NULL), sock(NULL), wpollset(NULL), wpollfd(NULL), rpollset(NULL), rpollfd(NULL), owner(false), ca(""), cert(""), key(""), cookie("") {
|
||||
}
|
||||
|
||||
CURLSession(const string& ca, const string& cert, const string& key) : h(curl_easy_init()), p(gc_pool(mkpool())), sock(NULL), wpollset(NULL), wpollfd(NULL), rpollset(NULL), rpollfd(NULL), owner(true), ca(ca), cert(cert), key(key) {
|
||||
CURLSession(const string& ca, const string& cert, const string& key, const string& cookie) : h(curl_easy_init()), p(gc_pool(mkpool())), sock(NULL), wpollset(NULL), wpollfd(NULL), rpollset(NULL), rpollfd(NULL), owner(true), ca(ca), cert(cert), key(key), cookie(cookie) {
|
||||
}
|
||||
|
||||
CURLSession(const CURLSession& c) : h(c.h), p(c.p), sock(c.sock), wpollset(c.wpollset), wpollfd(c.wpollfd), rpollset(c.rpollset), rpollfd(c.rpollfd), owner(false), ca(c.ca), cert(c.cert), key(c.key) {
|
||||
CURLSession(const CURLSession& c) : h(c.h), p(c.p), sock(c.sock), wpollset(c.wpollset), wpollfd(c.wpollfd), rpollset(c.rpollset), rpollfd(c.rpollfd), owner(false), ca(c.ca), cert(c.cert), key(c.key), cookie(c.cookie) {
|
||||
}
|
||||
|
||||
~CURLSession() {
|
||||
|
|
@ -104,6 +105,7 @@ public:
|
|||
string ca;
|
||||
string cert;
|
||||
string key;
|
||||
string cookie;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -184,6 +186,34 @@ const string escapeArg(const string& arg) {
|
|||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a URI and return its host name.
|
||||
*/
|
||||
const string hostName(const string& uri, const gc_pool& p) {
|
||||
apr_uri_t u;
|
||||
const apr_status_t rc = apr_uri_parse(pool(p), c_str(uri), &u);
|
||||
if (rc != APR_SUCCESS)
|
||||
return "";
|
||||
if (u.hostname == NULL)
|
||||
return "";
|
||||
return u.hostname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first subdomain name in a host name.
|
||||
*/
|
||||
const string subDomain(const string& host) {
|
||||
return substr(host, 0, find(host, '.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the top domain name in a host name.
|
||||
*/
|
||||
const string topDomain(const string& host) {
|
||||
const size_t d = find(host, '.');
|
||||
return d == length(host) ? host : substr(host, d + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a CURL session
|
||||
*/
|
||||
|
|
@ -217,6 +247,10 @@ const failable<CURL*> setup(const string& url, const CURLSession& cs) {
|
|||
curl_easy_setopt(ch, CURLOPT_SSLKEY, c_str(cs.key));
|
||||
curl_easy_setopt(ch, CURLOPT_SSLKEYTYPE, "PEM");
|
||||
}
|
||||
if (cs.cookie != "") {
|
||||
debug(cs.cookie, "http::setup::cookie");
|
||||
curl_easy_setopt(ch, CURLOPT_COOKIE, c_str(cs.cookie));
|
||||
}
|
||||
|
||||
// Set target URL
|
||||
curl_easy_setopt(ch, CURLOPT_URL, c_str(escapeURI(url)));
|
||||
|
|
@ -567,7 +601,7 @@ const failable<value, string> del(const string& url, const CURLSession& cs) {
|
|||
/**
|
||||
* Returns the current host name.
|
||||
*/
|
||||
const string hostname() {
|
||||
const string hostName() {
|
||||
char h[256];
|
||||
if (gethostname(h, 256) == -1)
|
||||
return "localhost";
|
||||
|
|
@ -722,7 +756,7 @@ const value escapeQuery(const value& arg) {
|
|||
* HTTP client proxy function.
|
||||
*/
|
||||
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))) {
|
||||
proxy(const string& uri, const string& ca, const string& cert, const string& key, const string& cookie, const gc_pool& p) : p(p), uri(uri), ca(ca), cert(cert), key(key), cookie(cookie), cs(*(new (gc_new<CURLSession>(p)) CURLSession(ca, cert, key, cookie))) {
|
||||
}
|
||||
|
||||
const value operator()(const list<value>& args) const {
|
||||
|
|
@ -757,6 +791,7 @@ struct proxy {
|
|||
const string ca;
|
||||
const string cert;
|
||||
const string key;
|
||||
const string cookie;
|
||||
const CURLSession& cs;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -144,13 +144,6 @@ const string hostName(request_rec* r, const string& def = "localhost") {
|
|||
return hn != NULL? hn : (r->server->server_hostname != NULL? r->server->server_hostname : def);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first subdomain name in a host name.
|
||||
*/
|
||||
const string subdomain(const string& host) {
|
||||
return substr(host, 0, find(host, '.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if a request is targeting a virtual host.
|
||||
*/
|
||||
|
|
@ -189,6 +182,16 @@ const string contentType(const request_rec* r) {
|
|||
return ct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cookie header of a request.
|
||||
*/
|
||||
const string cookie(const request_rec* r) {
|
||||
const char* c = apr_table_get(r->headers_in, "Cookie");
|
||||
if (c == NULL)
|
||||
return "";
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the remaining part of a uri after the given path (aka the path info.)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ int tunnel(conn_rec* conn, const string& ca, const string& cert, const string& k
|
|||
apr_socket_t* csock = (apr_socket_t*)ap_get_module_config(conn->conn_config, &core_module);
|
||||
|
||||
// Open connection to target
|
||||
http::CURLSession cs(ca, cert, key);
|
||||
http::CURLSession cs(ca, cert, key, "");
|
||||
const failable<bool> crc = http::connect(url, cs);
|
||||
if (!hasContent(crc))
|
||||
return abort(conn, csock, reason(crc));
|
||||
|
|
|
|||
|
|
@ -63,9 +63,9 @@ const maybe<string> sessionID(const list<string> c) {
|
|||
}
|
||||
|
||||
const maybe<string> sessionID(const request_rec* r) {
|
||||
const char* c = apr_table_get(r->headers_in, "Cookie");
|
||||
const string c = httpd::cookie(r);
|
||||
debug(c, "openauth::sessionid::cookies");
|
||||
if (c == NULL)
|
||||
if (length(c) == 0)
|
||||
return maybe<string>();
|
||||
return sessionID(tokenize(";", c));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue