Skip to content

Commit f1f9087

Browse files
committed
use .. program:: directive for documenting http.server CLI
1 parent a3990df commit f1f9087

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

Doc/library/http.server.rst

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -420,47 +420,58 @@ such as using different index file names by overriding the class attribute
420420

421421
.. _http-server-cli:
422422

423+
Command-line interface
424+
----------------------
425+
423426
:mod:`http.server` can also be invoked directly using the :option:`-m`
424427
switch of the interpreter. Similar to
425428
the previous example, this serves files relative to the current directory::
426429

427-
python -m http.server
430+
python -m http.server [--cgi] [-b ADDRESS] [-d DIRECTORY] [-p VERSION] [port]
431+
432+
.. program:: http.server
433+
434+
.. option:: port
435+
436+
The server listens to port 8000 by default. The default can be overridden
437+
by passing the desired port number as an argument::
428438

429-
The server listens to port 8000 by default. The default can be overridden
430-
by passing the desired port number as an argument::
439+
python -m http.server 9000
431440

432-
python -m http.server 9000
441+
.. option:: -b, --bind <address>
433442

434-
By default, the server binds itself to all interfaces. The option ``-b/--bind``
435-
specifies a specific address to which it should bind. Both IPv4 and IPv6
436-
addresses are supported. For example, the following command causes the server
437-
to bind to localhost only::
443+
Specifies a specific address to which it should bind. Both IPv4 and IPv6
444+
addresses are supported. By default, the server binds itself to all
445+
interfaces. For example, the following command causes the server to bind
446+
to localhost only::
438447

439-
python -m http.server --bind 127.0.0.1
448+
python -m http.server --bind 127.0.0.1
440449

441-
.. versionchanged:: 3.4
442-
Added the ``--bind`` option.
450+
.. versionadded:: 3.4
443451

444-
.. versionchanged:: 3.8
445-
Support IPv6 in the ``--bind`` option.
452+
.. versionchanged:: 3.8
453+
Support IPv6 in the ``--bind`` option.
446454

447-
By default, the server uses the current directory. The option ``-d/--directory``
448-
specifies a directory to which it should serve the files. For example,
449-
the following command uses a specific directory::
455+
.. option:: -d, --directory <dir>
456+
457+
Specifies a directory to which it should serve the files. By default,
458+
the server uses the current directory. For example, the following command
459+
uses a specific directory::
460+
461+
python -m http.server --directory /tmp/
462+
463+
.. versionadded:: 3.7
450464

451-
python -m http.server --directory /tmp/
465+
.. option:: -p, --protocol <version>
452466

453-
.. versionchanged:: 3.7
454-
Added the ``--directory`` option.
467+
Specifies the HTTP version to which the server is conformant. By default,
468+
the server is conformant to HTTP/1.0. For example, the following command
469+
runs an HTTP/1.1 conformant server::
455470

456-
By default, the server is conformant to HTTP/1.0. The option ``-p/--protocol``
457-
specifies the HTTP version to which the server is conformant. For example, the
458-
following command runs an HTTP/1.1 conformant server::
471+
python -m http.server --protocol HTTP/1.1
459472

460-
python -m http.server --protocol HTTP/1.1
473+
.. versionadded:: 3.11
461474

462-
.. versionchanged:: 3.11
463-
Added the ``--protocol`` option.
464475

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

0 commit comments

Comments
 (0)