Exemple #1
0
    def wsgi_response(self, msite, environ, start_response):
        import re
        from mobilize.httputil import _get_root_url

        if re.match(r"\w+://", self.where):
            # Has explicit protocol, so must be an absolute url
            location = self.where
        else:
            # Relative URL; construct relative URL from current request
            # TODO: I think there may be bug here regarding the desktop vs. mobile domain.
            location = _get_root_url(environ, use_defined_fullsite=False) + self.where
        start_response(self.status, [("Location", location)])
        return ['<html><body><a href="{}">Go to page</a>'.format(location)]
Exemple #2
0
 def test__get_root_url(self):
     from mobilize.httputil import _get_root_url
     def env(**kw):
         environ = {
         'MWU_SRC_DOMAIN' : 'www.example.com',
         'wsgi.url_scheme' : 'http',
         'SERVER_PORT' : 80,
         'REQUEST_URI' : '/',
         }
         if 'proto' in kw:
             environ['wsgi.url_scheme'] = kw['proto']
             del kw['proto']
         environ.update(kw)
         return environ
     testdata = [
         {'environ' : env(),
          'url'     : 'http://www.example.com',
          },
         {'environ' : env(REQUEST_URI='/foo/bar'),
          'url'     : 'http://www.example.com',
          },
         {'environ' : env(REQUEST_URI='/foo/bar', SERVER_PORT=42),
          'url'     : 'http://www.example.com:42',
          },
         {'environ' : env(),
          'url'     : 'http://www.example.com',
          },
         {'environ' : env(proto='https', SERVER_PORT=443),
          'url'     : 'https://www.example.com',
          },
         ]
     for ii, td in enumerate(testdata):
         expected = td['url']
         try:
             actual = _get_root_url(td['environ'])
         except AttributeError:
             print(td['environ'])
             raise
         self.assertSequenceEqual(expected, actual)