Exemplo n.º 1
0
    def create_item(self, url):
        aliases_limit = self.site.aliases_limit
        if (aliases_limit is not None and self.count() >= aliases_limit):
            raise LimitExceeded('Aliases limit exceeded')
        if len(url) > self.ALIAS_LEN_LIMIT:
            raise ValidationError('Url too long')

        url = url.strip().lower()
        (valid, error) = url_utils.validate_site_url(url)
        if not valid:
            raise ValidationError('Invalid url: ' + error)
        if self.find_item_by_url(url):
            raise ValidationError('Alias with this url already exists')
        return self._do_create_item(url=url_utils.remove_default_port(url))
    def create_item(self, url):
        aliases_limit = self.site.aliases_limit
        if (aliases_limit is not None and self.count() >= aliases_limit):
            raise LimitExceeded('Aliases limit exceeded')
        if len(url) > self.ALIAS_LEN_LIMIT:
            raise ValidationError('Url too long')

        url = url.strip().lower()
        (valid, error) = url_utils.validate_site_url(url)
        if not valid:
            raise ValidationError('Invalid url: ' + error)
        url = url_utils.remove_default_port(url)
        if self.find_item_by_url(url):
            raise ValidationError('Alias with this url already exists')
        return self._do_create_item(url=url)
Exemplo n.º 3
0
 def process_request(self, request):
     url = request.META.get('HTTP_SITE_URL', None)
     if url is None:
         return http.HttpResponseBadRequest('Missing Site-Url header')
     url = url_utils.remove_default_port(url)
     parts = url.split('://', 1)
     if len(parts) != 2:
         return http.HttpResponseBadRequest('Site-Url has incorrect format')
     scheme, host = parts
     if not self._alias_defined(request.site, url):
         return self._site_url_invalid(request, scheme, host)
     request.site_url = url
     request.META[SECURE_PROXY_SSL_HEADER] = scheme
     request.META['HTTP_X_FORWARDED_HOST'] = host
     # TODO: use is_secure() instead
     request.https = (scheme == 'https')
     return None
Exemplo n.º 4
0
 def process_request(self, request):
     url = request.META.get('HTTP_SITE_URL', None)
     if url is None:
         return http.HttpResponseBadRequest('Missing Site-Url header')
     url = url_utils.remove_default_port(url)
     parts = url.split('://', 1)
     if len(parts) != 2:
         return http.HttpResponseBadRequest('Site-Url has incorrect format')
     scheme, host = parts
     if not self._alias_defined(request.site, url):
         return self._site_url_invalid(request, scheme, host)
     request.site_url = url
     request.META[SECURE_PROXY_SSL_HEADER] = scheme
     request.META['HTTP_X_FORWARDED_HOST'] = host
     # TODO: use is_secure() instead
     request.https = (scheme == 'https')
     return None
Exemplo n.º 5
0
    def test_remove_default_port(self):
        self.assertEqual('http://example.com',
                         remove_default_port('http://example.com'))
        self.assertEqual('http://example.com:56',
                         remove_default_port('http://example.com:56'))

        self.assertEqual('https://example.com',
                         remove_default_port('https://example.com:443'))
        self.assertEqual('http://example.com:443',
                         remove_default_port('http://example.com:443'))

        self.assertEqual('http://example.com',
                         remove_default_port('http://example.com:80'))
        self.assertEqual('https://example.com:80',
                         remove_default_port('https://example.com:80'))