Added https support with Net implementation.
Added notion of default HTTP_CLIENT, to be able to build portable code among http client implementation.
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<variable name="netssl_http_client_enabled" value="false"/>
|
||||
<variable name="libcurl_http_client_disabled" value="false"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="http_client" location="..\http_client-safe.ecf" readonly="false" use_application_options="true">
|
||||
<option>
|
||||
@@ -17,6 +19,19 @@
|
||||
</option>
|
||||
</library>
|
||||
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
|
||||
<tests name="tests" location=".\"/>
|
||||
<tests name="tests" location=".\">
|
||||
<file_rule>
|
||||
<exclude>.*libcurl_.*.e$</exclude>
|
||||
<condition>
|
||||
<custom name="libcurl_http_client_disabled" value="true"/>
|
||||
</condition>
|
||||
</file_rule>
|
||||
<file_rule>
|
||||
<exclude>.*net_.*.e$</exclude>
|
||||
<condition>
|
||||
<custom name="net_http_client_disabled" value="true"/>
|
||||
</condition>
|
||||
</file_rule>
|
||||
</tests>
|
||||
</target>
|
||||
</system>
|
||||
|
||||
@@ -13,16 +13,40 @@ feature -- Init
|
||||
if attached null.new_session ("http://example.com/") as l_sess then
|
||||
check not l_sess.is_available end
|
||||
end
|
||||
test_get_with_authentication
|
||||
test_http_client
|
||||
end
|
||||
|
||||
test_get_with_authentication
|
||||
local
|
||||
cl: DEFAULT_HTTP_CLIENT
|
||||
sess: HTTP_CLIENT_SESSION
|
||||
ctx: HTTP_CLIENT_REQUEST_CONTEXT
|
||||
do
|
||||
-- GET REQUEST WITH AUTHENTICATION, see http://browserspy.dk/password.php
|
||||
-- check header WWW-Authenticate is received (authentication successful)
|
||||
create cl
|
||||
sess := cl.new_session ("http://browserspy.dk")
|
||||
sess.set_credentials ("test", "test")
|
||||
create ctx.make_with_credentials_required
|
||||
if attached sess.get ("/password-ok.php", ctx) as res then
|
||||
if attached {READABLE_STRING_8} res.body as l_body then
|
||||
assert ("Fetch all body, including closing html tag", l_body.has_substring ("</html>"))
|
||||
else
|
||||
assert ("has body", False)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test_http_client
|
||||
-- New test routine
|
||||
local
|
||||
sess: LIBCURL_HTTP_CLIENT_SESSION
|
||||
cl: DEFAULT_HTTP_CLIENT
|
||||
sess: HTTP_CLIENT_SESSION
|
||||
h: STRING_8
|
||||
do
|
||||
create sess.make ("http://www.google.com")
|
||||
create cl
|
||||
sess := cl.new_session ("http://www.google.com")
|
||||
if attached sess.get ("/search?q=eiffel", Void) as res then
|
||||
assert ("Get returned without error", not res.error_occurred)
|
||||
create h.make_empty
|
||||
|
||||
@@ -47,21 +47,30 @@ feature -- Test routines
|
||||
end
|
||||
end
|
||||
|
||||
test_http_client_requestbin
|
||||
test_http_client_ssl
|
||||
-- New test routine
|
||||
local
|
||||
sess: like new_session
|
||||
h: STRING_8
|
||||
do
|
||||
sess := new_session ("http://requestb.in")
|
||||
create h.make_empty
|
||||
if attached sess.get ("/1a0q2h61", Void).headers as hds then
|
||||
across
|
||||
hds as c
|
||||
loop
|
||||
h.append (c.item.name + ": " + c.item.value + "%R%N")
|
||||
sess := new_session ("https://www.eiffel.org")
|
||||
if attached sess.get ("/welcome", Void) as res then
|
||||
assert ("Get returned without error", not res.error_occurred)
|
||||
create h.make_empty
|
||||
if attached res.headers as hds then
|
||||
across
|
||||
hds as c
|
||||
loop
|
||||
h.append (c.item.name + ": " + c.item.value + "%R%N")
|
||||
end
|
||||
end
|
||||
if attached res.body as l_body then
|
||||
assert ("body not empty", not l_body.is_empty)
|
||||
else
|
||||
assert ("missing body", False)
|
||||
end
|
||||
assert ("same headers", h.same_string (res.raw_header))
|
||||
end
|
||||
print (h)
|
||||
end
|
||||
|
||||
test_headers
|
||||
|
||||
@@ -27,9 +27,9 @@ feature -- Tests
|
||||
test_http_client
|
||||
end
|
||||
|
||||
test_libcurl_http_client_requestbin
|
||||
test_libcurl_http_client_ssl
|
||||
do
|
||||
test_http_client_requestbin
|
||||
test_http_client_ssl
|
||||
end
|
||||
|
||||
test_libcurl_headers
|
||||
|
||||
@@ -27,9 +27,9 @@ feature -- Tests
|
||||
test_http_client
|
||||
end
|
||||
|
||||
test_net_http_client_requestbin
|
||||
test_net_http_client_ssl
|
||||
do
|
||||
test_http_client_requestbin
|
||||
test_http_client_ssl
|
||||
end
|
||||
|
||||
test_net_headers
|
||||
|
||||
Reference in New Issue
Block a user