two-images/metadata.py
GnomeZworc fe401b9a12
Some checks failed
Tests / check (push) Failing after 39s
two-images: construction reproductible de rocky10 et debian13 par Packer, test de démarrage syonad/two#53
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-10-24 13:53:56 +02:00

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()