# HG changeset patch # User jbe # Date 1425255334 -3600 # Node ID 2169a62e12f5a1b7d5b58ccb0f9bddab020b6291 # Parent 8f028a0aa114a0de376617be2a216bcb94d1aaf9 Work on demo application (to fit modified WebMCP API); Bugfixes of WebMCP diff -r 8f028a0aa114 -r 2169a62e12f5 demo-app/app/main/_filter/20_session.lua --- a/demo-app/app/main/_filter/20_session.lua Sun Mar 01 22:56:06 2015 +0100 +++ b/demo-app/app/main/_filter/20_session.lua Mon Mar 02 01:15:34 2015 +0100 @@ -1,9 +1,10 @@ -if cgi.cookies.session then - app.session = Session:by_ident(cgi.cookies.session) +local session_key = request.get_cookie{ name = "session" } +if session_key then + app.session = Session:by_ident(session_key) end if not app.session then app.session = Session:new() - cgi.add_header('Set-Cookie: session=' .. app.session.ident .. '; path=/' ) + request.add_header('Set-Cookie', 'session=' .. app.session.ident .. '; path=/' ) end request.set_csrf_secret(app.session.csrf_secret) diff -r 8f028a0aa114 -r 2169a62e12f5 demo-app/app/main/_prefork/01-models.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo-app/app/main/_prefork/01-models.lua Mon Mar 02 01:15:34 2015 +0100 @@ -0,0 +1,7 @@ +function mondelefant.class_prototype:by_id(id) + return self:new_selector() + :add_where{ "id = ?", id } + :optional_object_mode() + :exec() +end +execute.inner() diff -r 8f028a0aa114 -r 2169a62e12f5 demo-app/config/demo.lua --- a/demo-app/config/demo.lua Sun Mar 01 22:56:06 2015 +0100 +++ b/demo-app/config/demo.lua Mon Mar 02 01:15:34 2015 +0100 @@ -6,15 +6,17 @@ -- collectgarbage("stop") -- open and set default database handle -db = assert(mondelefant.connect{ +config.db = { engine='postgresql', dbname='webmcp_demo' -}) -at_exit(function() - db:close() -end) -function mondelefant.class_prototype:get_db_conn() return db end +} +listen{ + { proto = "tcp4", port = 8080 }, + { proto = "tcp6", port = 8080 } +} + +--[[ -- enable output of SQL commands in trace system function db:sql_tracer(command) return function(error_info) @@ -22,11 +24,12 @@ trace.sql{ command = command, error_position = error_info.position } end end +--]] -- 'request.get_relative_baseurl()' should be replaced by the absolute -- base URL of the application, as otherwise HTTP redirects will not be -- standard compliant -request.set_absolute_baseurl(request.get_relative_baseurl()) +--request.set_absolute_baseurl(request.get_relative_baseurl()) -- uncomment the following lines, if you want to use a database driven -- tempstore (for flash messages): @@ -39,10 +42,3 @@ -- end -function mondelefant.class_prototype:by_id(id) - return self:new_selector() - :add_where{ "id = ?", id } - :optional_object_mode() - :exec() -end - diff -r 8f028a0aa114 -r 2169a62e12f5 framework/env/request/add_header.lua --- a/framework/env/request/add_header.lua Sun Mar 01 22:56:06 2015 +0100 +++ b/framework/env/request/add_header.lua Mon Mar 02 01:15:34 2015 +0100 @@ -1,3 +1,6 @@ function request.add_header(key, value) + if value == nil then + error("Function request.add_header(...) requires two arguments") + end request._response_headers[#request._response_headers+1] = {key, value} end diff -r 8f028a0aa114 -r 2169a62e12f5 framework/env/request/get_absolute_baseurl.lua --- a/framework/env/request/get_absolute_baseurl.lua Sun Mar 01 22:56:06 2015 +0100 +++ b/framework/env/request/get_absolute_baseurl.lua Mon Mar 02 01:15:34 2015 +0100 @@ -10,6 +10,6 @@ if request._absolute_baseurl then return request._absolute_baseurl else - error("Absolute base URL is unknown. It should be set in the configuration by calling request.set_absolute_baseurl(...).") + return request._relative_baseurl end end diff -r 8f028a0aa114 -r 2169a62e12f5 framework/env/request/process.lua --- a/framework/env/request/process.lua Sun Mar 01 22:56:06 2015 +0100 +++ b/framework/env/request/process.lua Mon Mar 02 01:15:34 2015 +0100 @@ -21,6 +21,7 @@ f:close() slot.put_into("data", d) slot.set_layout(nil, "application/octet-stream") -- TODO + return end -- restore slots if coming from http redirect diff -r 8f028a0aa114 -r 2169a62e12f5 framework/env/request/set_absolute_baseurl.lua --- a/framework/env/request/set_absolute_baseurl.lua Sun Mar 01 22:56:06 2015 +0100 +++ b/framework/env/request/set_absolute_baseurl.lua Mon Mar 02 01:15:34 2015 +0100 @@ -3,7 +3,7 @@ url -- Base URL of the application ) -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. +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. --]]--