Software / code / prosody
File
plugins/mod_http_altconnect.lua @ 13762:81856814d74f 13.0
util.argparse: Fix bug (regression?) in argument parsing with --foo=bar
After recent changes, '--foo bar' was working, but '--foo=bar' was not. The
test had a typo (?) (bar != baz) and because util.argparse is not strict by
default, the typo was not caught.
The typo caused the code to take a different path, and bypassed the buggy
handling of --foo=bar options.
I've preserved the existing test (typo and all!) because it's still an
interesting test, and ensures no unintended behaviour changes compared to the
old code.
However I've added a new variant of the test, with strict mode enabled and the
typo fixed. This test failed due to the bug, and this commit introduces a fix.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 11 Mar 2025 18:27:36 +0000 |
| parent | 13718:569fae28a2f3 |
line wrap: on
line source
-- mod_http_altconnect -- XEP-0156: Discovering Alternative XMPP Connection Methods module:depends"http"; local mm = require "prosody.core.modulemanager"; local json = require"prosody.util.json"; local st = require"prosody.util.stanza"; local array = require"prosody.util.array"; local advertise_bosh = module:get_option_boolean("advertise_bosh", true); local advertise_websocket = module:get_option_boolean("advertise_websocket", true); local function get_supported() local uris = array(); if advertise_bosh and (mm.is_loaded(module.host, "bosh") or mm.is_loaded("*", "bosh")) then uris:push({ rel = "urn:xmpp:alt-connections:xbosh", href = module:http_url("bosh", "/http-bind") }); end if advertise_websocket and (mm.is_loaded(module.host, "websocket") or mm.is_loaded("*", "websocket")) then uris:push({ rel = "urn:xmpp:alt-connections:websocket", href = module:http_url("websocket", "xmpp-websocket"):gsub("^http", "ws") }); end return uris; end local function GET_xml(event) local response = event.response; local xrd = st.stanza("XRD", { xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0' }); local uris = get_supported(); for _, method in ipairs(uris) do xrd:tag("Link", method):up(); end response.headers.content_type = "application/xrd+xml" response.headers.access_control_allow_origin = "*"; return '<?xml version="1.0" encoding="UTF-8"?>' .. tostring(xrd); end local function GET_json(event) local response = event.response; local jrd = { links = get_supported() }; response.headers.content_type = "application/json" response.headers.access_control_allow_origin = "*"; return json.encode(jrd); end; module:provides("http", { default_path = "/.well-known"; route = { ["GET /host-meta"] = GET_xml; ["GET /host-meta.json"] = GET_json; }; });