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

Support configurably omitting server header #187

Merged
Copy path View file
@@ -1,3 +1,13 @@
Unreleased (2018-05-21)
-----------------------

Features
~~~~~~~~

- Server header can be omitted by specifying `ident=None` or `ident=''`.
See https://github.com/Pylons/waitress/pull/187


1.1.0 (2017-10-10)
------------------

Copy path View file
@@ -140,3 +140,5 @@ Contributors
- Atsushi Odagiri, 2017-02-12

- David D Lowe, 2017-06-02

- Jack Wearden, 2018-05-18
Copy path View file
@@ -66,6 +66,9 @@ def slash_fixed_str(s):
s = '/' + s.lstrip('/').rstrip('/')
return s

def str_iftruthy(s):
return str(s) if s else s

This comment has been minimized.

Copy link
@bertjwregeer

bertjwregeer May 21, 2018

Member

Shouldn't this be return str(s) if s else None?


class _str_marker(str):
pass

@@ -98,7 +101,7 @@ class Adjustments(object):
('max_request_header_size', int),
('max_request_body_size', int),
('expose_tracebacks', asbool),
('ident', str),
('ident', str_iftruthy),
('asyncore_loop_timeout', int),
('asyncore_use_poll', asbool),
('unix_socket', str),
Copy path View file
@@ -251,9 +251,11 @@ def close_on_finish():
# if the server is used as a proxy.
ident = self.channel.server.adj.ident
if not server_header:
response_headers.append(('Server', ident))
if ident:
response_headers.append(('Server', ident))
else:
response_headers.append(('Via', ident))

This comment has been minimized.

Copy link
@bertjwregeer

bertjwregeer May 21, 2018

Member

If ident is falsey here, we should set it to 'waitress'. We should not append an empty Via header.


if not date_header:
response_headers.append(('Date', build_http_date(self.start_time)))

@@ -219,6 +219,17 @@ def test_ipv4_disabled(self):
def test_ipv6_disabled(self):
self.assertRaises(ValueError, self._makeOne, ipv6=False, listen="[::]:8080")

def test_server_header_removable(self):
inst = self._makeOne(ident=None)
self.assertEqual(inst.ident, None)

inst = self._makeOne(ident='')
self.assertEqual(inst.ident, '')

This comment has been minimized.

Copy link
@bertjwregeer

bertjwregeer May 21, 2018

Member

In this case the ident should be None. So that if a user sets it to an empty string in a config file, there is no ident sent.


inst = self._makeOne(ident='specific_header')
self.assertEqual(inst.ident, 'specific_header')


class TestCLI(unittest.TestCase):

def parse(self, argv):
Copy path View file
@@ -14,6 +14,7 @@ def test_it(self):
self.assertEqual(result, None)
self.assertEqual(server.ran, True)


class Test_serve_paste(unittest.TestCase):

def _callFUT(self, app, **kw):
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.