commit 9dbb78b4a9b21d733e876304b3f1a7ca0ca4073e
parent 0b349c4aea03175d4c716fe39143a4cedb232386
Author: Amit Dutta <mail@amit.is-a.dev>
Date: Thu, 3 Sep 2026 17:26:36 +0530
Refactor content type handling in main.py
Diffstat:
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/app/main.py b/app/main.py
@@ -27,12 +27,22 @@ async def stream_raw(path: str):
await client.aclose()
raise HTTPException(status_code=404, detail="File not found")
- guessed_type, _ = mimetypes.guess_type(path)
+ filename = path.split("/")[-1].lower()
- if not guessed_type or guessed_type.startswith("text/"):
+ raw_no_ext_files = {"dockerfile", "makefile", "license", "readme", "cname"}
+
+ if filename in raw_no_ext_files:
content_type = "text/plain"
else:
- content_type = guessed_type
+ guessed_type, _ = mimetypes.guess_type(filename)
+
+ if guessed_type:
+ if guessed_type.startswith("text/"):
+ content_type = "text/plain"
+ else:
+ content_type = guessed_type
+ else:
+ content_type = "text/plain"
headers = {
"Access-Control-Allow-Origin": "*",