Improved support for absolute url passed tp HTTP_REQUEST_SESSION .
This commit is contained in:
@@ -36,13 +36,13 @@ 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
|
||||
url := session.url (a_url, Void)
|
||||
end
|
||||
end
|
||||
headers := session.headers.twin
|
||||
if ctx /= Void then
|
||||
context := ctx
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user