From: Alexandre Terrasa Date: Mon, 23 May 2016 19:14:17 +0000 (-0400) Subject: nitcorn/file_server: extract answer_redirection method X-Git-Url: http://nitlanguage.org nitcorn/file_server: extract answer_redirection method Signed-off-by: Alexandre Terrasa --- diff --git a/lib/nitcorn/file_server.nit b/lib/nitcorn/file_server.nit index b701aa9..0245d1f 100644 --- a/lib/nitcorn/file_server.nit +++ b/lib/nitcorn/file_server.nit @@ -90,11 +90,9 @@ class FileServer if local_file.file_stat.is_dir then # If we target a directory without an ending `/`, # redirect to the directory ending with `/`. - if not request.uri.is_empty and - request.uri.chars.last != '/' then - response = new HttpResponse(303) - response.header["Location"] = request.uri + "/" - return response + var uri = request.uri + if not uri.is_empty and uri.chars.last != '/' then + return answer_redirection(request.uri + "/") end # Show index file instead of the directory listing @@ -126,6 +124,13 @@ class FileServer return response end + # Answer a 303 redirection to `location`. + fun answer_redirection(location: String): HttpResponse do + var response = new HttpResponse(303) + response.header["Location"] = location + return response + end + # Build a reponse containing a single `local_file`. # # Returns a 404 error if local_file does not exists.