Mercurial > prosody-modules
view mod_http_authentication/mod_http_authentication.lua @ 4629:0e60ce83205c
mod_s2s_keepalive: Ignore errors from the local server
If a stanza can't be delivered and instead an bounce is generated, the
origin of the error, when different from the stanza 'from' should be
indicated in the 'by' attribute of the <error>, which we look for here
so this doesn't count as a successful ping.
An error that does come from the remote means we have connectivity, but
probably no XEP-0199 handling. This is fine. We care about connectivity,
not protocol.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 21 Jul 2021 15:57:13 +0200 |
parents | 05725785e3a6 |
children |
line wrap: on
line source
module:set_global(); local b64_decode = require "util.encodings".base64.decode; local server = require "net.http.server"; local credentials = module:get_option_string("http_credentials", "username:secretpassword"); local unauthed_endpoints = module:get_option_set("unauthenticated_http_endpoints", { "/http-bind", "/http-bind/" })._items; module:wrap_object_event(server._events, false, function (handlers, event_name, event_data) local request = event_data.request; if event_name ~= "http-error" and request and not unauthed_endpoints[request.path] then local response = event_data.response; local headers = request.headers; if not headers.authorization then response.headers.www_authenticate = ("Basic realm=%q"):format(module.host.."/"..module.name); return 401; end local user_password = b64_decode(headers.authorization:match("%s(%S*)$")); if user_password ~= credentials then return 401; end end return handlers(event_name, event_data); end);