[server] implement base_url with secure=True (closes #2508638)
authorArthur Lutz <arthur.lutz@logilab.fr>
Fri, 16 Nov 2012 11:52:06 +0100
changeset 8595 01e1e44f1eb3
parent 8594 001159e2e4f3
child 8596 bd4f5052a532
[server] implement base_url with secure=True (closes #2508638)
req.py
test/unittest_rset.py
--- a/req.py	Fri Nov 16 11:41:38 2012 +0100
+++ b/req.py	Fri Nov 16 11:52:06 2012 +0100
@@ -427,7 +427,7 @@
         """return the root url of the instance
         """
         if secure:
-            raise NotImplementedError()
+            return self.vreg.config.get('https-url', self.vreg.config['base-url'])
         return self.vreg.config['base-url']
 
     # abstract methods to override according to the web front-end #############
--- a/test/unittest_rset.py	Fri Nov 16 11:41:38 2012 +0100
+++ b/test/unittest_rset.py	Fri Nov 16 11:52:06 2012 +0100
@@ -112,6 +112,17 @@
         #                  '%stask/title/go' % baseurl)
         # empty _restpath should not crash
         self.compare_urls(req.build_url('view', _restpath=''), baseurl)
+        self.assertNotIn('https', req.build_url('view', vid='foo', rql='yo',
+                                                  __secure__=True))
+        try:
+            self.config.global_set_option('https-url', 'https://testing.fr/')
+            self.assertTrue('https', req.build_url('view', vid='foo', rql='yo',
+                                                     __secure__=True))
+            self.compare_urls(req.build_url('view', vid='foo', rql='yo',
+                                            __secure__=True),
+                              '%sview?vid=foo&rql=yo' % req.base_url(secure=True))
+        finally:
+            self.config.global_set_option('https-url', None)
 
 
     def test_build(self):