Some checks failed
Tests / check (push) Failing after 39s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
25 lines
748 B
Python
25 lines
748 B
Python
import os
|
|
import sys
|
|
|
|
|
|
def main():
|
|
root = os.path.realpath(sys.argv[1])
|
|
request = sys.stdin.buffer.readline().decode("latin-1").split()
|
|
while sys.stdin.buffer.readline() not in (b"\r\n", b"\n", b""):
|
|
pass
|
|
name = request[1].lstrip("/") if len(request) > 1 else ""
|
|
path = os.path.realpath(os.path.join(root, name))
|
|
out = sys.stdout.buffer
|
|
if name and os.path.dirname(path) == root and os.path.isfile(path):
|
|
with open(path, "rb") as f:
|
|
body = f.read()
|
|
out.write(b"HTTP/1.0 200 OK\r\n")
|
|
else:
|
|
body = b""
|
|
out.write(b"HTTP/1.0 404 Not Found\r\n")
|
|
out.write(b"Content-Length: %d\r\nConnection: close\r\n\r\n" % len(body))
|
|
out.write(body)
|
|
out.flush()
|
|
|
|
|
|
main()
|