Exclude one-time use parameters. Fixes #6118 (#6223)

* Exclude one-time use parameters. Fixes #6118

* Fix error.

* Delete items inplace, rather than creating new list.

* Fix stupid mistake.

* Use .index() for stability.

* Try previous idea while resetting the index.

* Shorter comment for pylint.

* More readable approach

* Fix whitespace
This commit is contained in:
Sam Bull
2018-09-12 16:38:37 -07:00
committed by ohemorange
parent 8f7209de14
commit a3b858db34
+11 -6
View File
@@ -395,12 +395,17 @@ class NginxParser(object):
addr.ipv6only = False
for directive in enclosing_block[new_vhost.path[-1]][1]:
if len(directive) > 0 and directive[0] == 'listen':
if 'default_server' in directive:
del directive[directive.index('default_server')]
if 'default' in directive:
del directive[directive.index('default')]
if 'ipv6only=on' in directive:
del directive[directive.index('ipv6only=on')]
# Exclude one-time use parameters which will cause an error if repeated.
# https://nginx.org/en/docs/http/ngx_http_core_module.html#listen
exclude = set(('default_server', 'default', 'setfib', 'fastopen', 'backlog',
'rcvbuf', 'sndbuf', 'accept_filter', 'deferred', 'bind',
'ipv6only', 'reuseport', 'so_keepalive'))
for param in exclude:
# See: github.com/certbot/certbot/pull/6223#pullrequestreview-143019225
keys = [x.split('=')[0] for x in directive]
if param in keys:
del directive[keys.index(param)]
return new_vhost