模拟容器内的服务
()
| 343 | print(f" '宿主机' 端口映射: 127.0.0.1:{external_port} → :{internal_port}") |
| 344 | |
| 345 | def internal_handler(): |
| 346 | """模拟容器内的服务""" |
| 347 | try: |
| 348 | client, _ = internal_server.accept() |
| 349 | client.recv(1024) # 读请求 |
| 350 | response = ( |
| 351 | "HTTP/1.1 200 OK\r\n" |
| 352 | "Content-Length: 24\r\n\r\n" |
| 353 | "Hello from 'container'!" |
| 354 | ) |
| 355 | client.sendall(response.encode()) |
| 356 | client.close() |
| 357 | except socket.timeout: |
| 358 | pass |
| 359 | |
| 360 | def proxy_handler(): |
| 361 | """模拟端口转发""" |
nothing calls this directly
no outgoing calls
no test coverage detected