Skip to content

Commit 79324d4

Browse files
committed
Use correct HTTP method for new page endpoint andrewvy#38
1 parent bfefcc8 commit 79324d4

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lib/http.ex

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ defmodule ChromeRemoteInterface.HTTP do
66
@type success_http_response :: {:ok, Map.t()}
77
@type error_http_response :: {:error, any()}
88

9-
@spec call(ChromeRemoteInterface.Server.t(), String.t()) ::
9+
@spec call(ChromeRemoteInterface.Server.t(), String.t(), method: :get | :put) ::
1010
success_http_response | error_http_response
11-
def call(server, path) do
11+
def call(server, path, opts \\ []) do
12+
method = Keyword.get(opts, :method, :get)
13+
1214
server
13-
|> execute_request(path)
15+
|> execute_request(method, path)
1416
|> handle_response()
1517
end
1618

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

25-
defp execute_request(server, path) do
26-
:hackney.request(:get, http_url(server, path), [], <<>>, path_encode_fun: & &1)
27+
defp execute_request(server, method, path) when method in [:get, :put] do
28+
:hackney.request(method, http_url(server, path), [], <<>>, path_encode_fun: & &1)
2729
end
2830

2931
defp handle_response({:ok, status_code, _response_headers, client_ref}) do

lib/session.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ defmodule ChromeRemoteInterface.Session do
4545
@spec new_page(Server.t()) :: HTTP.success_http_response() | HTTP.error_http_response()
4646
def new_page(server) do
4747
server
48-
|> HTTP.call("/json/new")
48+
|> HTTP.call("/json/new", method: :put)
4949
end
5050

5151
@doc """

0 commit comments

Comments
 (0)