mirror of
https://github.com/django/daphne.git
synced 2024-11-21 23:46:33 +03:00
Support for passing server name as cli argument (#231)
This commit is contained in:
parent
cc344c6e34
commit
9c574083ff
|
@ -150,6 +150,13 @@ class CommandLineInterface(object):
|
|||
"application",
|
||||
help="The application to dispatch to as path.to.module:instance.path",
|
||||
)
|
||||
self.parser.add_argument(
|
||||
"-s",
|
||||
"--server-name",
|
||||
dest="server_name",
|
||||
help="specify which value should be passed to response header Server attribute",
|
||||
default="Daphne",
|
||||
)
|
||||
|
||||
self.server = None
|
||||
|
||||
|
@ -268,5 +275,6 @@ class CommandLineInterface(object):
|
|||
proxy_forwarded_proto_header="X-Forwarded-Proto"
|
||||
if args.proxy_headers
|
||||
else None,
|
||||
server_name=args.server_name,
|
||||
)
|
||||
self.server.run()
|
||||
|
|
|
@ -239,6 +239,8 @@ class WebRequest(http.Request):
|
|||
# Write headers
|
||||
for header, value in message.get("headers", {}):
|
||||
self.responseHeaders.addRawHeader(header, value)
|
||||
if self.server.server_name and self.server.server_name.lower() != "daphne":
|
||||
self.setHeader(b"server", self.server.server_name.encode("utf-8"))
|
||||
logger.debug(
|
||||
"HTTP %s response started for %s", message["status"], self.client_addr
|
||||
)
|
||||
|
|
|
@ -54,6 +54,7 @@ class Server(object):
|
|||
websocket_handshake_timeout=5,
|
||||
application_close_timeout=10,
|
||||
ready_callable=None,
|
||||
server_name="Daphne",
|
||||
# Deprecated and does not work, remove in version 2.2
|
||||
ws_protocols=None,
|
||||
):
|
||||
|
@ -77,6 +78,7 @@ class Server(object):
|
|||
self.verbosity = verbosity
|
||||
self.abort_start = False
|
||||
self.ready_callable = ready_callable
|
||||
self.server_name = server_name
|
||||
# Check our construction is actually sensible
|
||||
if not self.endpoints:
|
||||
logger.error("No endpoints. This server will not listen on anything.")
|
||||
|
@ -87,7 +89,7 @@ class Server(object):
|
|||
self.connections = {}
|
||||
# Make the factory
|
||||
self.http_factory = HTTPFactory(self)
|
||||
self.ws_factory = WebSocketFactory(self, server="Daphne")
|
||||
self.ws_factory = WebSocketFactory(self, server=self.server_name)
|
||||
self.ws_factory.setProtocolOptions(
|
||||
autoPingTimeout=self.ping_timeout,
|
||||
allowNullOrigin=True,
|
||||
|
|
Loading…
Reference in New Issue
Block a user