added header helper feature in the context interface
added HTTP_CLIENT_SESSION.custom (...) to support any kind of request methods
This commit is contained in:
@@ -113,6 +113,27 @@ feature -- Element change
|
|||||||
headers.force (v, k)
|
headers.force (v, k)
|
||||||
end
|
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)
|
add_query_parameter (k: READABLE_STRING_32; v: READABLE_STRING_32)
|
||||||
do
|
do
|
||||||
query_parameters.force (v, k)
|
query_parameters.force (v, k)
|
||||||
|
|||||||
@@ -76,6 +76,11 @@ feature -- Basic operation
|
|||||||
end
|
end
|
||||||
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
|
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'.
|
-- Response for GET request based on Current, `a_path' and `ctx'.
|
||||||
deferred
|
deferred
|
||||||
@@ -124,7 +129,7 @@ feature -- Status report
|
|||||||
-- Is interface usable?
|
-- Is interface usable?
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Settings
|
feature -- Settings
|
||||||
|
|
||||||
timeout: INTEGER
|
timeout: INTEGER
|
||||||
|
|||||||
@@ -33,20 +33,22 @@ feature -- Status report
|
|||||||
|
|
||||||
feature -- Basic operation
|
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
|
local
|
||||||
req: HTTP_CLIENT_REQUEST
|
req: HTTP_CLIENT_REQUEST
|
||||||
do
|
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
|
Result := req.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
head (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE
|
get (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE
|
||||||
local
|
|
||||||
req: HTTP_CLIENT_REQUEST
|
|
||||||
do
|
do
|
||||||
create {LIBCURL_HTTP_CLIENT_REQUEST} req.make (base_url + a_path, "HEAD", Current, ctx)
|
Result := custom ("GET", a_path, ctx)
|
||||||
Result := req.execute
|
end
|
||||||
|
|
||||||
|
head (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE
|
||||||
|
do
|
||||||
|
Result := custom ("HEAD", a_path, ctx)
|
||||||
end
|
end
|
||||||
|
|
||||||
post (a_path: READABLE_STRING_8; a_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; data: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
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)
|
ctx.set_upload_filename (f.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
create {LIBCURL_HTTP_CLIENT_REQUEST} req.make (base_url + a_path, "PUT", Current, ctx)
|
Result := custom ("PUT", a_path, ctx)
|
||||||
Result := req.execute
|
|
||||||
if f /= Void then
|
if f /= Void then
|
||||||
f.delete
|
f.delete
|
||||||
end
|
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
|
put_file (a_path: READABLE_STRING_8; a_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT; fn: detachable READABLE_STRING_8): HTTP_CLIENT_RESPONSE
|
||||||
local
|
local
|
||||||
req: HTTP_CLIENT_REQUEST
|
|
||||||
ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT
|
ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT
|
||||||
do
|
do
|
||||||
ctx := a_ctx
|
ctx := a_ctx
|
||||||
@@ -110,16 +110,12 @@ feature -- Basic operation
|
|||||||
end
|
end
|
||||||
ctx.set_upload_filename (fn)
|
ctx.set_upload_filename (fn)
|
||||||
end
|
end
|
||||||
create {LIBCURL_HTTP_CLIENT_REQUEST} req.make (base_url + a_path, "PUT", Current, ctx)
|
Result := custom ("PUT", a_path, ctx)
|
||||||
Result := req.execute
|
|
||||||
end
|
end
|
||||||
|
|
||||||
delete (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE
|
delete (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): HTTP_CLIENT_RESPONSE
|
||||||
local
|
|
||||||
req: HTTP_CLIENT_REQUEST
|
|
||||||
do
|
do
|
||||||
create {LIBCURL_HTTP_CLIENT_REQUEST} req.make (base_url + a_path, "DELETE", Current, ctx)
|
Result := custom ("DELETE", a_path, ctx)
|
||||||
Result := req.execute
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|||||||
Reference in New Issue
Block a user