Skip to content

Commit b19ee64

Browse files
committed
remove http.server.CGIHTTPRequestHandler and --cgi flag
1 parent 30b1d8f commit b19ee64

File tree

10 files changed

+23
-750
lines changed

10 files changed

+23
-750
lines changed

Doc/deprecations/pending-removal-in-3.15.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Pending removal in Python 3.15
2020

2121
* :mod:`http.server`:
2222

23-
* The obsolete and rarely used :class:`~http.server.CGIHTTPRequestHandler`
23+
* The obsolete and rarely used :class:`!http.server.CGIHTTPRequestHandler`
2424
has been deprecated since Python 3.13.
2525
No direct replacement exists.
2626
*Anything* is better than CGI to interface

Doc/library/http.server.rst

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -459,55 +459,6 @@ such as using different index file names by overriding the class attribute
459459
:attr:`index_pages`.
460460

461461

462-
.. class:: CGIHTTPRequestHandler(request, client_address, server)
463-
464-
This class is used to serve either files or output of CGI scripts from the
465-
current directory and below. Note that mapping HTTP hierarchic structure to
466-
local directory structure is exactly as in :class:`SimpleHTTPRequestHandler`.
467-
468-
.. note::
469-
470-
CGI scripts run by the :class:`CGIHTTPRequestHandler` class cannot execute
471-
redirects (HTTP code 302), because code 200 (script output follows) is
472-
sent prior to execution of the CGI script. This pre-empts the status
473-
code.
474-
475-
The class will however, run the CGI script, instead of serving it as a file,
476-
if it guesses it to be a CGI script. Only directory-based CGI are used ---
477-
the other common server configuration is to treat special extensions as
478-
denoting CGI scripts.
479-
480-
The :func:`do_GET` and :func:`do_HEAD` functions are modified to run CGI scripts
481-
and serve the output, instead of serving files, if the request leads to
482-
somewhere below the ``cgi_directories`` path.
483-
484-
The :class:`CGIHTTPRequestHandler` defines the following data member:
485-
486-
.. attribute:: cgi_directories
487-
488-
This defaults to ``['/cgi-bin', '/htbin']`` and describes directories to
489-
treat as containing CGI scripts.
490-
491-
The :class:`CGIHTTPRequestHandler` defines the following method:
492-
493-
.. method:: do_POST()
494-
495-
This method serves the ``'POST'`` request type, only allowed for CGI
496-
scripts. Error 501, "Can only POST to CGI scripts", is output when trying
497-
to POST to a non-CGI url.
498-
499-
Note that CGI scripts will be run with UID of user nobody, for security
500-
reasons. Problems with the CGI script will be translated to error 403.
501-
502-
.. deprecated-removed:: 3.13 3.15
503-
504-
:class:`CGIHTTPRequestHandler` is being removed in 3.15. CGI has not
505-
been considered a good way to do things for well over a decade. This code
506-
has been unmaintained for a while now and sees very little practical use.
507-
Retaining it could lead to further :ref:`security considerations
508-
<http.server-security>`.
509-
510-
511462
.. _http-server-cli:
512463

513464
Command-line interface
@@ -564,24 +515,6 @@ The following options are accepted:
564515

565516
.. versionadded:: 3.11
566517

567-
.. option:: --cgi
568-
569-
:class:`CGIHTTPRequestHandler` can be enabled in the command line by passing
570-
the ``--cgi`` option::
571-
572-
python -m http.server --cgi
573-
574-
.. deprecated-removed:: 3.13 3.15
575-
576-
:mod:`http.server` command line ``--cgi`` support is being removed
577-
because :class:`CGIHTTPRequestHandler` is being removed.
578-
579-
.. warning::
580-
581-
:class:`CGIHTTPRequestHandler` and the ``--cgi`` command-line option
582-
are not intended for use by untrusted clients and may be vulnerable
583-
to exploitation. Always use within a secure environment.
584-
585518
.. option:: --tls-cert
586519

587520
Specifies a TLS certificate chain for HTTPS connections::

Doc/whatsnew/3.13.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ New Deprecations
18711871

18721872
* :mod:`http.server`:
18731873

1874-
* Deprecate :class:`~http.server.CGIHTTPRequestHandler`,
1874+
* Deprecate :class:`!http.server.CGIHTTPRequestHandler`,
18751875
to be removed in Python 3.15.
18761876
Process-based CGI HTTP servers have been out of favor for a very long time.
18771877
This code was outdated, unmaintained, and rarely used.

Doc/whatsnew/3.15.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,13 @@ Deprecated
118118
Removed
119119
=======
120120

121-
module_name
121+
http.server
122122
-----------
123123

124-
* TODO
124+
* The :class:`!http.server.CGIHTTPRequestHandler` class and
125+
the ``--cgi`` flag to the :program:`python -m http.server`
126+
command-line interface. Those are deprecated since 3.13.
127+
(Contributed by Bénédikt Tran in :gh:`133810`.)
125128

126129

127130
Porting to Python 3.15

Lib/http/client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,10 @@ def _strip_ipv6_iface(enc_name: bytes) -> bytes:
181181
return enc_name
182182

183183
class HTTPMessage(email.message.Message):
184-
# XXX The only usage of this method is in
185-
# http.server.CGIHTTPRequestHandler. Maybe move the code there so
186-
# that it doesn't need to be part of the public API. The API has
187-
# never been defined so this could cause backwards compatibility
188-
# issues.
184+
185+
# The getallmatchingheaders() method was only used in by the CGI handler
186+
# that was removed in Python 3.15. However, since the public API was not
187+
# properly defined, it will be kept for backwards compatibility reasons.
189188

190189
def getallmatchingheaders(self, name):
191190
"""Find all header lines matching a given header name.

0 commit comments

Comments
 (0)