Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting Accept-Language header #483

Merged
merged 2 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, **kwargs):
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',
Expand Down
13 changes: 12 additions & 1 deletion app/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ def __init__(self, normal_ua, root_path, config: Config):
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)
Expand Down Expand Up @@ -243,7 +249,12 @@ def send(self, base_url=SEARCH_URL, query='', attempt=0,
'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 = {
Expand Down
4 changes: 4 additions & 0 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@
<div class="config-div config-div-get-only">
<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 '' }}>
</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 class="config-div config-div-root-url">
<label for="config-url">{{ translation['config-url'] }}: </label>
Expand Down