Skip to content

Commit

Permalink
Bug fix kimchi-project#189: Forcing download of user log file
Browse files Browse the repository at this point in the history
The error in staticfile() happens when the browser tries to open
a recently created file in a separated tab/window but this file
isn't declared in the cherry-py config with tools.staticfile.on,
like '/favicon.ico' for example.

A suitable solution to avoid the error is to force the browser to
download the file instead of opening it. According to the Cherry-py
docs:

"Using "application/x-download" response content-type, you can
tell a browser that a resource should be downloaded onto the
user’s machine rather than displayed."

This patch set the application type of all '.txt' files created
under the /data/logs dir as 'application/x-download'.

Signed-off-by: Daniel Henrique Barboza <[email protected]>
  • Loading branch information
danielhb authored and alinefm committed Mar 27, 2017
1 parent a39da06 commit 20865ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/wok/config.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ class WokConfig(dict):
'/data/logs': {
'tools.staticdir.on': True,
'tools.staticdir.dir': '%s/logs' % paths.state_dir,
'tools.staticdir.content_types': {
'txt': 'application/x-download'
},
'tools.nocache.on': False,
'tools.wokauth.on': True,
},
Expand Down
5 changes: 4 additions & 1 deletion tests/test_config.py.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# Project Wok
#
# Copyright IBM Corp, 2014-2016
# Copyright IBM Corp, 2014-2017
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -84,6 +84,9 @@ class ConfigTests(unittest.TestCase):
'/data/logs': {
'tools.staticdir.on': True,
'tools.staticdir.dir': '%s/logs' % paths.state_dir,
'tools.staticdir.content_types': {
'txt': 'application/x-download'
},
'tools.nocache.on': False,
'tools.wokauth.on': True,
},
Expand Down

0 comments on commit 20865ce

Please sign in to comment.