serve
¶
Serve the local ShadowSim builder page.
HTTPServer
¶
Bases: ThreadingMixIn, HTTPServer
Serve each request on a daemon thread so one run does not block the page.
request_timeout is how long, in seconds, a client may take to send the
request line, the headers, and an authenticated body. At most
_MAX_HANDLERS connections are handled at once. A further connection is
closed so the accept loop can keep serving the page.
Source code in shadowsim/cli/serve.py
__init__
¶
__init__(
server_address: tuple[str, int],
request_handler_class: type[BaseHTTPRequestHandler],
bind_and_activate: bool = True,
*,
request_timeout: float = _REQUEST_TIMEOUT,
max_handlers: int = _MAX_HANDLERS,
) -> None
Bind the server.
Parameters:
-
server_address(tuple[str, int]) –Address and port to bind.
-
request_handler_class(type[BaseHTTPRequestHandler]) –Handler for each accepted connection.
-
bind_and_activate(bool, default:True) –Bind and listen during construction.
-
request_timeout(float, default:_REQUEST_TIMEOUT) –Seconds allowed for the request line, the headers, and an authenticated body.
-
max_handlers(int, default:_MAX_HANDLERS) –How many connections may be handled at once. A further connection is closed.
Source code in shadowsim/cli/serve.py
process_request
¶
Handle one connection on a daemon thread.
When every handler thread is busy, the connection is closed and the accept loop continues.
Parameters:
-
request(Any) –Accepted client socket.
-
client_address(Any) –Address of the client.
Source code in shadowsim/cli/serve.py
process_request_thread
¶
Handle one request, then free its handler slot.
Parameters:
-
request(Any) –Accepted client socket.
-
client_address(Any) –Address of the client.
Source code in shadowsim/cli/serve.py
add_serve_parser
¶
Register the serve subcommand on subparsers.
Source code in shadowsim/cli/serve.py
run_serve
¶
Run serve from a parsed serve subcommand namespace.
Source code in shadowsim/cli/serve.py
serve
¶
serve(
host: str,
port: int,
*,
open_browser: bool,
allow_remote: bool = False,
output_dir: str | Path = "results",
tls_cert: str | Path | None = None,
tls_key: str | Path | None = None,
) -> int
Bind a server and serve the builder page until interrupted.
A loopback bind speaks HTTP and prints a one-time ?token= URL. A
non-loopback bind requires allow_remote and both TLS files, speaks HTTPS,
and prints the startup token on its own line instead of in the URL. Passing
both TLS files on a loopback bind serves HTTPS there too.
Parameters:
-
host(str) –Address to bind.
-
port(int) –TCP port to bind.
-
open_browser(bool) –Open the page in the default browser after the server starts.
-
allow_remote(bool, default:False) –Permit a non-loopback
host. Without this, such an address is refused. Anyone who has the startup token can submit a run. -
output_dir(str | Path, default:'results') –Directory save and export paths must stay under. A relative path is resolved from the working directory when the server starts.
-
tls_cert(str | Path | None, default:None) –PEM certificate file used when the server speaks HTTPS. Required with
tls_keyfor a non-loopbackhost. -
tls_key(str | Path | None, default:None) –PEM private key file paired with
tls_cert.
Returns:
-
int–Process exit code.
0after a clean interrupt,1if the port is invalid, -
int–the address is not loopback and
allow_remoteis false, a non-loopback -
int–address has no TLS files, only one TLS file is set, the certificate cannot
-
int–be loaded, or the address cannot be bound.
Source code in shadowsim/cli/serve.py
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 | |