[Checkins] SVN: z3c.rest/trunk/ RESTClient() now correctly interprets https:// URLs.

Marius Gedminas marius at pov.lt
Thu Sep 4 15:48:03 EDT 2008


Log message for revision 90827:
  RESTClient() now correctly interprets https:// URLs.
  
  

Changed:
  U   z3c.rest/trunk/CHANGES.txt
  U   z3c.rest/trunk/src/z3c/rest/client.py
  U   z3c.rest/trunk/src/z3c/rest/client.txt
  U   z3c.rest/trunk/src/z3c/rest/testing.py

-=-
Modified: z3c.rest/trunk/CHANGES.txt
===================================================================
--- z3c.rest/trunk/CHANGES.txt	2008-09-04 19:24:13 UTC (rev 90826)
+++ z3c.rest/trunk/CHANGES.txt	2008-09-04 19:48:01 UTC (rev 90827)
@@ -2,6 +2,12 @@
 CHANGES
 =======
 
+0.2.4 (unreleased)
+------------------
+
+- RESTClient() now correctly interprets https:// URLs.
+
+
 0.2.3 (2008-03-20)
 ------------------
 

Modified: z3c.rest/trunk/src/z3c/rest/client.py
===================================================================
--- z3c.rest/trunk/src/z3c/rest/client.py	2008-09-04 19:24:13 UTC (rev 90826)
+++ z3c.rest/trunk/src/z3c/rest/client.py	2008-09-04 19:48:01 UTC (rev 90827)
@@ -86,6 +86,7 @@
     zope.interface.implements(interfaces.IRESTClient)
 
     connectionFactory = httplib.HTTPConnection
+    sslConnectionFactory = httplib.HTTPSConnection
 
     def __init__(self, url=None):
         self.requestHeaders = {}
@@ -123,7 +124,10 @@
 
         # Make a connection and retrieve the result
         pieces = urlparse.urlparse(self.url)
-        connection = self.connectionFactory(pieces[1])
+        if pieces[0] == 'https':
+            connection = self.sslConnectionFactory(pieces[1])
+        else:
+            connection = self.connectionFactory(pieces[1])
         try:
             connection.request(
                 method, getFullPath(pieces, params), data, requestHeaders)

Modified: z3c.rest/trunk/src/z3c/rest/client.txt
===================================================================
--- z3c.rest/trunk/src/z3c/rest/client.txt	2008-09-04 19:24:13 UTC (rev 90826)
+++ z3c.rest/trunk/src/z3c/rest/client.txt	2008-09-04 19:48:01 UTC (rev 90827)
@@ -39,7 +39,21 @@
     <acl xlink:type="simple" xlink:href="acl" xlink:title="ACL"/>
   </folder>
 
+HTTPS URLs are also supported
 
+  >>> client = testing.RESTClient('https://localhost/')
+  Using SSL
+  >>> print client.contents
+  <?xml version="1.0" ?>
+  <folder xmlns:xlink="http://www.w3.org/1999/xlink">
+    <name></name>
+    <title></title>
+    <items>
+    </items>
+    <acl xlink:type="simple" xlink:href="acl" xlink:title="ACL"/>
+  </folder>
+
+
 Getting Resources
 -----------------
 

Modified: z3c.rest/trunk/src/z3c/rest/testing.py
===================================================================
--- z3c.rest/trunk/src/z3c/rest/testing.py	2008-09-04 19:24:13 UTC (rev 90826)
+++ z3c.rest/trunk/src/z3c/rest/testing.py	2008-09-04 19:48:01 UTC (rev 90827)
@@ -62,6 +62,13 @@
         self._response = None
 
 
+class SSLPublisherConnection(PublisherConnection):
+
+    def __init__(self, server, port=None):
+        print "Using SSL"
+        PublisherConnection.__init__(self, server, port=port)
+
+
 class PublisherResponse(object):
     """Adapter of Zope 3 response objects into httplib.HTTPResponse."""
 
@@ -81,6 +88,7 @@
     zope.interface.implements(interfaces.IPublisherRESTClient)
 
     connectionFactory = PublisherConnection
+    sslConnectionFactory = SSLPublisherConnection
 
     @apply
     def handleErrors():



More information about the Checkins mailing list