diff --git a/swift/account/server.py b/swift/account/server.py index 1d892fba..10093dc8 100644 --- a/swift/account/server.py +++ b/swift/account/server.py @@ -44,6 +44,8 @@ from swift.common.request_helpers import is_sys_or_user_meta class AccountController(BaseStorageServer): """WSGI controller for the account server.""" + server_type = 'account-server' + def __init__(self, conf, logger=None): super(AccountController, self).__init__(conf) self.logger = logger or get_logger(conf, log_route='account-server') diff --git a/swift/common/base_storage_server.py b/swift/common/base_storage_server.py index 4eb024b2..f7b4be8e 100644 --- a/swift/common/base_storage_server.py +++ b/swift/common/base_storage_server.py @@ -14,6 +14,7 @@ # limitations under the License. import inspect +from swift import __version__ as swift_version from swift.common.utils import public, timing_stats, config_true_value from swift.common.swob import Response @@ -30,6 +31,11 @@ class BaseStorageServer(object): replication_server = config_true_value(replication_server) self.replication_server = replication_server + @property + def server_type(self): + raise NotImplementedError( + 'Storage nodes have not implemented the Server type.') + @property def allowed_methods(self): if self._allowed_methods is None: @@ -64,7 +70,8 @@ class BaseStorageServer(object): :returns: swob.Response object """ # Prepare the default response - headers = {'Allow': ', '.join(self.allowed_methods)} + headers = {'Allow': ', '.join(self.allowed_methods), + 'Server': '%s/%s' % (self.server_type, swift_version)} resp = Response(status=200, request=req, headers=headers) return resp diff --git a/swift/container/server.py b/swift/container/server.py index a1743421..5aa46706 100644 --- a/swift/container/server.py +++ b/swift/container/server.py @@ -78,6 +78,7 @@ class ContainerController(BaseStorageServer): # Ensure these are all lowercase save_headers = ['x-container-read', 'x-container-write', 'x-container-sync-key', 'x-container-sync-to'] + server_type = 'container-server' def __init__(self, conf, logger=None): super(ContainerController, self).__init__(conf) diff --git a/swift/obj/server.py b/swift/obj/server.py index 72672609..64be8223 100644 --- a/swift/obj/server.py +++ b/swift/obj/server.py @@ -68,6 +68,8 @@ class EventletPlungerString(str): class ObjectController(BaseStorageServer): """Implements the WSGI application for the Swift Object Server.""" + server_type = 'object-server' + def __init__(self, conf, logger=None): """ Creates a new WSGI application for the Swift Object Server. An diff --git a/test/unit/account/test_server.py b/test/unit/account/test_server.py index d4c514d2..8717f921 100644 --- a/test/unit/account/test_server.py +++ b/test/unit/account/test_server.py @@ -28,6 +28,7 @@ import random import simplejson import xml.dom.minidom +from swift import __version__ as swift_version from swift.common.swob import Request from swift.common import constraints from swift.account.server import AccountController @@ -66,6 +67,8 @@ class TestAccountController(unittest.TestCase): self.assertTrue( verb in resp.headers['Allow'].split(', ')) self.assertEquals(len(resp.headers['Allow'].split(', ')), 7) + self.assertEquals(resp.headers['Server'], + (server_handler.server_type + '/' + swift_version)) def test_DELETE_not_found(self): req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'DELETE', diff --git a/test/unit/container/test_server.py b/test/unit/container/test_server.py index 44f19de9..d07a1446 100644 --- a/test/unit/container/test_server.py +++ b/test/unit/container/test_server.py @@ -31,6 +31,7 @@ import random from eventlet import spawn, Timeout, listen import simplejson +from swift import __version__ as swift_version from swift.common.swob import Request, HeaderKeyDict import swift.container from swift.container import server as container_server @@ -312,6 +313,8 @@ class TestContainerController(unittest.TestCase): self.assertTrue( verb in resp.headers['Allow'].split(', ')) self.assertEquals(len(resp.headers['Allow'].split(', ')), 7) + self.assertEquals(resp.headers['Server'], + (self.controller.server_type + '/' + swift_version)) def test_PUT(self): req = Request.blank( diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py index 2fe69f34..111f1f02 100755 --- a/test/unit/obj/test_server.py +++ b/test/unit/obj/test_server.py @@ -38,6 +38,7 @@ from eventlet.green import httplib from nose import SkipTest +from swift import __version__ as swift_version from test.unit import FakeLogger, debug_logger, mocked_http_conn from test.unit import connect_tcp, readuntil2crlfs, patch_policies from swift.obj import server as object_server @@ -1136,6 +1137,8 @@ class TestObjectController(unittest.TestCase): self.assertTrue( verb in resp.headers['Allow'].split(', ')) self.assertEquals(len(resp.headers['Allow'].split(', ')), 8) + self.assertEquals(resp.headers['Server'], + (server_handler.server_type + '/' + swift_version)) def test_GET(self): # Test swift.obj.server.ObjectController.GET