Allow setting "Accept-Language" header (#483)

Closes #445
main
Vansh Comar 2021-10-26 03:19:09 +05:30 committed by GitHub
parent 999248d71b
commit 5118ddb8b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -28,6 +28,7 @@ class Config:
self.new_tab = read_config_bool('WHOOGLE_CONFIG_NEW_TAB') self.new_tab = read_config_bool('WHOOGLE_CONFIG_NEW_TAB')
self.view_image = read_config_bool('WHOOGLE_CONFIG_VIEW_IMAGE') self.view_image = read_config_bool('WHOOGLE_CONFIG_VIEW_IMAGE')
self.get_only = read_config_bool('WHOOGLE_CONFIG_GET_ONLY') self.get_only = read_config_bool('WHOOGLE_CONFIG_GET_ONLY')
self.accept_language = False
self.safe_keys = [ self.safe_keys = [
'lang_search', 'lang_search',

View File

@ -157,6 +157,12 @@ class Request:
self.language = ( self.language = (
config.lang_search if config.lang_search else '' 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 self.mobile = bool(normal_ua) and ('Android' in normal_ua
or 'iPhone' in normal_ua) or 'iPhone' in normal_ua)
self.modified_user_agent = gen_user_agent(self.mobile) self.modified_user_agent = gen_user_agent(self.mobile)
@ -243,7 +249,12 @@ class Request:
'User-Agent': modified_user_agent '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 # view is suppressed correctly
now = datetime.now() now = datetime.now()
cookies = { cookies = {

View File

@ -177,6 +177,10 @@
<div class="config-div config-div-get-only"> <div class="config-div config-div-get-only">
<label for="config-get-only">{{ translation['config-get-only'] }}: </label> <label for="config-get-only">{{ translation['config-get-only'] }}: </label>
<input type="checkbox" name="get_only" id="config-get-only" {{ 'checked' if config.get_only else '' }}> <input type="checkbox" name="get_only" id="config-get-only" {{ 'checked' if config.get_only else '' }}>
</div>
<div class="config-div config-div-get-only">
<label for="config-accept-language">Set Accept-Language: </label>
<input type="checkbox" name="accept_language" id="config-accept-language" {{ 'checked' if config.accept_language else '' }}>
</div> </div>
<div class="config-div config-div-root-url"> <div class="config-div config-div-root-url">
<label for="config-url">{{ translation['config-url'] }}: </label> <label for="config-url">{{ translation['config-url'] }}: </label>