Send content length as a header for files

This commit is contained in:
Archangel
2025-09-19 15:27:31 +02:00
parent 499e725e8c
commit 1bc3ef63f4
@@ -12,7 +12,10 @@ public class HttpFileUtil(HttpServerHelper httpServerHelper)
var pathSlice = filePath.Split("/");
var mimePath = httpServerHelper.GetMimeText(pathSlice[^1].Split(".")[^1]);
var type = string.IsNullOrWhiteSpace(mimePath) ? httpServerHelper.GetMimeText("txt") : mimePath;
var fileInfo = new FileInfo(filePath);
resp.Headers.Append("Content-Type", type);
resp.Headers.Append("Content-Length", fileInfo.Length.ToString());
await resp.SendFileAsync(filePath, CancellationToken.None);
}
}