Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-130160: use .. program:: directive for documenting http.server CLI #131010

New issue

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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 15, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add suggestions
  • Loading branch information
donBarbos committed Mar 15, 2025
commit 034336cf2765abbc8d5dbf4ff7bded51b4de1aef
101 changes: 51 additions & 50 deletions 101 Doc/library/http.server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,56 @@ the current directory::
such as using different index file names by overriding the class attribute
:attr:`index_pages`.


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

This class is used to serve either files or output of CGI scripts from the
current directory and below. Note that mapping HTTP hierarchic structure to
local directory structure is exactly as in :class:`SimpleHTTPRequestHandler`.

.. note::

CGI scripts run by the :class:`CGIHTTPRequestHandler` class cannot execute
redirects (HTTP code 302), because code 200 (script output follows) is
sent prior to execution of the CGI script. This pre-empts the status
code.

The class will however, run the CGI script, instead of serving it as a file,
if it guesses it to be a CGI script. Only directory-based CGI are used ---
the other common server configuration is to treat special extensions as
denoting CGI scripts.

The :func:`do_GET` and :func:`do_HEAD` functions are modified to run CGI scripts
and serve the output, instead of serving files, if the request leads to
somewhere below the ``cgi_directories`` path.

The :class:`CGIHTTPRequestHandler` defines the following data member:

.. attribute:: cgi_directories

This defaults to ``['/cgi-bin', '/htbin']`` and describes directories to
treat as containing CGI scripts.

The :class:`CGIHTTPRequestHandler` defines the following method:

.. method:: do_POST()

This method serves the ``'POST'`` request type, only allowed for CGI
scripts. Error 501, "Can only POST to CGI scripts", is output when trying
to POST to a non-CGI url.

Note that CGI scripts will be run with UID of user nobody, for security
reasons. Problems with the CGI script will be translated to error 403.

.. deprecated-removed:: 3.13 3.15

:class:`CGIHTTPRequestHandler` is being removed in 3.15. CGI has not
been considered a good way to do things for well over a decade. This code
has been unmaintained for a while now and sees very little practical use.
Retaining it could lead to further :ref:`security considerations
<http.server-security>`.


.. _http-server-cli:

Command-line interface
Expand All @@ -427,7 +477,7 @@ Command-line interface
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 [OPTIONS] [port]

The following options are accepted:

Expand Down Expand Up @@ -493,55 +543,6 @@ The following options are accepted:
to exploitation. Always use within a secure environment.


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

This class is used to serve either files or output of CGI scripts from the
current directory and below. Note that mapping HTTP hierarchic structure to
local directory structure is exactly as in :class:`SimpleHTTPRequestHandler`.

.. note::

CGI scripts run by the :class:`CGIHTTPRequestHandler` class cannot execute
redirects (HTTP code 302), because code 200 (script output follows) is
sent prior to execution of the CGI script. This pre-empts the status
code.

The class will however, run the CGI script, instead of serving it as a file,
if it guesses it to be a CGI script. Only directory-based CGI are used ---
the other common server configuration is to treat special extensions as
denoting CGI scripts.

The :func:`do_GET` and :func:`do_HEAD` functions are modified to run CGI scripts
and serve the output, instead of serving files, if the request leads to
somewhere below the ``cgi_directories`` path.

The :class:`CGIHTTPRequestHandler` defines the following data member:

.. attribute:: cgi_directories

This defaults to ``['/cgi-bin', '/htbin']`` and describes directories to
treat as containing CGI scripts.

The :class:`CGIHTTPRequestHandler` defines the following method:

.. method:: do_POST()

This method serves the ``'POST'`` request type, only allowed for CGI
scripts. Error 501, "Can only POST to CGI scripts", is output when trying
to POST to a non-CGI url.

Note that CGI scripts will be run with UID of user nobody, for security
reasons. Problems with the CGI script will be translated to error 403.

.. deprecated-removed:: 3.13 3.15

:class:`CGIHTTPRequestHandler` is being removed in 3.15. CGI has not
been considered a good way to do things for well over a decade. This code
has been unmaintained for a while now and sees very little practical use.
Retaining it could lead to further :ref:`security considerations
<http.server-security>`.


.. _http.server-security:

Security Considerations
donBarbos marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.