Skip to content

Instantly share code, notes, and snippets.

@vschiavoni vschiavoni/webserver_splay.lua Secret
Last active Aug 29, 2015

Embed
What would you like to do?
ori_print = print
print = function(...)
return ori_print("["..os.date("%x %X.%S").."]",...)
end
function callback(clientsocket)
local first_line = clientsocket:receive() --by default *l
local headers = {}
while true do
local data = clientsocket:receive("*l")
if #data < 1 then break end
local header_separator = string.find(data, ":")
local header_k = string.sub(data, 1, header_separator-1)
local header_v = string.sub(data, header_separator+2)
headers[header_k] = header_v
end
local payload_size = tonumber(headers["content-length"] or headers["Content-Length"])
local t2=socket.gettime()
local data = clientsocket:receive(payload_size)
local rt=socket.gettime()-t2
print(payload_size,"Bytes receive (time):",rt)
clientsocket:send("HTTP/1.1 200\r\nContent-Length: 0\r\n\r\n")
end
require"splay.base"
net=require"splay.net"
events.run(function()
net.server(8080,callback)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.