moonbridge

diff example_application.lua @ 33:59f485dc48ea

Removed method request:send_text_status_response(...); Added helloworld.lua
author jbe
date Tue Feb 17 13:15:08 2015 +0100 (2015-02-17)
parents 19a6d18bf34e
children e3df61bf62f4
line diff
     1.1 --- a/example_application.lua	Tue Feb 17 04:10:38 2015 +0100
     1.2 +++ b/example_application.lua	Tue Feb 17 13:15:08 2015 +0100
     1.3 @@ -1,5 +1,7 @@
     1.4  -- Moonbridge example application
     1.5  -- invoke with ./moonbridge example_application.lua
     1.6 +--
     1.7 +-- see helloworld.lua for a simpler example
     1.8  
     1.9  local http = require "moonbridge_http"
    1.10  
    1.11 @@ -61,13 +63,11 @@
    1.12      },
    1.13      function(request)
    1.14  
    1.15 -      local function file_not_found()
    1.16 -        request:send_status("404 Not Found")
    1.17 -        request:send_header("Content-Type", "text/html; chatset=UTF-8")
    1.18 -        request:send_data("<html>\n")
    1.19 -        request:send_data("<head><title>404 Not Found</title></head>\n")
    1.20 -        request:send_data("<body><h1>404 Not Found</h1></body>\n")
    1.21 -        request:send_data("</html>\n")
    1.22 +      local function error_response(status)
    1.23 +        request:send_status(status)
    1.24 +        request:send_header("Content-Type", "text/html")
    1.25 +        request:send_data("<html>\n<head><title>", status, "</title></head>\n<body><h1>", status, "</h1></body>\n</html>\n")
    1.26 +        request:finish()
    1.27        end
    1.28  
    1.29        if request.method == "GET" or request.method == "HEAD" then
    1.30 @@ -89,7 +89,7 @@
    1.31              end
    1.32              request:send_data(document)
    1.33            else
    1.34 -            file_not_found()
    1.35 +            error_response("404 Not Found")
    1.36            end
    1.37  
    1.38          end
    1.39 @@ -137,12 +137,12 @@
    1.40            request:send_data("</body>\n</html>\n")
    1.41  
    1.42          else
    1.43 -          file_not_found()
    1.44 +          error_response("404 Not Found")
    1.45  
    1.46          end
    1.47          
    1.48        else
    1.49 -        request:send_text_status_response("405 Method not allowed")
    1.50 +        error_response("405 Method not allowed")
    1.51  
    1.52        end
    1.53  

Impressum / About Us