Skip to content

Commit

Permalink
Support additional HTTP headers from nREPL config
Browse files Browse the repository at this point in the history
  • Loading branch information
dancek authored and bbatsov committed Aug 15, 2019
1 parent 3c8b5c7 commit bf2c7c9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ implementations to the `nrepl.core/url-connect` multimethod for
tool that uses `url-connect` will use `ring-client-transport` for
connecting to HTTP and HTTPS nREPL endpoints.

==== Configuration

The client supports additional HTTP headers, which is useful e.g. for
using Bearer authorization to connect to the endpoint. The headers can
be set in the nREPL configuration. For example, create `.nrepl.edn` in
the working directory with the contents:

[source,clojure]
----
{:drawbridge {:http-headers {:Authorization "Bearer <JWT token>"}}}
----

== TODO

The biggest outstanding issues are around the semantics of how HTTP
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject nrepl/drawbridge "0.2.0"
(defproject nrepl/drawbridge "0.2.1"
:description "HTTP transport support for Clojure's nREPL implemented as a Ring handler."
:url "http://github.com/nrepl/drawbridge"
:license {:name "Eclipse Public License"
Expand Down
6 changes: 5 additions & 1 deletion src/drawbridge/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
[cheshire.core :as json]
[clojure.java.io :as io]
[clj-http.client :as http]
[nrepl.config]
[nrepl.core :as nrepl]
[nrepl.transport :as transport])
(:import
(java.util.concurrent LinkedBlockingQueue TimeUnit)))

(def ^:private http-headers (get-in nrepl.config/config [:drawbridge :http-headers]))

(defn ring-client-transport
"Returns an nREPL client-side transport to connect to HTTP nREPL
endpoints implemented by `ring-handler`.
Expand All @@ -33,7 +36,8 @@
url
(merge {:as :stream
:cookies @session-cookies}
(when msg {:form-params msg})))]
(when msg {:form-params msg})
(when http-headers {:headers http-headers})))]
(swap! session-cookies merge cookies)
(fill body)))]
(transport/->FnTransport
Expand Down

0 comments on commit bf2c7c9

Please sign in to comment.