summaryrefslogtreecommitdiff
path: root/scripts/context/lua/mtx-server.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2012-05-14 10:40:15 +0300
committerMarius <mariausol@gmail.com>2012-05-14 10:40:15 +0300
commit86301645de1fc594ca94a2a722fce813c16966b1 (patch)
treec8723188d4d356086f97a40e36499ce883711b37 /scripts/context/lua/mtx-server.lua
parent8d448442950011295b60f1ea7385887e043388e9 (diff)
downloadcontext-86301645de1fc594ca94a2a722fce813c16966b1.tar.gz
beta 2012.05.14 09:19
Diffstat (limited to 'scripts/context/lua/mtx-server.lua')
-rw-r--r--scripts/context/lua/mtx-server.lua60
1 files changed, 33 insertions, 27 deletions
diff --git a/scripts/context/lua/mtx-server.lua b/scripts/context/lua/mtx-server.lua
index 4547877b5..068d51111 100644
--- a/scripts/context/lua/mtx-server.lua
+++ b/scripts/context/lua/mtx-server.lua
@@ -29,7 +29,8 @@ scripts.webserver = scripts.webserver or { }
dofile(resolvers.findfile("l-url.lua","tex"))
dofile(resolvers.findfile("luat-soc.lua","tex"))
-local socket = socket or require("socket") -- redundant in future version
+local socket = socket or require("socket")
+local http = socket or require("socket.http")
local format = string.format
-- The following two lists are taken from webrick (ruby) and
@@ -300,45 +301,50 @@ function scripts.webserver.run(configuration)
report("scripts subpath: %s",configuration.scripts)
report("context services: http://localhost:%s/mtx-server-ctx-startup.lua",configuration.port)
local server = assert(socket.bind("*", configuration.port))
---~ local reading = { server }
+-- local reading = { server }
while true do -- no multiple clients
local start = os.clock()
---~ local input = socket.select(reading)
---~ local client = input:accept()
+-- local input = socket.select(reading)
+-- local client = input:accept()
local client = server:accept()
client:settimeout(configuration.timeout or 60)
local request, e = client:receive()
+-- local request, e = client:receive("*a") -- doesn't work well (so no post)
if e then
errormessage(client,configuration,404)
else
local from = client:getpeername()
report("request from: %s",tostring(from))
- local fullurl = request:match("GET (.+) HTTP/.*$") -- todo: more clever
- fullurl = socket.url.unescape(fullurl)
- local hashed = url.hashed(fullurl)
- local query = url.query(hashed.query)
- local filename = hashed.path
---~ table.print(hashed)
- if filename then
- filename = socket.url.unescape(filename)
- report("requested action: %s",filename)
- if filename:find("%.%.") then
- filename = nil -- invalid path
- end
- if filename == nil or filename == "" or filename == "/" then
- filename = configuration.index
- report("invalid filename, forcing: %s",filename)
- end
- local suffix = file.extname(filename)
- local action = handlers[suffix] or handlers.generic
- if action then
- report("performing action: %s",filename)
- action(client,configuration,filename,suffix,false,hashed) -- filename and no content
+ local fullurl = request:match("GET (.+) HTTP/.*$") or "" -- todo: more clever / post
+ if fullurl == "" then
+ errormessage(client,configuration,404)
+ else
+ fullurl = socket.url.unescape(fullurl)
+ local hashed = url.hashed(fullurl)
+ local query = url.query(hashed.query)
+ local filename = hashed.path
+-- table.print(hashed)
+ if filename then
+ filename = socket.url.unescape(filename)
+ report("requested action: %s",filename)
+ if filename:find("%.%.") then
+ filename = nil -- invalid path
+ end
+ if filename == nil or filename == "" or filename == "/" then
+ filename = configuration.index
+ report("invalid filename, forcing: %s",filename)
+ end
+ local suffix = file.extname(filename)
+ local action = handlers[suffix] or handlers.generic
+ if action then
+ report("performing action: %s",filename)
+ action(client,configuration,filename,suffix,false,hashed) -- filename and no content
+ else
+ errormessage(client,configuration,404)
+ end
else
errormessage(client,configuration,404)
end
- else
- errormessage(client,configuration,404)
end
end
client:close()