changeset 495:75d8a5261f82

more verbose httpclient test
author Alain Mazy <am@osimis.io>
date Wed, 17 Aug 2022 09:37:47 +0200
parents cffef67c9a94
children f78f7ee6b660
files Database/Lua/HttpClient.lua
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Database/Lua/HttpClient.lua	Wed Aug 10 15:15:20 2022 +0200
+++ b/Database/Lua/HttpClient.lua	Wed Aug 17 09:37:47 2022 +0200
@@ -14,6 +14,7 @@
 retry = 10
 response = nil
 while retry > 0 and response == nil do
+	print("HttpClient test: POST with body to httpbin.org")
 	response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders))
 end
 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
@@ -24,6 +25,7 @@
 retry = 10
 response = nil
 while retry > 0 and response == nil do
+	print("HttpClient test: POST without body to httpbin.org")
 	response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders))
 end
 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
@@ -34,6 +36,7 @@
 retry = 10
 response = nil
 while retry > 0 and response == nil do
+	print("HttpClient test: PUT with body to httpbin.org")
 	response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders))
 end
 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
@@ -44,6 +47,7 @@
 retry = 10
 response = nil
 while retry > 0 and response == nil do
+	print("HttpClient test: PUT without body to httpbin.org")
 	response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders))
 end
 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
@@ -60,7 +64,9 @@
 retry = 10
 response = nil
 while retry > 0 and response == nil do
+	print("HttpClient test: GET to httpbin.org")
 	response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders))
+	sleep(1)
 end
 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
 if not testSucceeded then print('Failed in HttpGet') PrintRecursive(response) end
@@ -71,11 +77,13 @@
 if system['Version'] == 'mainline' or system['Version'] == '1.11.1' or system['ApiVersion'] >= 18 then  -- introduced in 1.11.1 which is ApiVersion 17 (too lazy to reimplement IsAboveOrthancVersion in lua :-) )
 	-- Test SetHttpTimeout
 	SetHttpTimeout(10)
+	print("HttpClient test: GET with timeout (10) to httpstat.us")
 	response = HttpGet('https://httpstat.us/200?sleep=1000')
 	testSucceeded = testSucceeded and (response == '200 OK')
 	if not testSucceeded then print('Failed in SetHttpTimeout1') PrintRecursive(response) end
 
 	SetHttpTimeout(1)
+	print("HttpClient test: GET with timeout (1) to httpstat.us")
 	response = HttpGet('https://httpstat.us/200?sleep=2000')
 	testSucceeded = testSucceeded and (response == nil)
 	if not testSucceeded then print('Failed in SetHttpTimeout2') PrintRecursive(response) end