def wms_proxy_view(request, wms_source_id): if request.method != 'GET': raise PermissionDenied() # If lizard_security decides the current user is not allowed to see # this wms_source, Http404 will be raised wms_source = get_object_or_404( models.WMSSource, pk=wms_source_id) url = url_utils.combine_url_and_params( wms_source.url, request.GET) # In debug mode, just redirect if settings.DEBUG: return HttpResponseRedirect(url) # use Nginx X-Accel-Redirect in production proxied_wms_servers = settings.WMS_PROXIED_WMS_SERVERS for proxied_domain, internal_url in proxied_wms_servers.items(): if proxied_domain in url: url = url.replace( proxied_domain, internal_url) break response = HttpResponse() response['X-Accel-Redirect'] = url return response
def test_empty_params_dict(self): self.assertEquals( url_utils.combine_url_and_params( 'http://example.com/', {}), 'http://example.com/')
def test_escaping(self): self.assertEquals( url_utils.combine_url_and_params( 'http://example.com/', {'question': 'answer&ersand'}), 'http://example.com/?question=answer%26ampersand')
def test_escaping_space(self): self.assertEquals( url_utils.combine_url_and_params( 'http://example.com/', {'question': 'answer with spaces'}), 'http://example.com/?question=answer+with+spaces')
def test_domain_without_slash(self): self.assertEquals( url_utils.combine_url_and_params( 'http://example.com', {'question': 'answer'}), 'http://example.com/?question=answer')
def test_existing_param(self): self.assertEquals( url_utils.combine_url_and_params( 'http://example.com/?one=two', {'question': 'answer'}), 'http://example.com/?one=two&question=answer')