|
@@ -267,13 +267,19 @@ end
|
267
|
267
|
--- retry @param retry number of times
|
268
|
268
|
-- @param url endpoint to be called
|
269
|
269
|
-- @param retry nr of retries, if retry is
|
|
270
|
+-- @param auth_token value to be passed as auth Bearer
|
270
|
271
|
-- nil there will be no retries
|
271
|
272
|
-- @returns result of the http call or nil if
|
272
|
273
|
-- the external call failed after the last retry
|
273
|
|
-function http_get_with_retry(url, retry)
|
|
274
|
+function http_get_with_retry(url, retry, auth_token)
|
274
|
275
|
local content, code;
|
275
|
276
|
local timeout_occurred;
|
276
|
277
|
local wait, done = async.waiter();
|
|
278
|
+ local request_headers = http_headers or {}
|
|
279
|
+ if auth_token ~= nil then
|
|
280
|
+ request_headers['Authorization'] = 'Bearer ' .. auth_token
|
|
281
|
+ end
|
|
282
|
+
|
277
|
283
|
local function cb(content_, code_, response_, request_)
|
278
|
284
|
if timeout_occurred == nil then
|
279
|
285
|
code = code_;
|
|
@@ -281,7 +287,7 @@ function http_get_with_retry(url, retry)
|
281
|
287
|
module:log("debug", "External call was successful, content %s", content_);
|
282
|
288
|
content = content_
|
283
|
289
|
else
|
284
|
|
- module:log("warn", "Error on public key request: Code %s, Content %s",
|
|
290
|
+ module:log("warn", "Error on GET request: Code %s, Content %s",
|
285
|
291
|
code_, content_);
|
286
|
292
|
end
|
287
|
293
|
done();
|
|
@@ -292,7 +298,7 @@ function http_get_with_retry(url, retry)
|
292
|
298
|
|
293
|
299
|
local function call_http()
|
294
|
300
|
return http.request(url, {
|
295
|
|
- headers = http_headers or {},
|
|
301
|
+ headers = request_headers,
|
296
|
302
|
method = "GET"
|
297
|
303
|
}, cb);
|
298
|
304
|
end
|
|
@@ -326,7 +332,7 @@ function http_get_with_retry(url, retry)
|
326
|
332
|
timer.add_task(http_timeout, cancel);
|
327
|
333
|
wait();
|
328
|
334
|
|
329
|
|
- return content;
|
|
335
|
+ return content, code;
|
330
|
336
|
end
|
331
|
337
|
|
332
|
338
|
-- Checks whether there is status in the <x node
|