Detecting text mode browser requests

merge-requests/30/head
Bob Mottram 2022-07-13 12:48:21 +01:00
parent e280c92d8f
commit ffbde038bc
2 changed files with 6 additions and 6 deletions

View File

@ -183,6 +183,7 @@ from webapp_confirm import html_confirm_unblock
from webapp_person_options import person_minimize_images
from webapp_person_options import person_undo_minimize_images
from webapp_person_options import html_person_options
from webapp_timeline import text_mode_browser
from webapp_timeline import html_shares
from webapp_timeline import html_wanted
from webapp_timeline import html_inbox
@ -657,8 +658,7 @@ class PubServer(BaseHTTPRequestHandler):
return False
if accept_str.startswith('*'):
if self.headers.get('User-Agent'):
if 'ELinks' in self.headers['User-Agent'] or \
'Lynx' in self.headers['User-Agent']:
if text_mode_browser(self.headers['User-Agent']):
return True
return False
if 'json' in accept_str:

View File

@ -382,10 +382,10 @@ def _html_timeline_keyboard(moderator: bool, text_mode_banner: str,
follow_approvals)
def _text_mode_browser(ua_str: str) -> bool:
def text_mode_browser(ua_str: str) -> bool:
"""Does the user agent indicate a text mode browser?
"""
text_mode_agents = ('Lynx/', 'w3m/', 'Links (', 'Emacs/')
text_mode_agents = ('Lynx/', 'w3m/', 'Links (', 'Emacs/', 'ELinks')
for agent in text_mode_agents:
if agent in ua_str:
return True
@ -413,7 +413,7 @@ def _html_timeline_end(base_dir: str, nickname: str, domain_full: str,
# right column
right_column_str = ''
if not _text_mode_browser(ua_str):
if not text_mode_browser(ua_str):
right_column_str = \
get_right_column_content(base_dir, nickname, domain_full,
http_prefix, translate,
@ -825,7 +825,7 @@ def html_timeline(default_timeline: str,
# left column
left_column_str = ''
if not _text_mode_browser(ua_str):
if not text_mode_browser(ua_str):
left_column_str = \
get_left_column_content(base_dir, nickname, domain_full,
http_prefix, translate,