webmcp

changeset 254:2169a62e12f5

Work on demo application (to fit modified WebMCP API); Bugfixes of WebMCP
author jbe
date Mon Mar 02 01:15:34 2015 +0100 (2015-03-02)
parents 8f028a0aa114
children 9e4be058959d
files demo-app/app/main/_filter/20_session.lua demo-app/app/main/_prefork/01-models.lua demo-app/config/demo.lua framework/env/request/add_header.lua framework/env/request/get_absolute_baseurl.lua framework/env/request/process.lua framework/env/request/set_absolute_baseurl.lua
line diff
     1.1 --- a/demo-app/app/main/_filter/20_session.lua	Sun Mar 01 22:56:06 2015 +0100
     1.2 +++ b/demo-app/app/main/_filter/20_session.lua	Mon Mar 02 01:15:34 2015 +0100
     1.3 @@ -1,9 +1,10 @@
     1.4 -if cgi.cookies.session then
     1.5 -  app.session = Session:by_ident(cgi.cookies.session)
     1.6 +local session_key = request.get_cookie{ name = "session" }
     1.7 +if session_key then
     1.8 +  app.session = Session:by_ident(session_key)
     1.9  end
    1.10  if not app.session then
    1.11    app.session = Session:new()
    1.12 -  cgi.add_header('Set-Cookie: session=' .. app.session.ident .. '; path=/' )
    1.13 +  request.add_header('Set-Cookie', 'session=' .. app.session.ident .. '; path=/' )
    1.14  end
    1.15  
    1.16  request.set_csrf_secret(app.session.csrf_secret)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/demo-app/app/main/_prefork/01-models.lua	Mon Mar 02 01:15:34 2015 +0100
     2.3 @@ -0,0 +1,7 @@
     2.4 +function mondelefant.class_prototype:by_id(id)
     2.5 +  return self:new_selector()
     2.6 +    :add_where{ "id = ?", id }
     2.7 +    :optional_object_mode()
     2.8 +    :exec()
     2.9 +end
    2.10 +execute.inner()
     3.1 --- a/demo-app/config/demo.lua	Sun Mar 01 22:56:06 2015 +0100
     3.2 +++ b/demo-app/config/demo.lua	Mon Mar 02 01:15:34 2015 +0100
     3.3 @@ -6,15 +6,17 @@
     3.4  -- collectgarbage("stop")
     3.5  
     3.6  -- open and set default database handle
     3.7 -db = assert(mondelefant.connect{
     3.8 +config.db = {
     3.9    engine='postgresql',
    3.10    dbname='webmcp_demo'
    3.11 -})
    3.12 -at_exit(function() 
    3.13 -  db:close()
    3.14 -end)
    3.15 -function mondelefant.class_prototype:get_db_conn() return db end
    3.16 +}
    3.17  
    3.18 +listen{
    3.19 +  { proto = "tcp4", port = 8080 },
    3.20 +  { proto = "tcp6", port = 8080 }
    3.21 +}
    3.22 +
    3.23 +--[[
    3.24  -- enable output of SQL commands in trace system
    3.25  function db:sql_tracer(command)
    3.26    return function(error_info)
    3.27 @@ -22,11 +24,12 @@
    3.28      trace.sql{ command = command, error_position = error_info.position }
    3.29    end
    3.30  end
    3.31 +--]]
    3.32  
    3.33  -- 'request.get_relative_baseurl()' should be replaced by the absolute
    3.34  -- base URL of the application, as otherwise HTTP redirects will not be
    3.35  -- standard compliant
    3.36 -request.set_absolute_baseurl(request.get_relative_baseurl())
    3.37 +--request.set_absolute_baseurl(request.get_relative_baseurl())
    3.38  
    3.39  -- uncomment the following lines, if you want to use a database driven
    3.40  -- tempstore (for flash messages):
    3.41 @@ -39,10 +42,3 @@
    3.42  -- end
    3.43  
    3.44  
    3.45 -function mondelefant.class_prototype:by_id(id)
    3.46 -  return self:new_selector()
    3.47 -    :add_where{ "id = ?", id }
    3.48 -    :optional_object_mode()
    3.49 -    :exec()
    3.50 -end
    3.51 -
     4.1 --- a/framework/env/request/add_header.lua	Sun Mar 01 22:56:06 2015 +0100
     4.2 +++ b/framework/env/request/add_header.lua	Mon Mar 02 01:15:34 2015 +0100
     4.3 @@ -1,3 +1,6 @@
     4.4  function request.add_header(key, value)
     4.5 +  if value == nil then
     4.6 +    error("Function request.add_header(...) requires two arguments")
     4.7 +  end
     4.8    request._response_headers[#request._response_headers+1] = {key, value}
     4.9  end
     5.1 --- a/framework/env/request/get_absolute_baseurl.lua	Sun Mar 01 22:56:06 2015 +0100
     5.2 +++ b/framework/env/request/get_absolute_baseurl.lua	Mon Mar 02 01:15:34 2015 +0100
     5.3 @@ -10,6 +10,6 @@
     5.4    if request._absolute_baseurl then
     5.5      return request._absolute_baseurl
     5.6    else
     5.7 -    error("Absolute base URL is unknown. It should be set in the configuration by calling request.set_absolute_baseurl(...).")
     5.8 +    return request._relative_baseurl
     5.9    end
    5.10  end
     6.1 --- a/framework/env/request/process.lua	Sun Mar 01 22:56:06 2015 +0100
     6.2 +++ b/framework/env/request/process.lua	Mon Mar 02 01:15:34 2015 +0100
     6.3 @@ -21,6 +21,7 @@
     6.4          f:close()
     6.5          slot.put_into("data", d)
     6.6          slot.set_layout(nil, "application/octet-stream")  -- TODO
     6.7 +        return
     6.8        end
     6.9  
    6.10        -- restore slots if coming from http redirect
     7.1 --- a/framework/env/request/set_absolute_baseurl.lua	Sun Mar 01 22:56:06 2015 +0100
     7.2 +++ b/framework/env/request/set_absolute_baseurl.lua	Mon Mar 02 01:15:34 2015 +0100
     7.3 @@ -3,7 +3,7 @@
     7.4    url                          -- Base URL of the application
     7.5  )
     7.6  
     7.7 -Calling this function is neccessary for every configuration, because an absolute URL is needed for HTTP redirects. If the URL of the application is volatile, and if you don't bother violating the HTTP standard, you might want to execute request.set_absolute_baseurl(request.get_relative_baseurl()) in your application configuration.
     7.8 +Calling this function is neccessary for every configuration, because an absolute URL is needed for HTTP redirects. If the URL of the application is volatile, and if you don't bother violating the HTTP standard, it is possible to skip calling this function in your configuration.
     7.9  
    7.10  --]]--
    7.11  

Impressum / About Us