Skip to content

Commit

Permalink
Fixed #27705 -- Added protocol/server_cls attributes to runserver for…
Browse files Browse the repository at this point in the history
… extensibility.
  • Loading branch information
dsanders11 authored and timgraham committed Jan 9, 2017
1 parent 9932e1b commit 49267d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions django/core/management/commands/runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

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

Expand All @@ -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(
Expand Down Expand Up @@ -128,11 +132,12 @@ def inner_run(self, *args, **options):
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,
Expand All @@ -141,7 +146,7 @@ def inner_run(self, *args, **options):
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 = {
Expand Down
6 changes: 3 additions & 3 deletions django/core/servers/basehttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ def handle(self):
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
Expand Down

0 comments on commit 49267d9

Please sign in to comment.