Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 13 additions & 2 deletions Doc/library/http.server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ provides three different variants:

.. attribute:: protocol_version

This specifies the HTTP protocol version used in responses. If set to
Specifies the HTTP version to which the server is conformant. It is sent
in responses to let the client know the server's communication
capabilities for future requests. If set to
``'HTTP/1.1'``, the server will permit HTTP persistent connections;
however, your server *must* then include an accurate ``Content-Length``
header (using :meth:`send_header`) in all of its responses to clients.
Expand Down Expand Up @@ -193,7 +195,7 @@ provides three different variants:

.. method:: handle_expect_100()

When a HTTP/1.1 compliant server receives an ``Expect: 100-continue``
When an HTTP/1.1 conformant server receives an ``Expect: 100-continue``
request header it responds back with a ``100 Continue`` followed by ``200
OK`` headers.
This method can be overridden to raise an error if the server does not
Expand Down Expand Up @@ -444,6 +446,15 @@ the following command uses a specific directory::
.. versionadded:: 3.7
``--directory`` argument was introduced.

By default, the server is conformant to HTTP/1.0. The option ``-p/--protocol``
specifies the HTTP version to which the server is conformant. For example, the
following command runs an HTTP/1.1 conformant server::

python -m http.server --protocol HTTP/1.1

.. versionadded:: 3.11
``--protocol`` argument was introduced.

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

This class is used to serve either files or output of CGI scripts from the
Expand Down
15 changes: 10 additions & 5 deletions Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,15 +1258,19 @@ def test(HandlerClass=BaseHTTPRequestHandler,
parser = argparse.ArgumentParser()
parser.add_argument('--cgi', action='store_true',
help='run as CGI server')
parser.add_argument('--bind', '-b', metavar='ADDRESS',
help='specify alternate bind address '
parser.add_argument('-b', '--bind', metavar='ADDRESS',
help='specify the address to bind to '
'(default: all interfaces)')
parser.add_argument('--directory', '-d', default=os.getcwd(),
help='specify alternate directory '
parser.add_argument('-d', '--directory', default=os.getcwd(),
help='specify the directory to serve '
'(default: current directory)')
parser.add_argument('-p', '--protocol', default='HTTP/1.0',
help='specify the HTTP version to conform to '
'(default: %(default)s)')
parser.add_argument('port', action='store', default=8000, type=int,
nargs='?',
help='specify alternate port (default: 8000)')
help='specify the port to bind to '
'(default: %(default)s)')
args = parser.parse_args()
if args.cgi:
handler_class = CGIHTTPRequestHandler
Expand All @@ -1292,4 +1296,5 @@ def finish_request(self, request, client_address):
ServerClass=DualStackServer,
port=args.port,
bind=args.bind,
protocol=args.protocol,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix command-line option ``-d``/``--directory`` in module :mod:`http.server`
which is ignored when combined with command-line option ``--cgi``. Patch by
Géry Ogam.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Add command-line option ``-p``/``--protocol`` to module :mod:`http.server`
which specifies the HTTP version to which the server is conformant (HTTP/1.1
conformant servers can now be run from the command-line interface of module
:mod:`http.server`). Patch by Géry Ogam.