@@ -418,49 +418,6 @@ the current directory::
418
418
such as using different index file names by overriding the class attribute
419
419
:attr: `index_pages `.
420
420
421
- .. _http-server-cli :
422
-
423
- :mod: `http.server ` can also be invoked directly using the :option: `-m `
424
- switch of the interpreter. Similar to
425
- the previous example, this serves files relative to the current directory::
426
-
427
- python -m http.server
428
-
429
- The server listens to port 8000 by default. The default can be overridden
430
- by passing the desired port number as an argument::
431
-
432
- python -m http.server 9000
433
-
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::
438
-
439
- python -m http.server --bind 127.0.0.1
440
-
441
- .. versionchanged :: 3.4
442
- Added the ``--bind `` option.
443
-
444
- .. versionchanged :: 3.8
445
- Support IPv6 in the ``--bind `` option.
446
-
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::
450
-
451
- python -m http.server --directory /tmp/
452
-
453
- .. versionchanged :: 3.7
454
- Added the ``--directory `` option.
455
-
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::
459
-
460
- python -m http.server --protocol HTTP/1.1
461
-
462
- .. versionchanged :: 3.11
463
- Added the ``--protocol `` option.
464
421
465
422
.. class :: CGIHTTPRequestHandler(request, client_address, server)
466
423
@@ -510,25 +467,85 @@ following command runs an HTTP/1.1 conformant server::
510
467
Retaining it could lead to further :ref: `security considerations
511
468
<http.server-security>`.
512
469
513
- :class: `CGIHTTPRequestHandler ` can be enabled in the command line by passing
514
- the ``--cgi `` option::
515
470
516
- python -m http.server --cgi
471
+ .. _http-server-cli :
472
+
473
+ Command-line interface
474
+ ----------------------
475
+
476
+ :mod: `http.server ` can also be invoked directly using the :option: `-m `
477
+ switch of the interpreter. The following example illustrates how to serve
478
+ files relative to the current directory::
479
+
480
+ python -m http.server [OPTIONS] [port]
481
+
482
+ The following options are accepted:
483
+
484
+ .. program :: http.server
517
485
518
- .. deprecated-removed :: 3.13 3.15
486
+ .. option :: port
519
487
520
- :mod: `http.server ` command line ``--cgi `` support is being removed
521
- because :class: `CGIHTTPRequestHandler ` is being removed.
488
+ The server listens to port 8000 by default. The default can be overridden
489
+ by passing the desired port number as an argument::
490
+
491
+ python -m http.server 9000
492
+
493
+ .. option :: -b , --bind <address >
494
+
495
+ Specifies a specific address to which it should bind. Both IPv4 and IPv6
496
+ addresses are supported. By default, the server binds itself to all
497
+ interfaces. For example, the following command causes the server to bind
498
+ to localhost only::
499
+
500
+ python -m http.server --bind 127.0.0.1
501
+
502
+ .. versionadded :: 3.4
503
+
504
+ .. versionchanged :: 3.8
505
+ Support IPv6 in the ``--bind `` option.
506
+
507
+ .. option :: -d , --directory <dir >
508
+
509
+ Specifies a directory to which it should serve the files. By default,
510
+ the server uses the current directory. For example, the following command
511
+ uses a specific directory::
512
+
513
+ python -m http.server --directory /tmp/
514
+
515
+ .. versionadded :: 3.7
516
+
517
+ .. option :: -p , --protocol <version >
518
+
519
+ Specifies the HTTP version to which the server is conformant. By default,
520
+ the server is conformant to HTTP/1.0. For example, the following command
521
+ runs an HTTP/1.1 conformant server::
522
+
523
+ python -m http.server --protocol HTTP/1.1
524
+
525
+ .. versionadded :: 3.11
526
+
527
+ .. option :: --cgi
528
+
529
+ :class: `CGIHTTPRequestHandler ` can be enabled in the command line by passing
530
+ the ``--cgi `` option::
531
+
532
+ python -m http.server --cgi
533
+
534
+ .. deprecated-removed :: 3.13 3.15
535
+
536
+ :mod: `http.server ` command line ``--cgi `` support is being removed
537
+ because :class: `CGIHTTPRequestHandler ` is being removed.
522
538
523
539
.. warning ::
524
540
525
- :class: `CGIHTTPRequestHandler ` and the ``--cgi `` command line option
541
+ :class: `CGIHTTPRequestHandler ` and the ``--cgi `` command- line option
526
542
are not intended for use by untrusted clients and may be vulnerable
527
543
to exploitation. Always use within a secure environment.
528
544
545
+
529
546
.. _http.server-security :
530
547
531
- Security Considerations
548
+ Security considerations
532
549
-----------------------
533
550
534
551
.. index :: pair: http.server; security
0 commit comments