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
This commit is contained in:
parent
6d7e65df3d
commit
a6b2565e93
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue