LP#1409055 Python gateway HTTP protocol options user/berick/lp1409055-osrf-gateway-proto
authorBill Erickson <berickxx@gmail.com>
Thu, 18 Jun 2015 15:25:30 +0000 (11:25 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 18 Jun 2015 15:25:30 +0000 (11:25 -0400)
* Default to https
* Add support for modifying the default protocol
* Add support for modifying request-specific protocol

Signed-off-by: Bill Erickson <berickxx@gmail.com>
src/python/osrf/gateway.py

index eda1139..33f90d3 100644 (file)
@@ -8,12 +8,18 @@ import urllib, urllib2, sys, re
 defaultHost = None
 
 class GatewayRequest:
+
+    ''' package-wide default protocol '''
+    default_protocol = 'https'
+
     def __init__(self, service, method, params=[]):
         self.service = service
         self.method = method
         self.params = params
         self.path = 'gateway'
         self.bytes_read = 0 # for now this, this is really characters read
+        # request-specific protocol
+        self.proto = GatewayRequest.default_protocol
 
     def setPath(self, path):
         self.path = path
@@ -50,7 +56,7 @@ class GatewayRequest:
     setDefaultHost = staticmethod(setDefaultHost)
 
     def buildURL(self):
-        return 'http://%s/%s' % (defaultHost, self.path)
+        return '%s://%s/%s' % (self.proto, defaultHost, self.path)
 
 class JSONGatewayRequest(GatewayRequest):
     def __init__(self, service, method, *params):