This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -510,25 +467,85 @@ 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
.. _http-server-cli:
Command-line interface
----------------------
:mod:`http.server` can also be invoked directly using the :option:`-m`
switch of the interpreter. The following example illustrates how to serve
files relative to the current directory::
python -m http.server [OPTIONS] [port]
The following options are accepted:
.. program:: http.server
.. deprecated-removed:: 3.13 3.15
.. option:: port
:mod:`http.server` command line ``--cgi`` support is being removed
because :class:`CGIHTTPRequestHandler` is being removed.
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
.. option:: -p, --protocol <version>
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::
python -m http.server --protocol HTTP/1.1
.. versionadded:: 3.11
.. option:: --cgi
: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`` commandline option
: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:
Security Considerations
Security considerations
-----------------------
.. index:: pair: http.server; security
Expand Down
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[3.13] gh-130160: use .. program:: directive for documenting http.server CLI (GH-131010) #131293
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
[3.13] gh-130160: use .. program:: directive for documenting http.server CLI (GH-131010) #131293
Filter by extension
Viewed files
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing