From c0c206e9ae2420350b9a458bd68a42cd7f814e8e Mon Sep 17 00:00:00 2001 From: jvelilla Date: Fri, 9 Dec 2011 21:11:16 -0300 Subject: [PATCH] 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. --- .../client/src/restbuck_client.e | 35 +++++++++++-------- examples/restbucksCRUD/src/restbucks_server.e | 2 -- .../libcurl/libcurl_http_client_request.e | 10 +++++- library/server/ewsgi/src/wgi_input_stream.e | 2 +- .../server/wsf/default/nino/default_service.e | 2 ++ 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/examples/restbucksCRUD/client/src/restbuck_client.e b/examples/restbucksCRUD/client/src/restbuck_client.e index dec021d0..bcaf158f 100644 --- a/examples/restbucksCRUD/client/src/restbuck_client.e +++ b/examples/restbucksCRUD/client/src/restbuck_client.e @@ -17,12 +17,26 @@ feature {NONE} -- Initialization local h: LIBCURL_HTTP_CLIENT 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 j: JSON_PARSER id: detachable STRING + context : HTTP_CLIENT_REQUEST_CONTEXT do - create h.make - sess := h.new_session ("http://127.0.0.1") s := "[ { "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 create j.make_parser (m) - 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 id := l_id.item end print (m) io.put_new_line - 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 -feature -- Status - -feature -- Access - -feature -- Change feature {NONE} -- Implementation diff --git a/examples/restbucksCRUD/src/restbucks_server.e b/examples/restbucksCRUD/src/restbucks_server.e index be9f9da5..b0c9093c 100644 --- a/examples/restbucksCRUD/src/restbucks_server.e +++ b/examples/restbucksCRUD/src/restbucks_server.e @@ -12,8 +12,6 @@ inherit URI_TEMPLATE_ROUTED_SERVICE - ROUTED_SERVICE_HELPER - DEFAULT_SERVICE create diff --git a/library/client/http_client/src/spec/libcurl/libcurl_http_client_request.e b/library/client/http_client/src/spec/libcurl/libcurl_http_client_request.e index b29bfeee..9026d9dc 100644 --- a/library/client/http_client/src/spec/libcurl/libcurl_http_client_request.e +++ b/library/client/http_client/src/spec/libcurl/libcurl_http_client_request.e @@ -167,7 +167,15 @@ feature -- Execution p := curl.slist_append (p, curs.key + ": " + curs.item) 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:") curl_easy.setopt_slist (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_httpheader, p) diff --git a/library/server/ewsgi/src/wgi_input_stream.e b/library/server/ewsgi/src/wgi_input_stream.e index 91a2a988..0fc87c28 100644 --- a/library/server/ewsgi/src/wgi_input_stream.e +++ b/library/server/ewsgi/src/wgi_input_stream.e @@ -27,7 +27,7 @@ feature -- Input read_string (nb: INTEGER) require 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 deferred ensure diff --git a/library/server/wsf/default/nino/default_service.e b/library/server/wsf/default/nino/default_service.e index 0eb3c0d1..42179264 100644 --- a/library/server/wsf/default/nino/default_service.e +++ b/library/server/wsf/default/nino/default_service.e @@ -17,11 +17,13 @@ feature {NONE} -- Initialization do port_number := 8080 base_url := "" + debug ("nino") 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") end create app.make_custom (agent wgi_execute, base_url) + app.configuration.set_is_verbose (True) app.listen (port_number) end