Skip to content

Commit

Permalink
Better resource proxy detection
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Nov 14, 2012
1 parent e1c6fc9 commit d5c42b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ckanext/jsonpreview/plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pylons
from logging import getLogger

import ckan.plugins as p
Expand Down Expand Up @@ -35,19 +36,23 @@ def update_config(self, config):
toolkit.add_template_directory(config, 'theme/templates')
toolkit.add_resource('theme/public', 'ckanext-jsonpreview')

def proxy_enabled(self):
return pylons.config.get('ckan.resource_proxy_enabled', False)

def can_preview(self, data_dict):
resource = data_dict['resource']
format_lower = resource['format'].lower()
if format_lower in self.JSONP_FORMATS:
return True
elif format_lower in self.JSON_FORMATS and (proxy or resource['on_same_domain']):
elif format_lower in self.JSON_FORMATS and (self.proxy_enabled() or resource['on_same_domain']):
return True
return False

def setup_template_variables(self, context, data_dict):
assert self.can_preview(data_dict)
resource = data_dict['resource']
format_lower = resource['format'].lower()
if format_lower in self.JSON_FORMATS and proxy and not resource['on_same_domain']:
if format_lower in self.JSON_FORMATS and self.proxy_enabled() and not resource['on_same_domain']:
base.c.resource['url'] = proxy.get_proxified_resource_url(data_dict)

def preview_template(self, context, data_dict):
Expand Down
1 change: 1 addition & 0 deletions ckanext/resourceproxy/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def proxy_resource(context, data_dict):

shutil.copyfileobj(res, base.response)

# todo only change the status code, not the whole content
if had_http_error and hasattr(res, 'code'):
abort(res.code)

Expand Down

0 comments on commit d5c42b0

Please sign in to comment.