mimetypes #1

Merged
yagich merged 4 commits from mimetypes into main 2022-06-25 14:45:51 +00:00
Showing only changes of commit e337f78740 - Show all commits

View File

@ -67,18 +67,13 @@ func _serve_file(_request: HTTPServer.Request, response: HTTPServer.Response, bi
var mime := mime_types.get(file_name) var mime := mime_types.get(file_name)
response.header("content-type", mime.full_type) response.header("content-type", mime.full_type)
# variant # variant
# warning-ignore:incompatible_ternary # warning-ignore:incompatible_ternary
var data = f.get_as_text() if mime.type == 'text' else f.get_buffer(f.get_len()) var data = f.get_as_text() if mime.type == 'text' else f.get_buffer(f.get_len())
response.data(data) response.data(data)
else: else:
response.header("content-type", "text/plain") response.header("content-type", "text/plain")
response.data("500 - Read Error") response.data("500 - Read Error")
func get_mime_type(file_name: String) -> String:
var ext := file_name.get_extension().to_lower()
return mime_types[ext] if ext in mime_types else "application/octet-stream"