Search code examples
cherrypy

CherryPy server name tag


When running a CherryPy app it will send server name tag something like CherryPy/version. Is it possible to rename/overwrite that from the app without modifying CherryPy so it will show something else?

Maybe something like MyAppName/version (CherryPy/version)


Solution

  • Actually asking on IRC on their official channel fumanchu gived me a more clean way to do this (using latest svn):

    import cherrypy
    from cherrypy import _cpwsgi_server 
    class HelloWorld(object):
        def index(self):
            return "Hello World!"
        index.exposed = True
    
    serverTag = "MyApp/%s (CherryPy/%s)" % ("1.2.3", cherrypy.__version__)
    _cpwsgi_server.CPWSGIServer.environ['SERVER_SOFTWARE'] = serverTag
    cherrypy.config.update({'tools.response_headers.on': True,
                            'tools.response_headers.headers': [('Server', serverTag)]})
    cherrypy.quickstart(HelloWorld())