summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/wsgi/httputil.py
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-06-05 05:38:43 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-06-05 05:38:43 +0000
commit69c6e0618ad4f18d18771ef91aacbb5c5a68f3a2 (patch)
tree2456aa85d86125726127b0d4ab022f68d2fc710b /sca-cpp/trunk/modules/wsgi/httputil.py
parentf052ca9d9dc273dc0f625c9a6ec6eb38d6bc0f3a (diff)
Add RSS support to the WSGI integration module.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@951655 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/wsgi/httputil.py')
-rw-r--r--sca-cpp/trunk/modules/wsgi/httputil.py58
1 files changed, 32 insertions, 26 deletions
diff --git a/sca-cpp/trunk/modules/wsgi/httputil.py b/sca-cpp/trunk/modules/wsgi/httputil.py
index 77d19eabe2..3d0c3350ef 100644
--- a/sca-cpp/trunk/modules/wsgi/httputil.py
+++ b/sca-cpp/trunk/modules/wsgi/httputil.py
@@ -29,41 +29,27 @@ from util import *
from atomutil import *
from jsonutil import *
+# JSON request id
id = 1
# Make a callable HTTP client
class client:
- def __init__(self, uri):
- self.uri = urlparse(uri)
+ def __init__(self, url):
+ self.url = urlparse(url)
def __call__(self, func, *args):
- # Connect to the configured URI
- print >> stderr, "Client POST", self.uri.geturl()
- c = None
- headers = {"Content-type": "application/json-rpc"}
- if self.uri.scheme == "https":
+ # Connect to the configured URL
+ print >> stderr, "Client POST", self.url.geturl()
+ c, headers = connect(self.url)
- # With HTTPS, use a cerficate or HTTP basic authentication
- if os.path.exists("server.key"):
- c = HTTPSConnection(self.uri.hostname, 443 if self.uri.port == None else self.uri.port, "server.key", "server.crt")
- else:
- c = HTTPSConnection(self.uri.hostname, 443 if self.uri.port == None else self.uri.port)
-
- # For HTTP basic authentication the user and password are
- # provided by htpasswd.py
- import htpasswd
- auth = 'Basic ' + b64encode(htpasswd.user + ':' + htpasswd.passwd)
- headers["Authorization"] = auth
- else:
- c = HTTPConnection(self.uri.hostname, 80 if self.uri.port == None else self.uri.port)
-
- # POST the JSON-RPC request
+ # POST a JSON-RPC request
global id
req = StringIO()
writeStrings(jsonRequest(id, func, args), req)
id = id + 1
- c.request("POST", self.uri.path, req.getvalue(), headers)
+ headers["Content-type"] = "application/json-rpc"
+ c.request("POST", self.url.path, req.getvalue(), headers)
res = c.getresponse()
print >> stderr, "Client status", res.status
if res.status != 200:
@@ -71,8 +57,28 @@ class client:
return jsonResultValue((res.read(),))
def __repr__(self):
- return repr((self.uri,))
+ return repr((self.url,))
+
+def mkclient(url):
+ return client(url)
+
+# Connect to a URL, return a connection and any authorization headers
+def connect(url):
+ if url.scheme == "https":
+
+ # With HTTPS, use a cerficate or HTTP basic authentication
+ if os.path.exists("server.key"):
+ c = HTTPSConnection(url.hostname, 443 if url.port == None else url.port, "server.key", "server.crt")
+ return c, {}
+ else:
+ c = HTTPSConnection(url.hostname, 443 if url.port == None else url.port)
-def mkclient(uri):
- return client(uri)
+ # For HTTP basic authentication the user and password are
+ # provided by htpasswd.py
+ import htpasswd
+ auth = 'Basic ' + b64encode(htpasswd.user + ':' + htpasswd.passwd)
+ return c, {"Authorization": auth}
+ else:
+ c = HTTPConnection(url.hostname, 80 if url.port == None else url.port)
+ return c, {}