Skip to content

Commit

Permalink
Tabs -> spaces, made formatting more consistent.
Browse files Browse the repository at this point in the history
  • Loading branch information
norman authored and mascarenhas committed Sep 8, 2010
1 parent e8c58b5 commit 513b6c7
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 265 deletions.
2 changes: 1 addition & 1 deletion src/wsapi/cgi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ module(...)
-- Runs an WSAPI application for this CGI request
function run(app_run)
common.run(app_run, { input = io.stdin, output = io.stdout,
error = io.stderr, env = os.getenv })
error = io.stderr, env = os.getenv })
end
24 changes: 12 additions & 12 deletions src/wsapi/fastcgi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ function run(app_run)
local headers
local function getenv(n)
if n == "headers" then
if headers then return headers end
local env_vars = lfcgi.environ()
headers = {}
for _, s in ipairs(env_vars) do
local name, val = s:match("^([^=]+)=(.*)$")
headers[name] = val
end
return headers
if headers then return headers end
local env_vars = lfcgi.environ()
headers = {}
for _, s in ipairs(env_vars) do
local name, val = s:match("^([^=]+)=(.*)$")
headers[name] = val
end
return headers
else
return lfcgi.getenv(n) or os.getenv(n)
return lfcgi.getenv(n) or os.getenv(n)
end
end
common.run(app_run, { input = lfcgi.stdin,
common.run(app_run, { input = lfcgi.stdin,
output = lfcgi.stdout,
error = lfcgi.stderr,
error = lfcgi.stderr,
env = getenv })
end
end
end
91 changes: 48 additions & 43 deletions src/wsapi/request.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,21 @@ local function fields(input, boundary)
_, state.pos = string.find(input, boundary, 1, true)
state.pos = state.pos + 1
return function (state, _)
local headers, name, file_name, value, size
headers, state.pos = read_field_headers(input, state.pos)
if headers then
name, file_name = get_field_names(headers)
if file_name then
value, size, state.pos = read_field_contents(input,
boundary,
state.pos)
value = file_value(value, file_name, size, headers)
else
value, size, state.pos = read_field_contents(input, boundary,
state.pos)
end
end
return name, value
end, state
local headers, name, file_name, value, size
headers, state.pos = read_field_headers(input, state.pos)
if headers then
name, file_name = get_field_names(headers)
if file_name then
value, size, state.pos = read_field_contents(input, boundary,
state.pos)
value = file_value(value, file_name, size, headers)
else
value, size, state.pos = read_field_contents(input, boundary,
state.pos)
end
end
return name, value
end, state
end

local function parse_multipart_data(input, input_type, tab, overwrite)
Expand All @@ -129,7 +128,7 @@ local function parse_post_data(wsapi_env, tab, overwrite)
else
local length = tonumber(wsapi_env.CONTENT_LENGTH) or 0
tab.post_data = wsapi_env.input:read(length) or ""
end
end
return tab
end

Expand All @@ -143,8 +142,8 @@ function methods.__index(tab, name)
local route_name = name:match("link_([%w_]+)")
if route_name then
func = function (self, query, ...)
return tab:route_link(route_name, query, ...)
end
return tab:route_link(route_name, query, ...)
end
end
end
tab[name] = func
Expand Down Expand Up @@ -201,40 +200,46 @@ end

function new(wsapi_env, options)
options = options or {}
local req = { GET = {}, POST = {}, method = wsapi_env.REQUEST_METHOD,
path_info = wsapi_env.PATH_INFO, query_string = wsapi_env.QUERY_STRING,
script_name = wsapi_env.SCRIPT_NAME, env = wsapi_env, mk_app = options.mk_app,
doc_root = wsapi_env.DOCUMENT_ROOT, app_path = wsapi_env.APP_PATH }
local req = {
GET = {},
POST = {},
method = wsapi_env.REQUEST_METHOD,
path_info = wsapi_env.PATH_INFO,
query_string = wsapi_env.QUERY_STRING,
script_name = wsapi_env.SCRIPT_NAME,
env = wsapi_env,
mk_app = options.mk_app,
doc_root = wsapi_env.DOCUMENT_ROOT,
app_path = wsapi_env.APP_PATH
}
parse_qs(wsapi_env.QUERY_STRING, req.GET, options.overwrite)
if options.delay_post then
req.parse_post = function (self)
parse_post_data(wsapi_env, self.POST, options.overwrite)
self.parse_post = function () return nil, "postdata already parsed" end
return self.POST
end
parse_post_data(wsapi_env, self.POST, options.overwrite)
self.parse_post = function () return nil, "postdata already parsed" end
return self.POST
end
else
parse_post_data(wsapi_env, req.POST, options.overwrite)
req.parse_post = function () return nil, "postdata already parsed" end
end
req.params = {}
setmetatable(req.params, { __index = function (tab, name)
local var = req.GET[name] or
req.POST[name]
rawset(tab, name, var)
return var
end })
local var = req.GET[name] or req.POST[name]
rawset(tab, name, var)
return var
end})
req.cookies = {}
local cookies = string.gsub(";" .. (wsapi_env.HTTP_COOKIE or "") .. ";",
"%s*;%s*", ";")
"%s*;%s*", ";")
setmetatable(req.cookies, { __index = function (tab, name)
name = name
local pattern = ";" .. name ..
"=(.-);"
local cookie = string.match(
cookies, pattern)
cookie = util.url_decode(cookie)
rawset(tab, name, cookie)
return cookie
end } )
name = name
local pattern = ";" .. name ..
"=(.-);"
local cookie = string.match(cookies, pattern)
cookie = util.url_decode(cookie)
rawset(tab, name, cookie)
return cookie
end})
return setmetatable(req, methods)
end
end
8 changes: 4 additions & 4 deletions src/wsapi/response.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ end
function methods:finish()
self.headers["Content-Length"] = self.length
return self.status, self.headers, coroutine.wrap(function ()
for _, s in ipairs(self.body) do
coroutine.yield(s)
end
end)
for _, s in ipairs(self.body) do
coroutine.yield(s)
end
end)
end

local function optional (what, name)
Expand Down
Loading

0 comments on commit 513b6c7

Please sign in to comment.