Fixed HTTP client callers

This commit is contained in:
Jocelyn Fiat
2011-12-12 18:17:39 +01:00
parent 0335226e8b
commit 011f8746d6
2 changed files with 44 additions and 67 deletions

View File

@@ -29,10 +29,9 @@ feature {NONE} -- Initialization
-- Read the Order -- Read the Order
print ("%N Read Order %N") print ("%N Read Order %N")
l_location := resp.headers.at ("Location") l_location := resp.header ("Location")
resp := read_order (sess, l_location) resp := read_order (sess, l_location)
-- Update the Order -- Update the Order
if attached resp.body as l_body then if attached resp.body as l_body then
@@ -44,63 +43,47 @@ feature {NONE} -- Initialization
end end
update_order ( sess: HTTP_CLIENT_SESSION; uri : detachable READABLE_STRING_8; a_body : STRING) : HTTP_CLIENT_RESPONSE update_order ( sess: HTTP_CLIENT_SESSION; uri : detachable READABLE_STRING_8; a_body : STRING) : HTTP_CLIENT_RESPONSE
local
l_headers: HASH_TABLE [READABLE_STRING_8,READABLE_STRING_8]
do do
create Result.make create Result.make
if attached uri as l_uri then if attached uri as l_uri then
sess.set_base_url (l_uri) sess.set_base_url (l_uri)
Result := sess.put ("", Void, a_body ) Result := sess.put ("", Void, a_body )
if attached Result as r then -- Show headers
-- Show headers across
l_headers := r.headers Result.headers as l_headers
from loop
l_headers.start print (l_headers.item.name)
until print (":")
l_headers.after print (l_headers.item.value)
loop
print (l_headers.key_for_iteration)
print (":")
print (l_headers.item_for_iteration)
l_headers.forth
io.put_new_line
end
-- Show body
print (r.body)
io.put_new_line io.put_new_line
end end
-- Show body
print (Result.body)
io.put_new_line
end end
end end
read_order ( sess: HTTP_CLIENT_SESSION; uri : detachable READABLE_STRING_8) : HTTP_CLIENT_RESPONSE read_order ( sess: HTTP_CLIENT_SESSION; uri : detachable READABLE_STRING_8) : HTTP_CLIENT_RESPONSE
local
l_headers: HASH_TABLE [READABLE_STRING_8,READABLE_STRING_8]
do do
create Result.make create Result.make
if attached uri as l_uri then if attached uri as l_uri then
sess.set_base_url (l_uri) sess.set_base_url (l_uri)
Result := sess.get ("", Void) Result := sess.get ("", Void)
if attached Result as r then
-- Show headers -- Show headers
l_headers := r.headers across
from Result.headers as l_headers
l_headers.start loop
until print (l_headers.item.name)
l_headers.after print (":")
loop print (l_headers.item.value)
print (l_headers.key_for_iteration)
print (":")
print (l_headers.item_for_iteration)
l_headers.forth
io.put_new_line
end
-- Show body
print (r.body)
io.put_new_line io.put_new_line
end end
-- Show body
print (Result.body)
io.put_new_line
end end
end end
@@ -112,7 +95,6 @@ feature {NONE} -- Initialization
j: JSON_PARSER j: JSON_PARSER
id: detachable STRING id: detachable STRING
context : HTTP_CLIENT_REQUEST_CONTEXT context : HTTP_CLIENT_REQUEST_CONTEXT
l_headers: HASH_TABLE [READABLE_STRING_8,READABLE_STRING_8]
do do
s := "[ s := "[
{ {
@@ -131,32 +113,26 @@ feature {NONE} -- Initialization
create context.make create context.make
context.headers.put ("application/json", "Content-Type") context.headers.put ("application/json", "Content-Type")
Result := sess.post ("/order", context, s) Result := sess.post ("/order", context, s)
if attached Result as r then -- Show the Headers
-- Show the Headers across
l_headers := r.headers Result.headers as l_headers
from loop
l_headers.start print (l_headers.item.name)
until print (":")
l_headers.after print (l_headers.item.value)
loop io.put_new_line
print (l_headers.key_for_iteration) end
print (":")
print (l_headers.item_for_iteration)
l_headers.forth
io.put_new_line
end
-- Show the Response body -- Show the Response body
if attached r.body as m then if attached Result.body as m then
create j.make_parser (m) create j.make_parser (m)
if j.is_parsed and attached j.parse_object as j_o then if j.is_parsed and attached j.parse_object as j_o then
if attached {JSON_STRING} j_o.item ("id") as l_id then if attached {JSON_STRING} j_o.item ("id") as l_id then
id := l_id.item id := l_id.item
end
print (m)
io.put_new_line
end end
print (m)
io.put_new_line
end end
end end
end end

View File

@@ -1,6 +1,7 @@
note note
description : "Objects that ..." description : "[
author : "$Author$" Response retrieved by the client
]"
date : "$Date$" date : "$Date$"
revision : "$Revision$" revision : "$Revision$"
@@ -59,7 +60,7 @@ feature -- Access
across across
headers as hds headers as hds
loop loop
k := hds.item.key k := hds.item.name
if k.same_string (a_name) then if k.same_string (a_name) then
v := hds.item.value v := hds.item.value
if s = Void then if s = Void then
@@ -73,7 +74,7 @@ feature -- Access
Result := s Result := s
end end
headers: LIST [TUPLE [key: READABLE_STRING_8; value: READABLE_STRING_8]] headers: LIST [TUPLE [name: READABLE_STRING_8; value: READABLE_STRING_8]]
-- Computed table of http headers of the response. -- Computed table of http headers of the response.
--| We use a LIST since one might have multiple message-header fields with the same field-name --| We use a LIST since one might have multiple message-header fields with the same field-name
--| Then the user can handle those case using default or custom concatenation --| Then the user can handle those case using default or custom concatenation