view Database/Lua/HttpClient.lua @ 193:ef2c66f81249

Added tag Orthanc-1.5.1 for changeset 6ff9d035b26b
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 20 Dec 2018 12:23:58 +0100
parents 7530eb50c3c4
children a2719263fd04
line wrap: on
line source

-- for these tests, we issue HTTP requests to httpbin.org that performs smart echo (it returns all data/headers it has received + some extra data)

testSucceeded = true

local payload = {}
payload['stringMember'] = 'toto'
payload['intMember'] = 2

local httpHeaders = {}
httpHeaders['Content-Type'] = 'application/json'
httpHeaders['Toto'] = 'Tutu'

-- Issue HttpPost with body
response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders))
testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto')
if not testSucceeded then print('Failed in HttpPost with body') PrintRecursive(response) end

-- Issue HttpPost without body
response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders))
testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
testSucceeded = testSucceeded and (response['data'] == '')
if not testSucceeded then print('Failed in HttpPost without body') PrintRecursive(response) end

-- Issue HttpPut with body
response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders))
testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto')
if not testSucceeded then print('Failed in HttpPut with body') PrintRecursive(response) end

-- Issue HttpPut without body
response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders))
testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
testSucceeded = testSucceeded and (response['data'] == '')
if not testSucceeded then print('Failed in HttpPut without body') PrintRecursive(response) end

-- Issue HttpDelete (juste make sure it is issued, we can't check the response)
HttpDelete('http://httpbin.org/delete', httpHeaders)

-- Issue HttpGet
response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders))
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

if testSucceeded then
	print('OK')
else
	print('FAILED')
end