From e5e37473573ab5813479a8e570ac379e87bb81a1 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Mon, 9 Jan 2017 08:41:33 -0700 Subject: [PATCH] Fixed #27705 -- Added protocol/server_cls attributes to runserver for extensibility. --- django/core/management/commands/runserver.py | 11 ++++++++--- django/core/servers/basehttp.py | 6 +++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py index b757783e5e..0bfbd5b68e 100644 --- a/django/core/management/commands/runserver.py +++ b/django/core/management/commands/runserver.py @@ -9,7 +9,9 @@ from datetime import datetime from django.conf import settings from django.core.management.base import BaseCommand, CommandError -from django.core.servers.basehttp import get_internal_wsgi_application, run +from django.core.servers.basehttp import ( + WSGIServer, get_internal_wsgi_application, run, +) from django.utils import autoreload, six from django.utils.encoding import force_text, get_system_encoding @@ -30,6 +32,8 @@ class Command(BaseCommand): leave_locale_alone = True default_port = '8000' + protocol = 'http' + server_cls = WSGIServer def add_arguments(self, parser): parser.add_argument( @@ -128,11 +132,12 @@ class Command(BaseCommand): self.stdout.write(now) self.stdout.write(( "Django version %(version)s, using settings %(settings)r\n" - "Starting development server at http://%(addr)s:%(port)s/\n" + "Starting development server at %(protocol)s://%(addr)s:%(port)s/\n" "Quit the server with %(quit_command)s.\n" ) % { "version": self.get_version(), "settings": settings.SETTINGS_MODULE, + "protocol": self.protocol, "addr": '[%s]' % self.addr if self._raw_ipv6 else self.addr, "port": self.port, "quit_command": quit_command, @@ -141,7 +146,7 @@ class Command(BaseCommand): try: handler = self.get_handler(*args, **options) run(self.addr, int(self.port), handler, - ipv6=self.use_ipv6, threading=threading) + ipv6=self.use_ipv6, threading=threading, server_cls=self.server_cls) except socket.error as e: # Use helpful error messages instead of ugly tracebacks. ERRORS = { diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py index b6fd7b17f6..3928d8c3ff 100644 --- a/django/core/servers/basehttp.py +++ b/django/core/servers/basehttp.py @@ -160,12 +160,12 @@ class WSGIRequestHandler(simple_server.WSGIRequestHandler, object): handler.run(self.server.get_app()) -def run(addr, port, wsgi_handler, ipv6=False, threading=False): +def run(addr, port, wsgi_handler, ipv6=False, threading=False, server_cls=WSGIServer): server_address = (addr, port) if threading: - httpd_cls = type(str('WSGIServer'), (socketserver.ThreadingMixIn, WSGIServer), {}) + httpd_cls = type(str('WSGIServer'), (socketserver.ThreadingMixIn, server_cls), {}) else: - httpd_cls = WSGIServer + httpd_cls = server_cls httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6) if threading: # ThreadingMixIn.daemon_threads indicates how threads will behave on an