Update the restbuck_client, still work in progress.
Update restbuck_server, remove unused class in inherit. Update libcurl_http_client_request, to parse context headers before the execution. Update wgi_input_stream, commented precondition.
This commit is contained in:
@@ -17,12 +17,26 @@ feature {NONE} -- Initialization
|
|||||||
local
|
local
|
||||||
h: LIBCURL_HTTP_CLIENT
|
h: LIBCURL_HTTP_CLIENT
|
||||||
sess: HTTP_CLIENT_SESSION
|
sess: HTTP_CLIENT_SESSION
|
||||||
|
do
|
||||||
|
create h.make
|
||||||
|
sess := h.new_session ("http://127.0.0.1:8080")
|
||||||
|
-- Create Order
|
||||||
|
create_order (sess)
|
||||||
|
|
||||||
|
-- if id /= Void and then attached sess.get ("/order/" + id, Void) as r then
|
||||||
|
-- print (r.body)
|
||||||
|
-- io.put_new_line
|
||||||
|
-- end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
create_order (sess: HTTP_CLIENT_SESSION)
|
||||||
|
local
|
||||||
s: READABLE_STRING_8
|
s: READABLE_STRING_8
|
||||||
j: JSON_PARSER
|
j: JSON_PARSER
|
||||||
id: detachable STRING
|
id: detachable STRING
|
||||||
|
context : HTTP_CLIENT_REQUEST_CONTEXT
|
||||||
do
|
do
|
||||||
create h.make
|
|
||||||
sess := h.new_session ("http://127.0.0.1")
|
|
||||||
s := "[
|
s := "[
|
||||||
{
|
{
|
||||||
"location":"takeAway",
|
"location":"takeAway",
|
||||||
@@ -37,32 +51,25 @@ feature {NONE} -- Initialization
|
|||||||
}
|
}
|
||||||
]"
|
]"
|
||||||
|
|
||||||
if attached sess.post ("/order", Void, s) as r then
|
create context.make
|
||||||
|
context.headers.put ("application/json", "Content-Type")
|
||||||
|
if attached sess.post ("/order", context, s) as r then
|
||||||
|
print (r.raw_header)
|
||||||
|
io.put_new_line
|
||||||
if attached r.body as m then
|
if attached r.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
|
end
|
||||||
print (m)
|
print (m)
|
||||||
io.put_new_line
|
io.put_new_line
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if id /= Void and then attached sess.get ("/order/" + id, Void) as r then
|
|
||||||
print (r.body)
|
|
||||||
io.put_new_line
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Status
|
|
||||||
|
|
||||||
feature -- Access
|
|
||||||
|
|
||||||
feature -- Change
|
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ inherit
|
|||||||
|
|
||||||
URI_TEMPLATE_ROUTED_SERVICE
|
URI_TEMPLATE_ROUTED_SERVICE
|
||||||
|
|
||||||
ROUTED_SERVICE_HELPER
|
|
||||||
|
|
||||||
DEFAULT_SERVICE
|
DEFAULT_SERVICE
|
||||||
|
|
||||||
create
|
create
|
||||||
|
|||||||
@@ -167,7 +167,15 @@ feature -- Execution
|
|||||||
p := curl.slist_append (p, curs.key + ": " + curs.item)
|
p := curl.slist_append (p, curs.key + ": " + curs.item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if ctx /= Void then
|
||||||
|
if attached ctx.headers as l_headers_2 then
|
||||||
|
across
|
||||||
|
l_headers_2 as curs_2
|
||||||
|
loop
|
||||||
|
p := curl.slist_append (p, curs_2.key + ": " + curs_2.item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
p := curl.slist_append (p, "Expect:")
|
p := curl.slist_append (p, "Expect:")
|
||||||
curl_easy.setopt_slist (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_httpheader, p)
|
curl_easy.setopt_slist (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_httpheader, p)
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ feature -- Input
|
|||||||
read_string (nb: INTEGER)
|
read_string (nb: INTEGER)
|
||||||
require
|
require
|
||||||
is_open_read: is_open_read
|
is_open_read: is_open_read
|
||||||
not_end_of_input: not end_of_input
|
-- not_end_of_input: not end_of_input
|
||||||
nb_large_enough: nb > 0
|
nb_large_enough: nb > 0
|
||||||
deferred
|
deferred
|
||||||
ensure
|
ensure
|
||||||
|
|||||||
@@ -17,11 +17,13 @@ feature {NONE} -- Initialization
|
|||||||
do
|
do
|
||||||
port_number := 8080
|
port_number := 8080
|
||||||
base_url := ""
|
base_url := ""
|
||||||
|
|
||||||
debug ("nino")
|
debug ("nino")
|
||||||
print ("Example: start a Nino web server on port " + port_number.out +
|
print ("Example: start a Nino web server on port " + port_number.out +
|
||||||
", %Nand reply Hello World for any request such as http://localhost:" + port_number.out + "/" + base_url + "%N")
|
", %Nand reply Hello World for any request such as http://localhost:" + port_number.out + "/" + base_url + "%N")
|
||||||
end
|
end
|
||||||
create app.make_custom (agent wgi_execute, base_url)
|
create app.make_custom (agent wgi_execute, base_url)
|
||||||
|
app.configuration.set_is_verbose (True)
|
||||||
app.listen (port_number)
|
app.listen (port_number)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user