Minor cleanup
This commit is contained in:
parent
5d4887927d
commit
51bfb3a8cc
@ -30,7 +30,6 @@ function parseRequest(request)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function uriToFilename(uri)
|
local function uriToFilename(uri)
|
||||||
if uri == "/" then return "http/index.html" end
|
|
||||||
return "http/" .. string.sub(uri, 2, -1)
|
return "http/" .. string.sub(uri, 2, -1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -43,7 +42,6 @@ end
|
|||||||
|
|
||||||
local function parseUri(uri)
|
local function parseUri(uri)
|
||||||
if uri == "/" then uri = "/index.html" end
|
if uri == "/" then uri = "/index.html" end
|
||||||
print ("uri is " .. uri)
|
|
||||||
questionMarkPos, b, c, d, e, f = uri:find("?")
|
questionMarkPos, b, c, d, e, f = uri:find("?")
|
||||||
r = {}
|
r = {}
|
||||||
if questionMarkPos == nil then
|
if questionMarkPos == nil then
|
||||||
@ -76,12 +74,11 @@ local function getMimeType(ext)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function onGet(connection, uri)
|
local function onGet(connection, uri)
|
||||||
print("onGet: requested uri is: " .. uri)
|
uri = parseUri(uri)
|
||||||
local fileExists = file.open(uriToFilename(uri), "r")
|
local fileExists = file.open(uriToFilename(uri.file), "r")
|
||||||
if not fileExists then
|
if not fileExists then
|
||||||
onError(connection, 404, "Not Found")
|
onError(connection, 404, "Not Found")
|
||||||
else
|
else
|
||||||
uri = parseUri(uri)
|
|
||||||
-- Use HTTP/1.0 to ensure client closes connection.
|
-- Use HTTP/1.0 to ensure client closes connection.
|
||||||
connection:send("HTTP/1.0 200 OK\r\nContent-Type: " .. getMimeType(uri.ext) .. "\r\Cache-Control: private, no-store\r\n\r\n")
|
connection:send("HTTP/1.0 200 OK\r\nContent-Type: " .. getMimeType(uri.ext) .. "\r\Cache-Control: private, no-store\r\n\r\n")
|
||||||
-- Send file in little 128-byte chunks
|
-- Send file in little 128-byte chunks
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user