Skip to content

Commit

Permalink
Use correct HTTP method for new page endpoint andrewvy#38
Browse files Browse the repository at this point in the history
  • Loading branch information
aus70 committed Apr 11, 2024
1 parent bfefcc8 commit 79324d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions lib/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ defmodule ChromeRemoteInterface.HTTP do
@type success_http_response :: {:ok, Map.t()}
@type error_http_response :: {:error, any()}

@spec call(ChromeRemoteInterface.Server.t(), String.t()) ::
@spec call(ChromeRemoteInterface.Server.t(), String.t(), method: :get | :put) ::
success_http_response | error_http_response
def call(server, path) do
def call(server, path, opts \\ []) do
method = Keyword.get(opts, :method, :get)

server
|> execute_request(path)
|> execute_request(method, path)
|> handle_response()
end

Expand All @@ -22,8 +24,8 @@ defmodule ChromeRemoteInterface.HTTP do
"http://#{server.host}:#{server.port}#{path}"
end

defp execute_request(server, path) do
:hackney.request(:get, http_url(server, path), [], <<>>, path_encode_fun: & &1)
defp execute_request(server, method, path) when method in [:get, :put] do
:hackney.request(method, http_url(server, path), [], <<>>, path_encode_fun: & &1)
end

defp handle_response({:ok, status_code, _response_headers, client_ref}) do
Expand Down
2 changes: 1 addition & 1 deletion lib/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ defmodule ChromeRemoteInterface.Session do
@spec new_page(Server.t()) :: HTTP.success_http_response() | HTTP.error_http_response()
def new_page(server) do
server
|> HTTP.call("/json/new")
|> HTTP.call("/json/new", method: :put)
end

@doc """
Expand Down

0 comments on commit 79324d4

Please sign in to comment.