Skip to content
Closed
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
11 changes: 9 additions & 2 deletions Doc/library/http.server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@ handler. Code to create and run the server looks like this::
:attr:`server_port`. The server is accessible by the handler, typically
through the handler's :attr:`server` instance variable.

.. class:: ThreadedHTTPServer(server_address, RequestHandlerClass)

The :class:`HTTPServer` must be given a *RequestHandlerClass* on instantiation,
of which this module provides three different variants:
This class is identical to HTTPServer but uses threads to handle
requests by using the :class:`~socketserver.ThreadingMixin`. This
is usefull to handle web browsers pre-opening sockets, on which

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usefull -> useful

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's a backport, should I simply fix it in a new PR?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the master and 3.7 versions are already merged, that would be simpler, sure.

:class:`HTTPServer` would wait indefinitly.

The :class:`HTTPServer` and :class:`ThreadedHTTPServer` must be given
a *RequestHandlerClass* on instantiation, of which this module
provides three different variants:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a version added comment.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Hum, what is the protocol to decide which version to put it as it's being backported? I initially though 3.8 but as it's backported ... maybe 3.6 but it's wrong (as not precise enough, it was not present in 3.6.*), so maybe versionadded:: 3.6.6?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 3.6.6 is the right answer in this case for all branches.


.. class:: BaseHTTPRequestHandler(request, client_address, server)

Expand Down
9 changes: 7 additions & 2 deletions Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
__version__ = "0.6"

__all__ = [
"HTTPServer", "BaseHTTPRequestHandler",
"HTTPServer", "ThreadedHTTPServer", "BaseHTTPRequestHandler",
"SimpleHTTPRequestHandler", "CGIHTTPRequestHandler",
]

Expand Down Expand Up @@ -139,6 +139,10 @@ def server_bind(self):
self.server_port = port


class ThreadedHTTPServer(socketserver.ThreadingMixIn, HTTPServer):
daemon_threads = True


class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):

"""HTTP request handler base class.
Expand Down Expand Up @@ -1173,7 +1177,8 @@ def run_cgi(self):


def test(HandlerClass=BaseHTTPRequestHandler,
ServerClass=HTTPServer, protocol="HTTP/1.0", port=8000, bind=""):
ServerClass=ThreadedHTTPServer,
protocol="HTTP/1.0", port=8000, bind=""):
"""Test the HTTP request handler class.

This runs an HTTP server on port 8000 (or the port argument).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
http.server now exposes a ThreadedHTTPServer class and uses it when the
module is invoked to cope with web browsers pre-opening sockets.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"and uses it when the module is invoked" ? Doesn't the user have to explicitly use the new class?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By "module is invoked" I mean running "python3 -m http.server". In the "python -m http.server" case, the ThreadedHTTPServer is used, to fix bpo-31639.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So perhaps change "is invoked" to "is run with -m" ?