-
-
Save vschiavoni/315af2d2ea91876506a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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