X-Git-Url: http://nitlanguage.org diff --git a/lib/nitcorn/file_server.nit b/lib/nitcorn/file_server.nit index 6c6d39c..5995558 100644 --- a/lib/nitcorn/file_server.nit +++ b/lib/nitcorn/file_server.nit @@ -60,10 +60,19 @@ class FileServer end # Error page template for a given `code` - fun error_page(code: Int): Streamable do return new ErrorTemplate(code) + fun error_page(code: Int): Writable do return new ErrorTemplate(code) # Header of each directory page - var header: nullable Streamable = null is writable + var header: nullable Writable = null is writable + + # Custom JavaScript code added within a ` {{{title}}} @@ -142,10 +158,10 @@ class FileServer """ response.header["Content-Type"] = media_types["html"].as(not null) - else + else if not is_dir then # It's a single file - var file = new IFStream.open(local_file) - response.body = file.read_all + response = new HttpResponse(200) + response.files.add local_file var ext = local_file.file_extension if ext != null then @@ -155,9 +171,10 @@ class FileServer else response.header["Content-Type"] = "application/octet-stream" end - file.close - end + # Cache control + response.header["cache-control"] = cache_control + else response = new HttpResponse(404) else response = new HttpResponse(404) else response = new HttpResponse(403)