moonbridge
changeset 23:6889aa20b19f
Code cleanup in example_application.lua; Removed memory limit in example_application.lua
author | jbe |
---|---|
date | Thu Jan 29 23:40:38 2015 +0100 (2015-01-29) |
parents | 891ceefb0876 |
children | 159aa2706cdf |
files | example_application.lua |
line diff
1.1 --- a/example_application.lua Thu Jan 29 22:07:58 2015 +0100 1.2 +++ b/example_application.lua Thu Jan 29 23:40:38 2015 +0100 1.3 @@ -45,7 +45,7 @@ 1.4 idle_timeout = 0, -- seconds (0 for no timeout) 1.5 1.6 -- maximum memory consumption before process gets terminated 1.7 - memory_limit = 1024*1024, -- bytes 1.8 + --memory_limit = 1024*1024, -- bytes 1.9 1.10 -- preparation of process (executed after fork) 1.11 prepare = function() 1.12 @@ -59,6 +59,15 @@ 1.13 }, 1.14 function(request) 1.15 1.16 + local function file_not_found() 1.17 + request:send_status("404 Not Found") 1.18 + request:send_header("Content-Type", "text/html; chatset=UTF-8") 1.19 + request:send_data("<html>\n") 1.20 + request:send_data("<head><title>404 Not Found</title></head>\n") 1.21 + request:send_data("<body><h1>404 Not Found</h1></body>\n") 1.22 + request:send_data("</html>\n") 1.23 + end 1.24 + 1.25 if request.method == "GET" or request.method == "HEAD" then 1.26 1.27 if request.path == "" then 1.28 @@ -79,9 +88,7 @@ 1.29 end 1.30 request:send_data(document) 1.31 else 1.32 - request:send_status("404 Not Found") 1.33 - request:send_header("Content-Type", "text/html; chatset=UTF-8") 1.34 - request:send_data("<html><head><title>404 Not Found</title></head><body><h1>404 Not Found</h1></body></html>") 1.35 + file_not_found() 1.36 end 1.37 1.38 end 1.39 @@ -129,10 +136,9 @@ 1.40 request:send_data("</body>\n</html>\n") 1.41 1.42 else 1.43 - request:send_status("404 Not Found") 1.44 - request:send_data("<html><head><title>404 Not Found</title></head><body><h1>404 Not Found</h1></body></html>") 1.45 + file_not_found() 1.46 1.47 - end 1.48 + end 1.49 1.50 else 1.51 request:send_text_status_response("405 Method not allowed")