Skip to content

Commit

Permalink
Improved support for absolute url passed tp HTTP_REQUEST_SESSION .
Browse files Browse the repository at this point in the history
  • Loading branch information
jocelyn committed Oct 27, 2017
1 parent 503e5f7 commit f770c23
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 4 deletions.
6 changes: 3 additions & 3 deletions library/network/http_client/src/http_client_request.e
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 29 additions & 1 deletion library/network/http_client/src/http_client_session.e
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ note
deferred class
HTTP_CLIENT_REQUEST_PARAMETER

inherit
DEBUG_OUTPUT

feature -- Access

name: READABLE_STRING_32
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions library/network/http_client/tests/test_http_client_i.e
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions library/network/http_client/tests/test_libcurl_http_client.e
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions library/network/http_client/tests/test_net_http_client.e
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f770c23

Please sign in to comment.