CherryPy server name tag

后端 未结 3 1926
一向
一向 2021-01-12 08:42

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

3条回答
  •  攒了一身酷
    2021-01-12 09:21

    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())
    

提交回复
热议问题