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

Add ability to use arguments parameter to actually go through to Backends #87

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Running:

chaussette

starts a very simple HTTP sample server on port 8080.
starts a very simple HTTP sample server on port 8080.


Starting a WSGI application using chaussette is simply a matter of calling:
Expand Down Expand Up @@ -71,7 +71,7 @@ In these examples, we start a standalone WSGI server, but the spirit of
chaussette is to be managed by Circus_, as described
https://chaussette.readthedocs.io/en/latest/#using-chaussette-in-circus


Links
-----

Expand All @@ -87,6 +87,16 @@ Links
Changelog
---------

Siyavula Fork - 2018-06-04
~~~~~~~~~~~~~~~~~~~~~~~~~~

Chaussette has NO support for actually transferring the arguments captured (under `arguments`) to
the webserver even though it appears exactly what it is intended for. This fork has been
specifically tested with Waitress but the change should work for other backends as well. This fork
assumes that those arguments (while still optional) are keyword arguments and then passes them in
when creating the server.


1.3.0 - 2015-06-01
~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion chaussette/backend/_eventlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Server(object):
def __init__(self, listener, application=None, backlog=2048,
socket_type=socket.SOCK_STREAM,
address_family=socket.AF_INET,
disable_monkeypatch=False):
disable_monkeypatch=False, **kw):
self.address_family = address_family
self.socket_type = socket_type
if not disable_monkeypatch:
Expand Down
2 changes: 1 addition & 1 deletion chaussette/backend/_meinheld.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Server(object):
def __init__(self, listener, application=None, backlog=2048,
socket_type=socket.SOCK_STREAM,
address_family=socket.AF_INET,
disable_monkeypatch=False):
disable_monkeypatch=False, **kw):
self.address_family = address_family
self.socket_type = socket_type
if not disable_monkeypatch:
Expand Down
8 changes: 6 additions & 2 deletions chaussette/backend/_waitress.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ def __init__(self, listener, application=None, backlog=2048,
self._fd = None

self._chaussette_family_and_type = address_family, socket_type

# Waitress can't handle this kwarg
kw.pop('disable_monkeypatch')

# check if waitress has IPv6 support (waitress >= 1.0)
if hasattr(waitress.compat, 'HAS_IPV6'):
ipv6 = address_family == socket.AF_INET6
super(Server, self).__init__(application, backlog=backlog,
host=host, port=port, ipv6=ipv6)
host=host, port=port, ipv6=ipv6, **kw)
else:
super(Server, self).__init__(application, backlog=backlog,
host=host, port=port)
host=host, port=port, **kw)

def create_socket(self, family, type):
# Ignore parameters passed by waitress to use chaussette options
Expand Down
14 changes: 11 additions & 3 deletions chaussette/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def make_server(app, host=None, port=None, backend='wsgiref', backlog=2048,
spawn=None, logger=None, address_family=socket.AF_INET,
socket_type=socket.SOCK_STREAM, graceful_timeout=None,
disable_monkeypatch=False):
disable_monkeypatch=False, webserver_kwargs=None):

logger = logger or chaussette_logger
logger.info('Application is %r' % app)
Expand All @@ -29,9 +29,10 @@ def make_server(app, host=None, port=None, backend='wsgiref', backlog=2048,
'backlog': backlog,
'address_family': address_family,
'socket_type': socket_type,
'disable_monkeypatch': disable_monkeypatch
'disable_monkeypatch': disable_monkeypatch,
}

server_class_kwargs.update(webserver_kwargs or {})
if spawn is not None:
server_class_kwargs['spawn'] = spawn
if graceful_timeout is not None:
Expand Down Expand Up @@ -207,14 +208,21 @@ def main():

def inner():
try:
# Assumes that all arguments are kwargs - refactor for args as required
webserver_kwargs = {}
for argument in args.arguments:
key, value = argument.split('=')
webserver_kwargs[key] = value

httpd = make_server(app, host=host, port=args.port,
backend=args.backend, backlog=args.backlog,
spawn=args.spawn,
graceful_timeout=args.graceful_timeout,
logger=logger,
address_family=address_family,
socket_type=_SOCKET_TYPE[args.socket_type],
disable_monkeypatch=args.no_monkey)
disable_monkeypatch=args.no_monkey,
webserver_kwargs=webserver_kwargs)
try:
httpd.serve_forever()
except KeyboardInterrupt:
Expand Down