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

Commit 2d30ade

Browse filesBrowse files
geryogammerwokJelleZijlstra
authored
bpo-46285: Add command-line option -p/--protocol to module http.server (#30999)
Co-authored-by: Éric <merwok@netwok.org> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent 32e4f45 commit 2d30ade
Copy full SHA for 2d30ade

File tree

Expand file treeCollapse file tree

3 files changed

+29
-9
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+29
-9
lines changed

‎Doc/library/http.server.rst

Copy file name to clipboardExpand all lines: Doc/library/http.server.rst
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ provides three different variants:
157157

158158
.. attribute:: protocol_version
159159

160-
This specifies the HTTP protocol version used in responses. If set to
160+
Specifies the HTTP version to which the server is conformant. It is sent
161+
in responses to let the client know the server's communication
162+
capabilities for future requests. If set to
161163
``'HTTP/1.1'``, the server will permit HTTP persistent connections;
162164
however, your server *must* then include an accurate ``Content-Length``
163165
header (using :meth:`send_header`) in all of its responses to clients.
@@ -193,7 +195,7 @@ provides three different variants:
193195

194196
.. method:: handle_expect_100()
195197

196-
When a HTTP/1.1 compliant server receives an ``Expect: 100-continue``
198+
When an HTTP/1.1 conformant server receives an ``Expect: 100-continue``
197199
request header it responds back with a ``100 Continue`` followed by ``200
198200
OK`` headers.
199201
This method can be overridden to raise an error if the server does not
@@ -444,6 +446,15 @@ the following command uses a specific directory::
444446
.. versionadded:: 3.7
445447
``--directory`` argument was introduced.
446448

449+
By default, the server is conformant to HTTP/1.0. The option ``-p/--protocol``
450+
specifies the HTTP version to which the server is conformant. For example, the
451+
following command runs an HTTP/1.1 conformant server::
452+
453+
python -m http.server --protocol HTTP/1.1
454+
455+
.. versionadded:: 3.11
456+
``--protocol`` argument was introduced.
457+
447458
.. class:: CGIHTTPRequestHandler(request, client_address, server)
448459

449460
This class is used to serve either files or output of CGI scripts from the

‎Lib/http/server.py

Copy file name to clipboardExpand all lines: Lib/http/server.py
+12-7Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,15 +1256,19 @@ def test(HandlerClass=BaseHTTPRequestHandler,
12561256
parser = argparse.ArgumentParser()
12571257
parser.add_argument('--cgi', action='store_true',
12581258
help='run as CGI server')
1259-
parser.add_argument('--bind', '-b', metavar='ADDRESS',
1260-
help='specify alternate bind address '
1259+
parser.add_argument('-b', '--bind', metavar='ADDRESS',
1260+
help='bind to this address '
12611261
'(default: all interfaces)')
1262-
parser.add_argument('--directory', '-d', default=os.getcwd(),
1263-
help='specify alternate directory '
1262+
parser.add_argument('-d', '--directory', default=os.getcwd(),
1263+
help='serve this directory '
12641264
'(default: current directory)')
1265-
parser.add_argument('port', action='store', default=8000, type=int,
1266-
nargs='?',
1267-
help='specify alternate port (default: 8000)')
1265+
parser.add_argument('-p', '--protocol', metavar='VERSION',
1266+
default='HTTP/1.0',
1267+
help='conform to this HTTP version '
1268+
'(default: %(default)s)')
1269+
parser.add_argument('port', default=8000, type=int, nargs='?',
1270+
help='bind to this port '
1271+
'(default: %(default)s)')
12681272
args = parser.parse_args()
12691273
if args.cgi:
12701274
handler_class = CGIHTTPRequestHandler
@@ -1290,4 +1294,5 @@ def finish_request(self, request, client_address):
12901294
ServerClass=DualStackServer,
12911295
port=args.port,
12921296
bind=args.bind,
1297+
protocol=args.protocol,
12931298
)
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Add command-line option ``-p``/``--protocol`` to module :mod:`http.server`
2+
which specifies the HTTP version to which the server is conformant (HTTP/1.1
3+
conformant servers can now be run from the command-line interface of module
4+
:mod:`http.server`). Patch by Géry Ogam.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.