Skip to content

Commit

Permalink
Add ServerAdapter for CherryPy >= 9
Browse files Browse the repository at this point in the history
Since CherryPy >= 9, the server part of CherryPy has been extracted and named Cheroot. Thus the old CherryPy ServerAdapter does not work for CherryPy >= 9: the import fails, and the SSL part should be different too. Cheroot can be installed (git install cheroot) without CherryPy so that we can just have a CherootServer adapter in addition to the CherryPyServer adapter for the older versions.

(cherry picked from commit b9229ee)
Signed-off-by: Juerg Haefliger <juergh@protonmail.com>
  • Loading branch information
06180339 authored and juergh committed May 24, 2022
1 parent e1be22d commit 888aa8e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,25 @@ def run(self, handler): # pragma: no cover
server.stop()


class CherootServer(ServerAdapter):
def run(self, handler): # pragma: no cover
from cheroot import wsgi
from cheroot.ssl import builtin
self.options['bind_addr'] = (self.host, self.port)
self.options['wsgi_app'] = handler
certfile = self.options.pop('certfile', None)
keyfile = self.options.pop('keyfile', None)
chainfile = self.options.pop('chainfile', None)
server = wsgi.Server(**self.options)
if certfile and keyfile:
server.ssl_adapter = builtin.BuiltinSSLAdapter(
certfile, keyfile, chainfile)
try:
server.start()
finally:
server.stop()


class WaitressServer(ServerAdapter):
def run(self, handler):
from waitress import serve
Expand Down

0 comments on commit 888aa8e

Please sign in to comment.