Skip to content
Merged
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
96 changes: 56 additions & 40 deletions Doc/library/http.server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -420,47 +420,78 @@ such as using different index file names by overriding the class attribute

.. _http-server-cli:

Command-line interface
----------------------

:mod:`http.server` can also be invoked directly using the :option:`-m`
switch of the interpreter. Similar to
the previous example, this serves files relative to the current directory::

python -m http.server
python -m http.server

The following options are accepted:

.. program:: http.server

.. option:: port

The server listens to port 8000 by default. The default can be overridden
by passing the desired port number as an argument::

python -m http.server 9000

.. option:: -b, --bind <address>

Specifies a specific address to which it should bind. Both IPv4 and IPv6
addresses are supported. By default, the server binds itself to all
interfaces. For example, the following command causes the server to bind
to localhost only::

python -m http.server --bind 127.0.0.1

.. versionadded:: 3.4

.. versionchanged:: 3.8
Support IPv6 in the ``--bind`` option.

.. option:: -d, --directory <dir>

Specifies a directory to which it should serve the files. By default,
the server uses the current directory. For example, the following command
uses a specific directory::

python -m http.server --directory /tmp/

.. versionadded:: 3.7

The server listens to port 8000 by default. The default can be overridden
by passing the desired port number as an argument::
.. option:: -p, --protocol <version>

python -m http.server 9000
Specifies the HTTP version to which the server is conformant. By default,
the server is conformant to HTTP/1.0. For example, the following command
runs an HTTP/1.1 conformant server::

By default, the server binds itself to all interfaces. The option ``-b/--bind``
specifies a specific address to which it should bind. Both IPv4 and IPv6
addresses are supported. For example, the following command causes the server
to bind to localhost only::
python -m http.server --protocol HTTP/1.1

python -m http.server --bind 127.0.0.1
.. versionadded:: 3.11

.. versionchanged:: 3.4
Added the ``--bind`` option.
.. option:: --cgi

.. versionchanged:: 3.8
Support IPv6 in the ``--bind`` option.
:class:`CGIHTTPRequestHandler` can be enabled in the command line by passing
the ``--cgi`` option::

By default, the server uses the current directory. The option ``-d/--directory``
specifies a directory to which it should serve the files. For example,
the following command uses a specific directory::
python -m http.server --cgi

python -m http.server --directory /tmp/
.. deprecated-removed:: 3.13 3.15

.. versionchanged:: 3.7
Added the ``--directory`` option.
:mod:`http.server` command line ``--cgi`` support is being removed
because :class:`CGIHTTPRequestHandler` is being removed.

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::
.. warning::

python -m http.server --protocol HTTP/1.1
:class:`CGIHTTPRequestHandler` and the ``--cgi`` command line option
are not intended for use by untrusted clients and may be vulnerable
to exploitation. Always use within a secure environment.

.. versionchanged:: 3.11
Added the ``--protocol`` option.

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

Expand Down Expand Up @@ -510,21 +541,6 @@ following command runs an HTTP/1.1 conformant server::
Retaining it could lead to further :ref:`security considerations
<http.server-security>`.

:class:`CGIHTTPRequestHandler` can be enabled in the command line by passing
the ``--cgi`` option::

python -m http.server --cgi

.. deprecated-removed:: 3.13 3.15

:mod:`http.server` command line ``--cgi`` support is being removed
because :class:`CGIHTTPRequestHandler` is being removed.

.. warning::

:class:`CGIHTTPRequestHandler` and the ``--cgi`` command line option
are not intended for use by untrusted clients and may be vulnerable
to exploitation. Always use within a secure environment.

.. _http.server-security:

Expand Down
Loading