Created
March 20, 2011 02:45
-
-
Save Neopallium/878012 to your computer and use it in GitHub Desktop.
mongrel2 lua handler version of dumpenv.lua
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
local mongrel2 = require 'mongrel2' | |
local sender_id = '558c92aa-1644-4e24-a524-39baad0f8e78' | |
local sub_addr = 'tcp://127.0.0.1:8989' | |
local pub_addr = 'tcp://127.0.0.1:8988' | |
local io_threads = 1 | |
-- Create new mongrel2 context | |
-- This is basically just a wrapper around the zeromq context so we can | |
-- properly terminate it, and set a number of threads to use. | |
local ctx = assert(mongrel2.new(io_threads)) | |
-- Creates a new connection object using the mongrel2 context | |
local conn = assert(ctx:new_connection(sender_id, sub_addr, pub_addr)) | |
local function dump(req) | |
s = {} | |
table.insert(s, "<pre>\n") | |
for n, v in pairs(req.headers) do | |
table.insert(s, string.format("%s = %s\n", n, v)) | |
end | |
table.insert(s, "</pre>\n") | |
if req.body ~= nil and #req.body > 0 then | |
table.insert(s, string.format("<textarea>%s</textarea>", req.body)) | |
end | |
return table.concat(s) | |
end | |
while true do | |
--print 'Waiting for request...' | |
local req = assert(conn:recv()) | |
if req:is_disconnect() then | |
print 'Disconnected' | |
else | |
local response = dump(req) | |
--print(response) | |
assert(conn:reply_http(req, response)) | |
end | |
end | |
assert(ctx:term()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment