summaryrefslogtreecommitdiffhomepage
path: root/default.lua
blob: ab15a95a73900cc9a495afa3e25b57ee45133bcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
--- Default client request handler.
-- TODO: Add documentation once request and response API are more stable.
return function (stream)
	local method, path, version, h = stream:read " ", stream:read " ", stream:read "\r\n", stream:read "\r\n\r\n"
	local headers = {}
	for header, value in h:gmatch "([^%s:]+)%s*:%s+([^\r\n]*)" do
		headers[header:lower()] = value
	end

	local response_data = [["Hello from plop/lua!"]]
	local headers = {Connection="close", ["Content-Length"]=#response_data, ["Content-Type"]="application/json"}

	return {status=200, headers=headers, data=response_data}
end