Improved support for absolute url passed tp HTTP_REQUEST_SESSION .

This commit is contained in:
Jocelyn Fiat
2017-10-27 19:24:52 +02:00
parent 503e5f7915
commit f770c236d5
7 changed files with 75 additions and 4 deletions

View File

@@ -36,8 +36,8 @@ feature {NONE} -- Initialization
i := a_url.substring_index ("://", 1)
if i > 0 then
check
a_url.substring (1, i).same_string ("http")
or a_url.substring (1, i).same_string ("https")
a_url.head (i - 1).same_string ("http")
or a_url.head (i - 1).same_string ("https")
end
url := a_url
else

View File

@@ -61,12 +61,40 @@ feature -- Access
url (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): STRING_8
-- Url computed from Current and `ctx' data.
do
Result := base_url + a_path
if is_absolute_url (a_path) then
-- Is Absolute url
Result := a_path
else
Result := base_url + a_path
end
if ctx /= Void then
ctx.append_query_parameters_to_url (Result)
end
end
is_absolute_url (s: READABLE_STRING_GENERAL): BOOLEAN
-- Does `s` represent an absolute url?
local
i, pos: INTEGER
sch: READABLE_STRING_GENERAL
do
pos := s.substring_index ("://", 1)
if pos > 0 then
sch := s.head (pos - 1)
if not sch.is_whitespace then
from
i := 1
Result := True
until
not Result or i > sch.count
loop
Result := sch[i].is_alpha_numeric
i := i + 1
end
end
end
end
feature {NONE} -- Access: verbose
verbose_mode: INTEGER

View File

@@ -7,6 +7,9 @@ note
deferred class
HTTP_CLIENT_REQUEST_PARAMETER
inherit
DEBUG_OUTPUT
feature -- Access
name: READABLE_STRING_32
@@ -18,6 +21,15 @@ feature -- Access
deferred
end
feature -- Status report
debug_output: STRING_32
do
create Result.make_empty
Result.append (name)
Result.append ("=...")
end
feature -- Conversion
append_form_url_encoded_to (a_output: STRING_8)

View File

@@ -29,6 +29,11 @@ feature -- Access
Result := items.count
end
has (a_parameter_name: READABLE_STRING_GENERAL): BOOLEAN
do
Result := across items as ic some a_parameter_name.same_string (ic.item.name) end
end
feature -- Element change
extend, force (i: G)

View File

@@ -74,6 +74,22 @@ feature -- Test routines
end
end
test_abs_url
local
sess: like new_session
h: STRING_8
l_url: STRING
do
sess := new_session ("https://www.eiffel.org")
l_url := "/foo/bar"
assert ("abs rel", sess.url (l_url, Void).same_string (sess.base_url + l_url))
l_url := "https://www.eiffel.org/foo/bar"
assert ("abs 1", sess.url (l_url, Void).same_string (l_url))
l_url := "https://example.com/foo/bar"
assert ("abs 2", sess.url (l_url, Void).same_string (l_url))
end
test_headers
local
res: HTTP_CLIENT_RESPONSE

View File

@@ -32,6 +32,11 @@ feature -- Tests
test_http_client_ssl
end
test_libcurl_abs_url
do
test_abs_url
end
test_libcurl_headers
do
test_headers

View File

@@ -32,6 +32,11 @@ feature -- Tests
test_http_client_ssl
end
test_net_abs_url
do
test_abs_url
end
test_net_headers
do
test_headers