Reflect back to the client their IP address

At Discourse we often need to know what IP address a user might be coming from to diagnose their problems.

We just got rid of a droplet that was serving this function and replaced it with a Lua function running inside HAProxy:

reflectip = function(applet)
  applet:set_status(200)
  applet:add_header("cache-control", "none")
  applet:add_header("content-type", "text/plain")
  applet:start_response()
  applet:send(applet.f:src())
end

core.register_service("reflectip", "http", reflectip)
2 Likes

A possibly easier way without Lua:

http-request return status 200 content-type text/plain lf-string "Your IP: %[src]"

2 Likes