| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# Copyright 2012 - 2017, New York University and the TUF contributors |
| 4 |
# SPDX-License-Identifier: MIT OR Apache-2.0 |
| 5 |
|
| 6 |
"""Simple HTTP server for python-tuf tests""" |
| 7 |
|
| 8 |
import socketserver |
| 9 |
from http.server import SimpleHTTPRequestHandler |
| 10 |
|
| 11 |
# Allow reuse so you can re-run tests as often as you want even if the |
| 12 |
# tests reuse ports. Otherwise TCP TIME-WAIT prevents reuse for ~1 minute |
| 13 |
socketserver.TCPServer.allow_reuse_address = True |
| 14 |
|
| 15 |
httpd = socketserver.TCPServer(("localhost", 0), SimpleHTTPRequestHandler) |
| 16 |
port_message = "bind succeeded, server port is: " + str(httpd.server_address[1]) |
| 17 |
print(port_message) |
| 18 |
httpd.serve_forever() |