Created
August 12, 2013 14:53
-
-
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
This file contains hidden or 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
-- 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