parallelization_phase: use `ANode::validate` after AST shenanigans.
[nit.git] / lib / nitcorn / file_server.nit
index 6c6d39c..d46d2a4 100644 (file)
@@ -60,10 +60,10 @@ 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
 
        redef fun answer(request, turi)
        do
@@ -106,14 +106,15 @@ class FileServer
                                        var files = local_file.files
 
                                        var links = new Array[String]
-                                       if local_file.length > 1 then
-                                               # The extra / is a hack
-                                               var path = "/" + (turi + "/..").simplify_path
-                                               links.add "<a href=\"{path}\">..</a>"
+                                       if turi.length > 1 then
+                                               var path = (request.uri + "/..").simplify_path
+                                               links.add "<a href=\"{path}/\">..</a>"
                                        end
                                        for file in files do
-                                               var path = (turi + "/" + file).simplify_path
-                                               links.add "<a href=\"{path}\">{file}</a>"
+                                               var local_path = local_file.join_path(file).simplify_path
+                                               var web_path = file.simplify_path
+                                               if local_path.file_stat.is_dir then web_path = web_path + "/"
+                                               links.add "<a href=\"{web_path}\">{file}</a>"
                                        end
 
                                        var header = self.header
@@ -144,7 +145,7 @@ class FileServer
                                        response.header["Content-Type"] = media_types["html"].as(not null)
                                else
                                        # It's a single file
-                                       var file = new IFStream.open(local_file)
+                                       var file = new FileReader.open(local_file)
                                        response.body = file.read_all
 
                                        var ext = local_file.file_extension