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-85162: Add HTTPSServer to http.server #129607

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 54 commits into from
Apr 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
5bfc939
Add support HTTPS in http.server
donBarbos Feb 2, 2025
b382985
Correct style code
donBarbos Feb 2, 2025
4cc80c5
Add tests for HTTPSServer
donBarbos Feb 2, 2025
75fff2b
Update options
donBarbos Feb 3, 2025
64c3070
Update docs
donBarbos Feb 3, 2025
e4652a7
Merge branch 'main' into issue-85162
donBarbos Feb 3, 2025
abd949c
Revert "Correct style code"
donBarbos Feb 3, 2025
8fc2311
Merge branch 'main' into issue-85162
donBarbos Feb 3, 2025
4f587bd
Update docs and correct raising errors
donBarbos Feb 3, 2025
db796cd
Add helper method _create_context
donBarbos Feb 3, 2025
96d4a68
Update docs and replace password option
donBarbos Feb 4, 2025
947f581
Update Lib/http/server.py
donBarbos Feb 15, 2025
b8ba151
Update Doc/library/http.server.rst
donBarbos Feb 15, 2025
97e2032
Update Doc/library/http.server.rst
donBarbos Feb 15, 2025
bd97fd6
Update Doc/library/http.server.rst
donBarbos Feb 15, 2025
15b2581
Update Doc/library/http.server.rst
donBarbos Feb 15, 2025
1951e22
Update Doc/library/http.server.rst
donBarbos Feb 15, 2025
b4e1eba
Update Lib/http/server.py
donBarbos Feb 15, 2025
4838ff8
Update Lib/http/server.py
donBarbos Feb 15, 2025
3a7821f
Update Lib/http/server.py
donBarbos Feb 15, 2025
85ee1b5
Update Lib/http/server.py
donBarbos Feb 15, 2025
196e71d
Update Doc/library/http.server.rst
donBarbos Feb 15, 2025
efd44a4
Update Doc/library/http.server.rst
donBarbos Feb 15, 2025
4b33ecc
Update Doc/whatsnew/3.14.rst
donBarbos Feb 15, 2025
5fcc947
Update Doc/whatsnew/3.14.rst
donBarbos Feb 15, 2025
4df61de
Update Lib/http/server.py
donBarbos Feb 15, 2025
08a5720
Add suggestions
donBarbos Feb 15, 2025
43ae6b8
Merge branch 'main' into issue-85162
donBarbos Feb 15, 2025
6cff350
Update 2025-02-02-00-30-09.gh-issue-85162.BNF_aJ.rst
donBarbos Feb 15, 2025
0b2d50a
Update http.server.rst
donBarbos Feb 15, 2025
8a7f316
Move function back
donBarbos Feb 15, 2025
e7d9250
Add test case for pass certdata
donBarbos Feb 15, 2025
1b64e3d
Update test_httpservers.py
donBarbos Feb 15, 2025
c004b71
Update test_httpservers.py
donBarbos Feb 15, 2025
b6ba37f
Update test_httpservers.py
donBarbos Feb 15, 2025
bf86a0d
Update test_httpservers.py
donBarbos Feb 15, 2025
b89f4c4
Update test_httpservers.py
donBarbos Feb 15, 2025
c6879de
Update test_httpservers.py
donBarbos Feb 15, 2025
1ee542f
Update test_httpservers.py
donBarbos Feb 15, 2025
0c40dd7
Add more suggestions
donBarbos Feb 15, 2025
6e51ec3
Update docs
donBarbos Feb 15, 2025
4b85253
Update
donBarbos Feb 15, 2025
09d32b3
Update tests
donBarbos Feb 15, 2025
4b8786f
Correct style code
donBarbos Feb 15, 2025
96ba50d
Wrap the lines
donBarbos Feb 15, 2025
5d87f80
Wrap again
donBarbos Feb 15, 2025
05f5f65
Add seealso section
donBarbos Feb 15, 2025
e7a42f7
Update http.server.rst
donBarbos Feb 15, 2025
4c68c27
Merge branch 'main' into issue-85162
donBarbos Mar 16, 2025
3ca55d1
Update cli description
donBarbos Mar 16, 2025
3daf484
Update doc
donBarbos Mar 16, 2025
8b84be2
Update docs
donBarbos Apr 4, 2025
50e0ed5
Update Doc/whatsnew/3.14.rst
picnixz Apr 5, 2025
4f36fbf
Update Doc/whatsnew/3.14.rst
picnixz Apr 5, 2025
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
Update docs and correct raising errors
  • Loading branch information
donBarbos committed Feb 3, 2025
commit 4f587bdb29ecefa8b19e4ee911c8e787e76c1ed4
35 changes: 23 additions & 12 deletions 35 Doc/library/http.server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,28 @@ handler. Code to create and run the server looks like this::
.. versionadded:: 3.7


The :class:`HTTPServer` and :class:`ThreadingHTTPServer` must be given
a *RequestHandlerClass* on instantiation, of which this module
provides three different variants:

.. class:: HTTPSServer(server_address, RequestHandlerClass, \
donBarbos marked this conversation as resolved.
Show resolved Hide resolved
bind_and_activate=True, *, certfile, keyfile=None, \
donBarbos marked this conversation as resolved.
Show resolved Hide resolved
password=None, alpn_protocols=None)

This class is a :class:`HTTPServer` subclass with a wrapped socket using the
donBarbos marked this conversation as resolved.
Show resolved Hide resolved
:mod:`ssl`, if the :mod:`ssl` module is not available the class will not
initialize. The *certfile* argument is required and is the path to the SSL
initialize.

The *certfile* argument is required and is the path to the SSL
certificate chain file. The *keyfile* is the path to its private key. But
private keys are often protected and wrapped with PKCS #8, so we provide
*password* argument for that case.

.. versionadded:: 3.14
The *alpn_protocols* argument, if provided, should be a sequence of strings
specifying the Application-Layer Protocol Negotiation (ALPN) protocols
supported by the server. ALPN allows the server and client to negotiate
the application protocol during the TLS handshake. By default, it is set
to ``["http/1.1"]``, meaning the server will support HTTP/1.1. Other
possible values may include ``["h2", "http/1.1"]`` to enable HTTP/2
donBarbos marked this conversation as resolved.
Show resolved Hide resolved
support.

.. versionadded:: next

.. class:: ThreadingHTTPSServer(server_address, RequestHandlerClass, \
bind_and_activate=True, *, certfile, keyfile=None, \
Expand All @@ -77,7 +83,12 @@ provides three different variants:
analogue of :class:`ThreadingHTTPServer` class only using
:class:`HTTPSServer`.

.. versionadded:: 3.14
.. versionadded:: next


The :class:`HTTPServer`, :class:`ThreadingHTTPServer`, :class:`HTTPSServer` and
:class:`ThreadingHTTPSServer` must be given a *RequestHandlerClass* on
instantiation, of which this module provides three different variants:

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

Expand Down Expand Up @@ -488,13 +499,13 @@ following command runs an HTTP/1.1 conformant server::

The server can also support TLS encryption. The options ``--tls-cert`` and
``--tls-key`` allow specifying a TLS certificate chain and private key for
secure HTTPS connections. And ``--tls-password`` option has been added to
``http.server`` to support password-protected private keys. For example, the
following command runs the server with TLS enabled::
secure HTTPS connections. Use ``--tls-password`` option if private keys are
donBarbos marked this conversation as resolved.
Show resolved Hide resolved
passphrase-protected. For example, the following command runs the server with
TLS enabled::

python -m http.server --tls-cert cert.pem --tls-key key.pem
python -m http.server --tls-cert cert.pem --tls-key key.pem --tls-password

.. versionchanged:: 3.14
.. versionchanged:: next
Added the ``--tls-cert``, ``--tls-key`` and ``--tls-password`` options.

.. class:: CGIHTTPRequestHandler(request, client_address, server)
Expand Down
12 changes: 12 additions & 0 deletions 12 Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,18 @@ http
module allow the browser to apply its default dark mode.
(Contributed by Yorik Hansen in :gh:`123430`.)

* The :mod:`http.server` module now supports serving over HTTPS using the
new :class:`http.server.HTTPSServer`. This class is a subclass of
:class:`http.server.HTTPServer` that enables TLS encryption with the
:mod:`ssl` module. To use HTTPS from the command line, new options have been
added to ``python -m http.server``:
donBarbos marked this conversation as resolved.
Show resolved Hide resolved

* ``--tls-cert <path>``: Path to the TLS certificate file.
donBarbos marked this conversation as resolved.
Show resolved Hide resolved
* ``--tls-key <path>``: Path to the private key file.
* ``--tls-password <password>``: Optional password for the private key.

(Contributed by Semyon Moroz in :gh:`85162`.)


inspect
-------
Expand Down
6 changes: 2 additions & 4 deletions 6 Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,9 +1263,7 @@ def __init__(self, server_address, RequestHandlerClass,
bind_and_activate=True, *, certfile, keyfile=None,
password=None, alpn_protocols=None):
if ssl is None:
raise ImportError("SSL support missing")
if not certfile:
raise TypeError("__init__() missing required argument 'certfile'")
raise RuntimeError("SSL support missing")

self.certfile = certfile
self.keyfile = keyfile
Expand All @@ -1278,7 +1276,7 @@ def __init__(self, server_address, RequestHandlerClass,
def server_activate(self):
"""Wrap the socket in SSLSocket."""
if ssl is None:
raise ImportError("SSL support missing")
raise RuntimeError("SSL support missing")

super().server_activate()

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.