some fixes

This commit is contained in:
Artem Pastukhov 2015-04-02 15:37:40 +03:00
parent 5301792d16
commit a37de51189
3 changed files with 34 additions and 11 deletions

View File

@ -24,6 +24,10 @@ end
local function parseUri(uri) local function parseUri(uri)
local r = {} local r = {}
local filename
local ext
local fullExt = {}
if uri == nil then return r end if uri == nil then return r end
if uri == "/" then uri = "/index.html" end if uri == "/" then uri = "/index.html" end
questionMarkPos, b, c, d, e, f = uri:find("?") questionMarkPos, b, c, d, e, f = uri:find("?")
@ -34,7 +38,16 @@ local function parseUri(uri)
r.file = uri:sub(1, questionMarkPos - 1) r.file = uri:sub(1, questionMarkPos - 1)
r.args = parseArgs(uri:sub(questionMarkPos+1, #uri)) r.args = parseArgs(uri:sub(questionMarkPos+1, #uri))
end end
_, r.ext = r.file:match("(.+)%.(.+)") filename = r.file
while filename:match("%.") do
filename,ext = filename:match("(.+)%.(.+)")
table.insert(fullExt,1,ext)
end
r.ext = table.concat(fullExt,".")
-- _, r.ext = r.file:match("(.+)%.(.+)")
r.isScript = r.ext == "lua" or r.ext == "lc" r.isScript = r.ext == "lua" or r.ext == "lc"
r.file = uriToFilename(r.file) r.file = uriToFilename(r.file)
return r return r

View File

@ -3,16 +3,27 @@
-- Author: Marcos Kirsch -- Author: Marcos Kirsch
local function getMimeType(ext) local function getMimeType(ext)
local gzip = false
-- A few MIME types. Keep list short. If you need something that is missing, let's add it. -- A few MIME types. Keep list short. If you need something that is missing, let's add it.
local mt = {css = "text/css", gif = "image/gif", html = "text/html", ico = "image/x-icon", jpeg = "image/jpeg", jpg = "image/jpeg", js = "application/javascript", json = "application/json", png = "image/png"} local mt = {css = "text/css", gif = "image/gif", html = "text/html", ico = "image/x-icon", jpeg = "image/jpeg", jpg = "image/jpeg", js = "application/javascript", json = "application/json", png = "image/png"}
if mt[ext] then return mt[ext] else return "text/plain" end if ext:find("gz$") then
ext = ext:sub(1, -4)
gzip = true
end
if mt[ext] then contentType = mt[ext] else contentType = "text/plain" end
return {contentType = contentType, gzip = gzip }
end end
local function sendHeader(connection, code, codeString, mimeType) local function sendHeader(connection, code, codeString, mimeType)
connection:send("HTTP/1.0 " .. code .. " " .. codeString .. "\r\nServer: nodemcu-httpserver\r\nContent-Type: " .. mimeType .. "\r\nConnection: close\r\n\r\n") connection:send("HTTP/1.0 " .. code .. " " .. codeString .. "\r\nServer: nodemcu-httpserver\r\nContent-Type: " .. mimeType["contentType"] .. "\r\n")
if mimeType["gzip"] then
connection:send("Content-Encoding: gzip\r\n")
end
connection:send("Connection: close\r\n\r\n")
end end
return function (connection, args) return function (connection, args)
--print(args.ext)
sendHeader(connection, 200, "OK", getMimeType(args.ext)) sendHeader(connection, 200, "OK", getMimeType(args.ext))
--print("Begin sending:", args.file) --print("Begin sending:", args.file)
-- Send file in little chunks -- Send file in little chunks

View File

@ -5,18 +5,14 @@ print('set (mode='..wifi.getmode()..')')
print('MAC: ',wifi.sta.getmac()) print('MAC: ',wifi.sta.getmac())
print('chip: ',node.chipid()) print('chip: ',node.chipid())
print('heap: ',node.heap()) print('heap: ',node.heap())
<<<<<<< HEAD
local joincounter = 0 wifi.sta.config("BT_WiFi", "PlacNinObOj9")
cfg={} cfg={}
cfg.ssid="ESP-"..node.chipid() cfg.ssid="ESP-"..node.chipid()
cfg.pwd="ESP-"..node.chipid() cfg.pwd="ESP-"..node.chipid()
wifi.ap.config(cfg) wifi.ap.config(cfg)
cfg = nil cfg = nil
=======
wifi.sta.config("Kirsch Extreme","1151511515")
>>>>>>> parent of 4989410... Update init.lua
-- Compile server code and remove original .lua files. -- Compile server code and remove original .lua files.
-- This only happens the first time afer the .lua files are uploaded. -- This only happens the first time afer the .lua files are uploaded.
@ -29,7 +25,7 @@ local compileAndRemoveIfNeeded = function(f)
end end
end end
local serverFiles = {'httpserver.lua', 'httpserver-request.lua', 'httpserver-static.lua', 'httpserver-error.lua','http/ual.lua'} local serverFiles = {'httpserver.lua', 'httpserver-request.lua', 'httpserver-static.lua', 'httpserver-error.lua'}
for i, f in ipairs(serverFiles) do compileAndRemoveIfNeeded(f) end for i, f in ipairs(serverFiles) do compileAndRemoveIfNeeded(f) end
compileAndRemoveIfNeeded = nil compileAndRemoveIfNeeded = nil
@ -37,6 +33,9 @@ serverFiles = nil
-- Connect to the WiFi access point. Once the device is connected, -- Connect to the WiFi access point. Once the device is connected,
-- you may start the HTTP server. -- you may start the HTTP server.
local joincounter = 0
tmr.alarm(0, 3000, 1, function() tmr.alarm(0, 3000, 1, function()
if wifi.sta.getip() == nil and joincounter < 5 then if wifi.sta.getip() == nil and joincounter < 5 then