Software /
code /
prosody
Comparison
plugins/mod_bosh.lua @ 8594:b4a0bc46c82d
mod_http: Set request.ip on all HTTP requests (moves code out of mod_bosh) (fixes #540)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 15 Mar 2018 17:22:49 +0100 |
parent | 8525:7be8f649d97d |
child | 8743:81929cfe7f86 |
comparison
equal
deleted
inserted
replaced
8593:c4222e36333c | 8594:b4a0bc46c82d |
---|---|
43 local consider_bosh_secure = module:get_option_boolean("consider_bosh_secure"); | 43 local consider_bosh_secure = module:get_option_boolean("consider_bosh_secure"); |
44 local cross_domain = module:get_option("cross_domain_bosh", false); | 44 local cross_domain = module:get_option("cross_domain_bosh", false); |
45 | 45 |
46 if cross_domain == true then cross_domain = "*"; end | 46 if cross_domain == true then cross_domain = "*"; end |
47 if type(cross_domain) == "table" then cross_domain = table.concat(cross_domain, ", "); end | 47 if type(cross_domain) == "table" then cross_domain = table.concat(cross_domain, ", "); end |
48 | |
49 local trusted_proxies = module:get_option_set("trusted_proxies", { "127.0.0.1", "::1" })._items; | |
50 | |
51 local function get_ip_from_request(request) | |
52 local ip = request.conn:ip(); | |
53 local forwarded_for = request.headers.x_forwarded_for; | |
54 if forwarded_for then | |
55 forwarded_for = forwarded_for..", "..ip; | |
56 for forwarded_ip in forwarded_for:gmatch("[^%s,]+") do | |
57 if not trusted_proxies[forwarded_ip] then | |
58 ip = forwarded_ip; | |
59 end | |
60 end | |
61 end | |
62 return ip; | |
63 end | |
64 | 48 |
65 local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; | 49 local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; |
66 | 50 |
67 -- All sessions, and sessions that have no requests open | 51 -- All sessions, and sessions that have no requests open |
68 local sessions = module:shared("sessions"); | 52 local sessions = module:shared("sessions"); |
305 bosh_version = attr.ver, bosh_wait = wait, streamid = sid, | 289 bosh_version = attr.ver, bosh_wait = wait, streamid = sid, |
306 bosh_max_inactive = bosh_max_inactivity, | 290 bosh_max_inactive = bosh_max_inactivity, |
307 requests = { }, send_buffer = {}, reset_stream = bosh_reset_stream, | 291 requests = { }, send_buffer = {}, reset_stream = bosh_reset_stream, |
308 close = bosh_close_stream, dispatch_stanza = core_process_stanza, notopen = true, | 292 close = bosh_close_stream, dispatch_stanza = core_process_stanza, notopen = true, |
309 log = logger.init("bosh"..sid), secure = consider_bosh_secure or request.secure, | 293 log = logger.init("bosh"..sid), secure = consider_bosh_secure or request.secure, |
310 ip = get_ip_from_request(request); | 294 ip = request.ip; |
311 }; | 295 }; |
312 sessions[sid] = session; | 296 sessions[sid] = session; |
313 | 297 |
314 session.thread = runner(function (stanza) | 298 session.thread = runner(function (stanza) |
315 session:dispatch_stanza(stanza); | 299 session:dispatch_stanza(stanza); |