Repository: searxng/searxng

Issue:
Searxng 1.0.0-1487-687bdef4 can't save preferences after updating
Hi all.

After updating SearxNG to 1.0.0-1487-687bdef4, it seems impossible to save the preferences.
The preference pages opens correctly, but upon pressing "Save" the attached message appears from nginx (page unavailable).

It was working correctly before the update (sorry, can't remember which version I was using back then).

I guess it's not really a bug, but most likely some kind of misconfiguration on my part.
May someone suggest me what to check to make it work again?

SearxNG was installed using the installation script on Arch Linux, without Morty or Filtron, as this is a purely personal instance.

I can give the URL of the instance, if needed.

Thanks a lot in advance.

EDIT: nginx logs say the following

` *36 upstream sent too big header while reading response header from upstream, client: 147.xxx.xxx.xxx, server: searx.xxx.xyz, request: "POST /preferences HTTP/1.1", upstream: "uwsgi://unix:/run/uwsgi/app/searx/socket:", host: "searx.xxx.xyz"
`

![image](https://user-images.githubusercontent.com/25054477/149298574-c3773444-ffe9-4564-875a-0e310732dcdc.png)



Discussion:
It seems that the whole list of enabled and disabled engines are saved instead of the different compare to the default settings.
Perhaps related to the recent changes on /preferences
> It seems that the whole list of enabled and disabled engines

Oops now I realize, this is also the reason why we need to increase the read buffer size in filtron #738
Thanks a lot for your response, @dalf . Is there any workaround I can put in place on my part? Sorry, I'd like to actively contribute to the code but my programming skills are nonexistent.
@catfluoride : you can try to use an older version.
`1.0.0-1447-a583d095` seems a good candidate, but I haven't tested (it's a guess that this version works).

---

https://github.com/searxng/searxng/pull/708 was merged just after the commit a583d095

Thank you, I need to learn how to downgrade. I'll give it a try later.

Resolving patch:
diff --git a/searx/preferences.py b/searx/preferences.py
--- a/searx/preferences.py
+++ b/searx/preferences.py
@@ -205,6 +205,7 @@ def __init__(self, name: str, choices: Dict[str, bool], locked: bool = False):
         self.name = name
         self.choices = choices
         self.locked = locked
+        self.default_choices = dict(choices)
 
     def transform_form_items(self, items):
         # pylint: disable=no-self-use
@@ -241,8 +242,10 @@ def disabled(self):
 
     def save(self, resp: flask.Response):
         """Save cookie in the HTTP reponse obect"""
-        resp.set_cookie('disabled_{0}'.format(self.name), ','.join(self.disabled), max_age=COOKIE_MAX_AGE)
-        resp.set_cookie('enabled_{0}'.format(self.name), ','.join(self.enabled), max_age=COOKIE_MAX_AGE)
+        disabled_changed = (k for k in self.disabled if self.default_choices[k])
+        enabled_changed = (k for k in self.enabled if not self.default_choices[k])
+        resp.set_cookie('disabled_{0}'.format(self.name), ','.join(disabled_changed), max_age=COOKIE_MAX_AGE)
+        resp.set_cookie('enabled_{0}'.format(self.name), ','.join(enabled_changed), max_age=COOKIE_MAX_AGE)
 
     def get_disabled(self):
         return self.transform_values(list(self.disabled))


Test patch: