Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/elastix/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ defmodule Elastix.HTTP do
@type resp :: {:ok, HTTPoison.Response.t()} | {:error, HTTPoison.Error.t()}

@doc false
def prepare_url(url, path) when is_binary(path), do: URI.merge(url, path) |> to_string
def prepare_url(url, parts) when is_list(parts), do: prepare_url(url, Path.join(parts))
def prepare_url(url, path) when is_binary(path) do
"#{url}/"
|> URI.merge(String.trim_leading(path, "/"))
|> to_string
end

def prepare_url(url, parts) when is_list(parts),
do: prepare_url("#{url}/", Path.join(parts))

@doc false
def request(method, url, body \\ "", headers \\ [], options \\ []) do
Expand Down
6 changes: 2 additions & 4 deletions lib/elastix/search.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@ defmodule Elastix.Search do

@doc false
def make_path(index, types, query_params, api_type \\ "_search") do
path_root = "/#{index}"

path =
case types do
[] -> path_root
_ -> path_root <> "/" <> Enum.join(types, ",")
[] -> index
_ -> index <> "/" <> Enum.join(types, ",")
end

full_path = "#{path}/#{api_type}"
Expand Down
9 changes: 9 additions & 0 deletions test/elastix/http_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@

@test_url Elastix.config(:test_url)

test "prepare_url/2 should concat url with path" do

Check failure on line 7 in test/elastix/http_test.exs

View workflow job for this annotation

GitHub Actions / Ex1.18.2/OTP27.2.4

test prepare_url/2 should concat url with path (Elastix.HTTPTest)

Check failure on line 7 in test/elastix/http_test.exs

View workflow job for this annotation

GitHub Actions / Ex1.18.2/OTP26.2.5

test prepare_url/2 should concat url with path (Elastix.HTTPTest)

Check failure on line 7 in test/elastix/http_test.exs

View workflow job for this annotation

GitHub Actions / Ex1.17.3/OTP27.2.4

test prepare_url/2 should concat url with path (Elastix.HTTPTest)

Check failure on line 7 in test/elastix/http_test.exs

View workflow job for this annotation

GitHub Actions / Ex1.18.2/OTP25.3.2

test prepare_url/2 should concat url with path (Elastix.HTTPTest)
assert HTTP.prepare_url("http://127.0.0.1:9200/", "/some_path") ==
"http://127.0.0.1:9200/some_path"

assert HTTP.prepare_url("http://127.0.0.1:9200/base_path", "/some_path") ==
"http://127.0.0.1:9200/base_path/some_path"

assert HTTP.prepare_url("http://127.0.0.1:9200/base_path", "some_path") ==
"http://127.0.0.1:9200/base_path/some_path"

assert HTTP.prepare_url("http://127.0.0.1:9200/base_path/", "/some_path") ==
"http://127.0.0.1:9200/base_path/some_path"
end

test "prepare_url/2 should concat url with a list of path parts" do

Check failure on line 21 in test/elastix/http_test.exs

View workflow job for this annotation

GitHub Actions / Ex1.18.2/OTP27.2.4

test prepare_url/2 should concat url with a list of path parts (Elastix.HTTPTest)

Check failure on line 21 in test/elastix/http_test.exs

View workflow job for this annotation

GitHub Actions / Ex1.18.2/OTP26.2.5

test prepare_url/2 should concat url with a list of path parts (Elastix.HTTPTest)

Check failure on line 21 in test/elastix/http_test.exs

View workflow job for this annotation

GitHub Actions / Ex1.17.3/OTP27.2.4

test prepare_url/2 should concat url with a list of path parts (Elastix.HTTPTest)

Check failure on line 21 in test/elastix/http_test.exs

View workflow job for this annotation

GitHub Actions / Ex1.18.2/OTP25.3.2

test prepare_url/2 should concat url with a list of path parts (Elastix.HTTPTest)
assert HTTP.prepare_url("http://127.0.0.1:9200/", ["/some/", "/path/"]) ==
"http://127.0.0.1:9200/some/path"
end
Expand Down
Loading