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
6 changes: 3 additions & 3 deletions core/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
:pack {:extra-deps {pack/pack.alpha {:git/url "https://github.com/juxt/pack.alpha.git"
:sha "c70740ffc10805f34836da2160fa1899601fac02"}}
:main-opts ["-m" "mach.pack.alpha.skinny" "--no-libs" "--project-path" "dist/json-rpc.core.jar"]}
:deploy {:extra-deps {deps-deploy {:mvn/version "RELEASE"}}
:deploy {:extra-deps {deps-deploy/deps-deploy {:mvn/version "RELEASE"}}
:main-opts ["-m" "deps-deploy.deps-deploy" "deploy"
"dist/json-rpc.core.jar"]}}
:deps {camel-snake-kebab {:mvn/version "0.4.1"}
clj-http {:mvn/version "3.10.1"}
:deps {camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.1"}
clj-http/clj-http {:mvn/version "3.10.1"}
com.github.jnr/jnr-unixsocket {:mvn/version "0.30"}
org.clojure/clojure {:mvn/version "1.10.1"}
org.clojure/core.async {:mvn/version "1.1.587"}
Expand Down
2 changes: 1 addition & 1 deletion core/src/json_rpc/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

(defprotocol Client
"A JSON-RPC client."
(open [this url] "Opens a connection to the given URL")
(open [this url headers] "Opens a connection to the given URL")
(send [this conneciton message] "Sends a JSON-RPC request to the open connection")
(close [this conneciton] "Closes the connection"))
4 changes: 2 additions & 2 deletions core/src/json_rpc/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
(close-fn)))

(defn open
[url & {route-fn :route-fn}]
[url & {route-fn :route-fn headers :headers}]
(let [route-fn (or route-fn route)
client (route-fn url)
channel (client/open client url)]
channel (client/open client url headers)]
(log/debugf "url => %s" url)
(map->Channel {:send-fn (partial client/send client channel)
:close-fn #(client/close client channel)})))
Expand Down
12 changes: 7 additions & 5 deletions core/src/json_rpc/http.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
(defrecord CljHttpClient [options]
client/Client

(open [this url]
{:url url})
(open [this url headers]
{:url url
:headers headers})

(send [this {url :url} message]
(->> {:body message}
(merge options)
(send [this {url :url headers :headers} message]
(->> (-> options
(update :headers merge headers)
(assoc :body message))
(http/post url)
:body))

Expand Down
2 changes: 1 addition & 1 deletion core/src/json_rpc/unix.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(defrecord UnixSocketClient []
client/Client

(open [this path]
(open [this path _headers]
(-> path
(io/file)
(UnixSocketAddress.)
Expand Down
6 changes: 3 additions & 3 deletions core/src/json_rpc/ws.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

(defrecord GniazdoClient []
client/Client
(open [this url]

(open [this url headers]
(let [source (async/chan)
socket (ws/connect url :on-receive #(>!! source %))]
socket (ws/connect url :on-receive #(>!! source %) :headers headers)]
{:socket socket
:source source}))

Expand Down
2 changes: 1 addition & 1 deletion core/test/json_rpc/http_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
(testing "POST requests"
(doseq [url ["http://postman-echo.com/post"
"https://postman-echo.com/post"]]
(let [channel (client/open clj-http url)]
(let [channel (client/open clj-http url {})]
(try
(let [request {:jsonrpc "2.0"
:method "eth_blockNumber"
Expand Down
2 changes: 1 addition & 1 deletion core/test/json_rpc/ws_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(deftest ^:integration gniazdo-test
(testing "with echo response"
(doseq [url ["ws://echo.websocket.org"]]
(let [channel (client/open gniazdo url)]
(let [channel (client/open gniazdo url {})]
(try
(let [request {:jsonrpc "2.0"
:method "eth_blockNumber"
Expand Down