Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f26f87ef
Commit
f26f87ef
authored
Oct 13, 2010
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Run a simple HTTPS server when Lib/test/ssl_servers.py is run as __main__
parent
a0006457
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
1 deletion
+59
-1
Lib/test/ssl_servers.py
Lib/test/ssl_servers.py
+59
-1
No files found.
Lib/test/ssl_servers.py
View file @
f26f87ef
import
os
import
sys
import
ssl
import
pprint
import
threading
import
urllib.parse
# Rename HTTPServer to _HTTPServer so as to avoid confusion with HTTPSServer.
from
http.server
import
HTTPServer
as
_HTTPServer
,
SimpleHTTPRequestHandler
from
http.server
import
(
HTTPServer
as
_HTTPServer
,
SimpleHTTPRequestHandler
,
BaseHTTPRequestHandler
)
from
test
import
support
...
...
@@ -73,6 +75,36 @@ class RootedHTTPRequestHandler(SimpleHTTPRequestHandler):
self
.
log_date_time_string
(),
format
%
args
))
class
StatsRequestHandler
(
BaseHTTPRequestHandler
):
"""Example HTTP request handler which returns SSL statistics on GET
requests.
"""
server_version
=
"StatsHTTPS/1.0"
def
do_GET
(
self
,
send_body
=
True
):
"""Serve a GET request."""
sock
=
self
.
rfile
.
raw
.
_sock
context
=
sock
.
context
body
=
pprint
.
pformat
(
context
.
session_stats
())
body
=
body
.
encode
(
'utf-8'
)
self
.
send_response
(
200
)
self
.
send_header
(
"Content-type"
,
"text/plain; charset=utf-8"
)
self
.
send_header
(
"Content-Length"
,
str
(
len
(
body
)))
self
.
end_headers
()
if
send_body
:
self
.
wfile
.
write
(
body
)
def
do_HEAD
(
self
):
"""Serve a HEAD request."""
self
.
do_GET
(
send_body
=
False
)
def
log_request
(
self
,
format
,
*
args
):
if
support
.
verbose
:
BaseHTTPRequestHandler
.
log_request
(
self
,
format
,
*
args
)
class
HTTPSServerThread
(
threading
.
Thread
):
def
__init__
(
self
,
context
,
host
=
HOST
,
handler_class
=
None
):
...
...
@@ -117,3 +149,29 @@ def make_https_server(case, certfile=CERTFILE, host=HOST, handler_class=None):
server
.
join
()
case
.
addCleanup
(
cleanup
)
return
server
if
__name__
==
"__main__"
:
import
argparse
parser
=
argparse
.
ArgumentParser
(
description
=
'Run a test HTTPS server. '
'By default, the current directory is served.'
)
parser
.
add_argument
(
'-p'
,
'--port'
,
type
=
int
,
default
=
4433
,
help
=
'port to listen on (default: %(default)s)'
)
parser
.
add_argument
(
'-q'
,
'--quiet'
,
dest
=
'verbose'
,
default
=
True
,
action
=
'store_false'
,
help
=
'be less verbose'
)
parser
.
add_argument
(
'-s'
,
'--stats'
,
dest
=
'use_stats_handler'
,
default
=
False
,
action
=
'store_true'
,
help
=
'always return stats page'
)
args
=
parser
.
parse_args
()
support
.
verbose
=
args
.
verbose
if
args
.
use_stats_handler
:
handler_class
=
StatsRequestHandler
else
:
handler_class
=
RootedHTTPRequestHandler
handler_class
.
root
=
os
.
getcwd
()
context
=
ssl
.
SSLContext
(
ssl
.
PROTOCOL_TLSv1
)
context
.
load_cert_chain
(
CERTFILE
)
server
=
HTTPSServer
((
""
,
args
.
port
),
handler_class
,
context
)
server
.
serve_forever
(
0.1
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment