From ad34ec11565ffb715ae1f6f8f1df45a8e0deddd6 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Mon, 22 Apr 2013 21:05:11 +0200 Subject: [PATCH] added header helper feature in the context interface added HTTP_CLIENT_SESSION.custom (...) to support any kind of request methods --- .../src/http_client_request_context.e | 21 ++++++++++++++ .../http_client/src/http_client_session.e | 7 ++++- .../libcurl/libcurl_http_client_session.e | 28 ++++++++----------- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/library/network/http_client/src/http_client_request_context.e b/library/network/http_client/src/http_client_request_context.e index a02ba6b3..663c6a57 100644 --- a/library/network/http_client/src/http_client_request_context.e +++ b/library/network/http_client/src/http_client_request_context.e @@ -113,6 +113,27 @@ feature -- Element change headers.force (v, k) end + add_header_line (s: READABLE_STRING_8) + local + i: INTEGER + do + i := s.index_of (':', 1) + if i > 0 then + add_header (s.substring (1, i - 1), s.substring (i + 1, s.count)) + end + end + + add_header_lines (lst: ITERABLE [READABLE_STRING_8]) + local + i: INTEGER + do + across + lst as c + loop + add_header_line (c.item) + end + end + add_query_parameter (k: READABLE_STRING_32; v: READABLE_STRING_32) do query_parameters.force (v, k) diff --git a/library/network/http_client/src/http_client_session.e b/library/network/http_client/src/http_client_session.e index a2721957..a0aeec09 100644 --- a/library/network/http_client/src/http_client_session.e +++ b/library/network/http_client/src/http_client_session.e @@ -76,6 +76,11 @@ feature -- Basic operation end end + custom (a_method: READABLE_STRING_8; a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE + -- Response for `a_method' request based on Current, `a_path' and `ctx'. + deferred + end + get (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE -- Response for GET request based on Current, `a_path' and `ctx'. deferred @@ -124,7 +129,7 @@ feature -- Status report -- Is interface usable? deferred end - + feature -- Settings timeout: INTEGER diff --git a/library/network/http_client/src/spec/libcurl/libcurl_http_client_session.e b/library/network/http_client/src/spec/libcurl/libcurl_http_client_session.e index 4f80befb..e54dd360 100644 --- a/library/network/http_client/src/spec/libcurl/libcurl_http_client_session.e +++ b/library/network/http_client/src/spec/libcurl/libcurl_http_client_session.e @@ -33,20 +33,22 @@ feature -- Status report feature -- Basic operation - get (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE + custom (a_method: READABLE_STRING_8; a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE local req: HTTP_CLIENT_REQUEST do - create {LIBCURL_HTTP_CLIENT_REQUEST} req.make (base_url + a_path, "GET", Current, ctx) + create {LIBCURL_HTTP_CLIENT_REQUEST} req.make (base_url + a_path, a_method, Current, ctx) Result := req.execute end - head (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE - local - req: HTTP_CLIENT_REQUEST + get (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE do - create {LIBCURL_HTTP_CLIENT_REQUEST} req.make (base_url + a_path, "HEAD", Current, ctx) - Result := req.execute + Result := custom ("GET", a_path, ctx) + end + + head (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE + do + Result := custom ("HEAD", a_path, ctx) end post (a_path: READABLE_STRING_8; a_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; data: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE @@ -87,8 +89,7 @@ feature -- Basic operation ctx.set_upload_filename (f.name) end end - create {LIBCURL_HTTP_CLIENT_REQUEST} req.make (base_url + a_path, "PUT", Current, ctx) - Result := req.execute + Result := custom ("PUT", a_path, ctx) if f /= Void then f.delete end @@ -100,7 +101,6 @@ feature -- Basic operation put_file (a_path: READABLE_STRING_8; a_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; fn: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE local - req: HTTP_CLIENT_REQUEST ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT do ctx := a_ctx @@ -110,16 +110,12 @@ feature -- Basic operation end ctx.set_upload_filename (fn) end - create {LIBCURL_HTTP_CLIENT_REQUEST} req.make (base_url + a_path, "PUT", Current, ctx) - Result := req.execute + Result := custom ("PUT", a_path, ctx) end delete (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE - local - req: HTTP_CLIENT_REQUEST do - create {LIBCURL_HTTP_CLIENT_REQUEST} req.make (base_url + a_path, "DELETE", Current, ctx) - Result := req.execute + Result := custom ("DELETE", a_path, ctx) end feature {NONE} -- Implementation