From a6b2565e9300665e10c677d0cab8868d8ca887ec Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Wed, 19 Aug 2015 09:07:13 -0700 Subject: [PATCH] Only provide html if client supports it We can specify via config that a file should be served as html but we should still only do so if the client supports html. Otherwise fallback on text. This allows us to have a default for log files that is rendered html in a browser but text when wgetted or viewed in a text editor. This corrects an issue where we are attempting to index a bunch of html into elasticsearch because we always get html for the log files even though the logstash http client doesn't support html. Change-Id: I35d78498034a9303bd940f57ac34f423673448db --- os_loganalyze/view.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/os_loganalyze/view.py b/os_loganalyze/view.py index b886f02..40283ad 100644 --- a/os_loganalyze/view.py +++ b/os_loganalyze/view.py @@ -213,6 +213,9 @@ class PassthroughView(collections.Iterable): def get_view_generator(filter_generator, environ, root_path, config): """Return the view to use as per the config.""" + # Determine if html is supported by the client if yes then supply html + # otherwise fallback to text. + supports_html = util.should_be_html(environ) # Check file specific conditions first view_selected = util.get_file_conditions('view', filter_generator.file_generator, @@ -225,7 +228,7 @@ def get_view_generator(filter_generator, environ, root_path, config): view_selected = config.get('general', 'view') if view_selected: - if view_selected.lower() in ['htmlview', 'html']: + if view_selected.lower() in ['htmlview', 'html'] and supports_html: return HTMLView(filter_generator) elif view_selected.lower() in ['textview', 'text']: return TextView(filter_generator) @@ -235,7 +238,7 @@ def get_view_generator(filter_generator, environ, root_path, config): # Otherwise guess if util.use_passthrough_view(filter_generator.file_generator.file_headers): return PassthroughView(filter_generator) - elif util.should_be_html(environ): + elif supports_html: return HTMLView(filter_generator) else: return TextView(filter_generator)