Comparison

plugins/mod_http_altconnect.lua @ 13721:8170dd8f370c

Merge 13.0->trunk
author Matthew Wild <mwild1@gmail.com>
date Sun, 16 Feb 2025 13:44:23 +0000
parent 13718:569fae28a2f3
comparison
equal deleted inserted replaced
13716:953108962cd0 13721:8170dd8f370c
1 -- mod_http_altconnect
2 -- XEP-0156: Discovering Alternative XMPP Connection Methods
3
4 module:depends"http";
5
6 local mm = require "prosody.core.modulemanager";
7 local json = require"prosody.util.json";
8 local st = require"prosody.util.stanza";
9 local array = require"prosody.util.array";
10
11 local advertise_bosh = module:get_option_boolean("advertise_bosh", true);
12 local advertise_websocket = module:get_option_boolean("advertise_websocket", true);
13
14 local function get_supported()
15 local uris = array();
16 if advertise_bosh and (mm.is_loaded(module.host, "bosh") or mm.is_loaded("*", "bosh")) then
17 uris:push({ rel = "urn:xmpp:alt-connections:xbosh", href = module:http_url("bosh", "/http-bind") });
18 end
19 if advertise_websocket and (mm.is_loaded(module.host, "websocket") or mm.is_loaded("*", "websocket")) then
20 uris:push({ rel = "urn:xmpp:alt-connections:websocket", href = module:http_url("websocket", "xmpp-websocket"):gsub("^http", "ws") });
21 end
22 return uris;
23 end
24
25
26 local function GET_xml(event)
27 local response = event.response;
28 local xrd = st.stanza("XRD", { xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0' });
29 local uris = get_supported();
30 for _, method in ipairs(uris) do
31 xrd:tag("Link", method):up();
32 end
33 response.headers.content_type = "application/xrd+xml"
34 response.headers.access_control_allow_origin = "*";
35 return '<?xml version="1.0" encoding="UTF-8"?>' .. tostring(xrd);
36 end
37
38 local function GET_json(event)
39 local response = event.response;
40 local jrd = { links = get_supported() };
41 response.headers.content_type = "application/json"
42 response.headers.access_control_allow_origin = "*";
43 return json.encode(jrd);
44 end;
45
46 module:provides("http", {
47 default_path = "/.well-known";
48 route = {
49 ["GET /host-meta"] = GET_xml;
50 ["GET /host-meta.json"] = GET_json;
51 };
52 });