From 5118ddb8b8c70e42a01b39187d41afa3579e2379 Mon Sep 17 00:00:00 2001 From: Vansh Comar <69755265+vacom13@users.noreply.github.com> Date: Tue, 26 Oct 2021 03:19:09 +0530 Subject: [PATCH] Allow setting "Accept-Language" header (#483) Closes #445 --- app/models/config.py | 1 + app/request.py | 13 ++++++++++++- app/templates/index.html | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/config.py b/app/models/config.py index 1902009..ef4204f 100644 --- a/app/models/config.py +++ b/app/models/config.py @@ -28,6 +28,7 @@ class Config: self.new_tab = read_config_bool('WHOOGLE_CONFIG_NEW_TAB') self.view_image = read_config_bool('WHOOGLE_CONFIG_VIEW_IMAGE') self.get_only = read_config_bool('WHOOGLE_CONFIG_GET_ONLY') + self.accept_language = False self.safe_keys = [ 'lang_search', diff --git a/app/request.py b/app/request.py index 68e30d8..9bb9bd0 100644 --- a/app/request.py +++ b/app/request.py @@ -157,6 +157,12 @@ class Request: self.language = ( config.lang_search if config.lang_search else '' ) + + # For setting Accept-language Header + self.lang_interface = '' + if config.accept_language: + self.lang_interface = config.lang_interface + self.mobile = bool(normal_ua) and ('Android' in normal_ua or 'iPhone' in normal_ua) self.modified_user_agent = gen_user_agent(self.mobile) @@ -243,7 +249,12 @@ class Request: 'User-Agent': modified_user_agent } - # FIXME: Should investigate this further to ensure the consent + # Adding the Accept-Language to the Header if possible + if self.lang_interface: + headers.update({'Accept-Language': + self.lang_interface.replace('lang_', '') + + ';q=1.0'}) + # view is suppressed correctly now = datetime.now() cookies = { diff --git a/app/templates/index.html b/app/templates/index.html index 435dcf3..27b1f1b 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -177,6 +177,10 @@