Skip to content

Commit 0cfecb2

Browse files
André DietrichAndré Dietrich
authored andcommitted
fix health checks
1 parent 8570ab1 commit 0cfecb2

1 file changed

Lines changed: 5 additions & 16 deletions

File tree

server.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,7 @@ def read_http_headers(self):
2626
http_get = self.rfile.readline().decode().strip()
2727

2828
if not http_get.upper().startswith('GET'):
29-
logging.info("Unsupported HTTP method")
30-
response = 'HTTP/1.1 405 Method Not Allowed\r\nConnection: close\r\nContent-Length: 0\r\n\r\n'
31-
try:
32-
with self._send_lock:
33-
self.request.sendall(response.encode())
34-
except BrokenPipeError:
35-
logging.debug("Client closed before error response could be sent.")
36-
except Exception as e:
37-
logging.debug("Failed to send error response: %s", e)
38-
finally:
39-
self.keep_alive = False
40-
return headers
29+
logging.debug("Non-GET HTTP request, treating as health check: %r", http_get)
4130

4231
# headers lesen
4332
while True:
@@ -534,8 +523,8 @@ def stop(error_message: str | None = None, images=[], videos=[], files=[]):
534523
if __name__ == "__main__":
535524
argv = sys.argv[1:]
536525

537-
PORT = int(os.environ.get('CODERUNNER_PORT') or '8000')
538-
HOST = os.environ.get('CODERUNNER_HOST') or '127.0.0.1'
526+
PORT = int(os.environ.get('CODERUNNER_PORT') or os.environ.get('PORT') or '8000')
527+
HOST = os.environ.get('CODERUNNER_HOST') or '0.0.0.0'
539528

540529
options, args = getopt.getopt(argv, "p:h", ["port=", "host=", "help"])
541530

@@ -553,10 +542,10 @@ def stop(error_message: str | None = None, images=[], videos=[], files=[]):
553542
print("Options:")
554543
print()
555544
print(" -h, --help Print out the help")
556-
print(" -p, --port Set the server port, this will overwrite the env-variable CODERUNNER_PORT")
545+
print(" -p, --port Set the server port, this will overwrite the env-variable CODERUNNER_PORT or PORT")
557546
print(" ... defaults to 8000")
558547
print(" --host Set the server host, this will overwrite the env-variable CODERUNNER_HOST")
559-
print(" ... defaults to 127.0.0.1")
548+
print(" ... defaults to 0.0.0.0")
560549
exit(0)
561550

562551
server = Server(host=HOST, port=PORT)

0 commit comments

Comments
 (0)