Skip to content

Commit

Permalink
Merge pull request gvalkov#11 from geobeau/patch-1
Browse files Browse the repository at this point in the history
Added possibility to declare custom headers in configuration
  • Loading branch information
Thib17 authored Jan 10, 2018
2 parents 9898082 + e303d8f commit 52fc55d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 7 additions & 1 deletion tailon/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def parseconfig(cfg):
'follow-names': raw_config.get('follow-names', False),
'relative-root': raw_config.get('relative-root', '/'),
'http-auth': raw_config.get('http-auth', False),
'http-headers': raw_config.get('http-headers', {}),
'users': raw_config.get('users', {}),
'wrap-lines': raw_config.get('wrap-lines', True),
'tail-lines': raw_config.get('tail-lines', 10),
Expand Down Expand Up @@ -118,10 +119,14 @@ def parseopts(args=None):
relative-root: /tailon # web app root path (default: '')
commands: [tail, grep] # allowed commands
tail-lines: 10 # number of lines to tail initially
grep-lines: 3000 # number max of lines to grep
grep-lines: 3000 # number max of lines to grep
wrap-lines: true # initial line-wrapping state
live-view: False # view files live (tail) or just search in files
http-headers: # custom http headers
Access-Control-Allow-Origin: "*"
files:
- '/var/log/messages'
- '/var/log/nginx/*.log'
Expand Down Expand Up @@ -215,6 +220,7 @@ def setup(opts):
'commands': opts.commands,
'allow-transfers': opts.allow_transfers,
'http-auth': opts.__dict__.get('http_auth', False),
'http-headers': opts.__dict__.get('http_auth', {}),
'users': dict((i.split(':') for i in opts.users)),
'follow-names': opts.follow_names,
'relative-root': opts.__dict__.get('relative_root', ''),
Expand Down
12 changes: 8 additions & 4 deletions tailon/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ class Files(BaseHandler):
def get(self, check=None):
self.application.file_lister.refresh()
self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
self.set_header('Content-Type', 'application/json')
self.set_header('Access-Control-Allow-Origin', '*')
self.set_header('Content-Type', 'application/json')

for header in self.config["http-headers"]:
self.set_header(header, self.config["http-headers"][header])

if check:
message = self.application.file_lister.has_changed
Expand All @@ -62,8 +64,10 @@ def get(self, check=None):
self.application.file_lister.refresh()
self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
self.set_header('Content-Type', 'application/json')
self.set_header('Access-Control-Allow-Origin', '*')


for header in self.config["http-headers"]:
self.set_header(header, self.config["http-headers"][header])

if check:
message = self.application.file_lister.has_changed
else:
Expand Down

0 comments on commit 52fc55d

Please sign in to comment.