comparison mod_rest/mod_rest.lua @ 3862:3b6b8dcff78e

mod_rest: Log connectivity problems via module status API
author Kim Alvefur <zash@zash.se>
date Sat, 25 Jan 2020 20:06:48 +0100
parents ede3d1724dd1
children d845475c75f3
comparison
equal deleted inserted replaced
3861:ede3d1724dd1 3862:3b6b8dcff78e
151 local send_type = module:get_option_string("rest_callback_content_type", "application/xmpp+xml"); 151 local send_type = module:get_option_string("rest_callback_content_type", "application/xmpp+xml");
152 if send_type == "json" then 152 if send_type == "json" then
153 send_type = "application/json"; 153 send_type = "application/json";
154 end 154 end
155 155
156 module:set_status("info", "Not yet connected");
156 http.request(rest_url, { 157 http.request(rest_url, {
157 method = "OPTIONS", 158 method = "OPTIONS",
158 }, function (body, code, response) 159 }, function (body, code, response)
160 if code == 0 then
161 return module:log_status("error", "Could not connect to callback URL %q: %s", rest_url, body);
162 else
163 module:set_status("info", "Connected");
164 end
159 if code == 200 and response.headers.accept then 165 if code == 200 and response.headers.accept then
160 send_type = decide_type(response.headers.accept); 166 send_type = decide_type(response.headers.accept);
161 module:log("debug", "Set 'rest_callback_content_type' = %q based on Accept header", send_type); 167 module:log("debug", "Set 'rest_callback_content_type' = %q based on Accept header", send_type);
162 end 168 end
163 end); 169 end);
214 ["Content-Type"] = send_type, 220 ["Content-Type"] = send_type,
215 ["Content-Language"] = stanza.attr["xml:lang"], 221 ["Content-Language"] = stanza.attr["xml:lang"],
216 Accept = table.concat(supported_types, ", "); 222 Accept = table.concat(supported_types, ", ");
217 }, 223 },
218 }, function (body, code, response) 224 }, function (body, code, response)
225 if code == 0 then
226 return module:log_status("error", "Could not connect to callback URL %q: %s", rest_url, body);
227 else
228 module:set_status("info", "Connected");
229 end
219 if (code == 202 or code == 204) and not reply_needed then 230 if (code == 202 or code == 204) and not reply_needed then
220 -- Delivered, no reply 231 -- Delivered, no reply
221 return; 232 return;
222 end 233 end
223 local reply; 234 local reply;