Merge pull request #26 from pkulev/pr-moveout-plain-agents
refactor: move out plain text agents to separate list.
This commit is contained in:
commit
430c56e946
1 changed files with 11 additions and 2 deletions
13
bin/srv.py
13
bin/srv.py
|
|
@ -218,11 +218,20 @@ def send_favicon():
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
@app.route("/<string:location>")
|
@app.route("/<string:location>")
|
||||||
def wttr(location = None):
|
def wttr(location = None):
|
||||||
|
plain_text_agents = [
|
||||||
|
"curl",
|
||||||
|
"httpie",
|
||||||
|
"lwp-request",
|
||||||
|
"wget",
|
||||||
|
]
|
||||||
|
|
||||||
user_agent = request.headers.get('User-Agent').lower()
|
user_agent = request.headers.get('User-Agent').lower()
|
||||||
|
|
||||||
html_output = True
|
if any(agent in user_agent for agent in plain_text_agents):
|
||||||
if 'curl' in user_agent or 'wget' in user_agent or 'httpie' in user_agent or 'lwp-request' in user_agent:
|
|
||||||
html_output = False
|
html_output = False
|
||||||
|
else:
|
||||||
|
html_output = True
|
||||||
|
|
||||||
|
|
||||||
if location == ':help':
|
if location == ':help':
|
||||||
help_ = show_help()
|
help_ = show_help()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue