Skip to content

Instantly share code, notes, and snippets.

@aarmot
Created August 12, 2013 14:53
Show Gist options
  • Save aarmot/6211516 to your computer and use it in GitHub Desktop.
Save aarmot/6211516 to your computer and use it in GitHub Desktop.
Primitive daemon, which listens on port 80 and replies with http redirect Requires luasocket and luadaemon
-- HTTP redirect daemon
local port = 80
local redir = "HTTP/1.0 301 Moved Permanently\nLocation: https://example.org/\n\n"
local socket = require("socket")
local daemon = require("daemon")
daemon.daemonize()
local server = assert(socket.bind("*", port))
while true do
local client = server:accept()
client:settimeout(10)
local line, err
repeat
line, err = client:receive()
if not err and line:len() == 0 then
client:send(redir)
line = false
end
until not line
client:close()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment