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)
|
i := a_url.substring_index ("://", 1)
|
||||||
if i > 0 then
|
if i > 0 then
|
||||||
check
|
check
|
||||||
a_url.substring (1, i).same_string ("http")
|
a_url.head (i - 1).same_string ("http")
|
||||||
or a_url.substring (1, i).same_string ("https")
|
or a_url.head (i - 1).same_string ("https")
|
||||||
end
|
end
|
||||||
url := a_url
|
url := a_url
|
||||||
else
|
else
|
||||||
url := session.url (a_url, Void)
|
url := session.url (a_url, Void)
|
||||||
end
|
end
|
||||||
headers := session.headers.twin
|
headers := session.headers.twin
|
||||||
if ctx /= Void then
|
if ctx /= Void then
|
||||||
context := ctx
|
context := ctx
|
||||||
|
|||||||
@@ -61,12 +61,40 @@ feature -- Access
|
|||||||
url (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): STRING_8
|
url (a_path: READABLE_STRING_8; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): STRING_8
|
||||||
-- Url computed from Current and `ctx' data.
|
-- Url computed from Current and `ctx' data.
|
||||||
do
|
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
|
if ctx /= Void then
|
||||||
ctx.append_query_parameters_to_url (Result)
|
ctx.append_query_parameters_to_url (Result)
|
||||||
end
|
end
|
||||||
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
|
feature {NONE} -- Access: verbose
|
||||||
|
|
||||||
verbose_mode: INTEGER
|
verbose_mode: INTEGER
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ note
|
|||||||
deferred class
|
deferred class
|
||||||
HTTP_CLIENT_REQUEST_PARAMETER
|
HTTP_CLIENT_REQUEST_PARAMETER
|
||||||
|
|
||||||
|
inherit
|
||||||
|
DEBUG_OUTPUT
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
name: READABLE_STRING_32
|
name: READABLE_STRING_32
|
||||||
@@ -18,6 +21,15 @@ feature -- Access
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Status report
|
||||||
|
|
||||||
|
debug_output: STRING_32
|
||||||
|
do
|
||||||
|
create Result.make_empty
|
||||||
|
Result.append (name)
|
||||||
|
Result.append ("=...")
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Conversion
|
feature -- Conversion
|
||||||
|
|
||||||
append_form_url_encoded_to (a_output: STRING_8)
|
append_form_url_encoded_to (a_output: STRING_8)
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ feature -- Access
|
|||||||
Result := items.count
|
Result := items.count
|
||||||
end
|
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
|
feature -- Element change
|
||||||
|
|
||||||
extend, force (i: G)
|
extend, force (i: G)
|
||||||
|
|||||||
@@ -74,6 +74,22 @@ feature -- Test routines
|
|||||||
end
|
end
|
||||||
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
|
test_headers
|
||||||
local
|
local
|
||||||
res: HTTP_CLIENT_RESPONSE
|
res: HTTP_CLIENT_RESPONSE
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ feature -- Tests
|
|||||||
test_http_client_ssl
|
test_http_client_ssl
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test_libcurl_abs_url
|
||||||
|
do
|
||||||
|
test_abs_url
|
||||||
|
end
|
||||||
|
|
||||||
test_libcurl_headers
|
test_libcurl_headers
|
||||||
do
|
do
|
||||||
test_headers
|
test_headers
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ feature -- Tests
|
|||||||
test_http_client_ssl
|
test_http_client_ssl
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test_net_abs_url
|
||||||
|
do
|
||||||
|
test_abs_url
|
||||||
|
end
|
||||||
|
|
||||||
test_net_headers
|
test_net_headers
|
||||||
do
|
do
|
||||||
test_headers
|
test_headers
|
||||||
|
|||||||
Reference in New Issue
Block a user