You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pgfqe6ch8/lib/response_ip.rb

21 lines
755 B

6 years ago
#coding=utf-8
#
require 'socket'
class ResponseIp
def initialize(app)
@app = app
end
def ip
addr = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}.ip_address rescue
addr || ''
end
def call(env)
status, headers, body = @app.call(env)
headers["X-response-ip"] = ip
[status, headers, body]
end
end