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
@@ -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,11 @@ def slash_fixed_str(s):
s = '/' + s.lstrip('/').rstrip('/')
return s

def str_ifnotnone(s):
if s is None:
return None

This comment has been minimized.

Copy link
@bertjwregeer

bertjwregeer May 19, 2018

Member

This line is not yet covered by the test. The test is using a bunch of dummies, instead you'll want to add to https://github.com/Pylons/waitress/blob/master/waitress/tests/test_adjustments.py

return str(s)

class _str_marker(str):
pass

@@ -98,7 +103,7 @@ class Adjustments(object):
('max_request_header_size', int),
('max_request_body_size', int),
('expose_tracebacks', asbool),
('ident', str),
('ident', str_ifnotnone),
('asyncore_loop_timeout', int),
('asyncore_use_poll', asbool),
('unix_socket', str),
Copy path View file
@@ -250,10 +250,12 @@ def close_on_finish():
# Set the Server and Date field, if not yet specified. This is needed
# if the server is used as a proxy.
ident = self.channel.server.adj.ident
if not server_header:
response_headers.append(('Server', ident))
else:
response_headers.append(('Via', ident))
if ident is not None:
if not server_header:
response_headers.append(('Server', ident))
else:
response_headers.append(('Via', ident))

This comment has been minimized.

Copy link
@bertjwregeer

bertjwregeer May 19, 2018

Member

This should not be removed if ident is not set. We always went to send a Via header even if there is no user provided ident to make sure that that if waitress is used as a proxy it can't be used to do proxy looping. If there is no user provided ident, we need to make sure to set it to something reasonable like "waitress".

This comment has been minimized.

Copy link
@bertjwregeer

bertjwregeer May 19, 2018

Member

I'm okay with dropping the Server header if none is set by the WSGI app, but we should absolutely set a Via header if a Server header is set by the WSGI app (likely means that waitress is being used as some sort of proxy).

If you also want to drop any potentially proxied Server header, I would recommend using some WSGI middleware to drop it from the response before it gets to Waitress, and then Waitress won't add a Via header.


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

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

def test_empty_server_header(self):
server = DummyServerFactory()

This comment has been minimized.

Copy link
@bertjwregeer

bertjwregeer May 19, 2018

Member

DummyServerFactory uses a DummyAdjustment.

app = object()
result = self._callFUT(app, _server=server, _quiet=True, ident=None)
self.assertIsNone(server.adj.ident)


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.