Skip to content

Commit bf2c7c9

Browse files
dancekbbatsov
authored andcommitted
Support additional HTTP headers from nREPL config
1 parent 3c8b5c7 commit bf2c7c9

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

README.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ implementations to the `nrepl.core/url-connect` multimethod for
125125
tool that uses `url-connect` will use `ring-client-transport` for
126126
connecting to HTTP and HTTPS nREPL endpoints.
127127

128+
==== Configuration
129+
130+
The client supports additional HTTP headers, which is useful e.g. for
131+
using Bearer authorization to connect to the endpoint. The headers can
132+
be set in the nREPL configuration. For example, create `.nrepl.edn` in
133+
the working directory with the contents:
134+
135+
[source,clojure]
136+
----
137+
{:drawbridge {:http-headers {:Authorization "Bearer <JWT token>"}}}
138+
----
139+
128140
== TODO
129141

130142
The biggest outstanding issues are around the semantics of how HTTP

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject nrepl/drawbridge "0.2.0"
1+
(defproject nrepl/drawbridge "0.2.1"
22
:description "HTTP transport support for Clojure's nREPL implemented as a Ring handler."
33
:url "http://github.com/nrepl/drawbridge"
44
:license {:name "Eclipse Public License"

src/drawbridge/client.clj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
[cheshire.core :as json]
44
[clojure.java.io :as io]
55
[clj-http.client :as http]
6+
[nrepl.config]
67
[nrepl.core :as nrepl]
78
[nrepl.transport :as transport])
89
(:import
910
(java.util.concurrent LinkedBlockingQueue TimeUnit)))
1011

12+
(def ^:private http-headers (get-in nrepl.config/config [:drawbridge :http-headers]))
13+
1114
(defn ring-client-transport
1215
"Returns an nREPL client-side transport to connect to HTTP nREPL
1316
endpoints implemented by `ring-handler`.
@@ -33,7 +36,8 @@
3336
url
3437
(merge {:as :stream
3538
:cookies @session-cookies}
36-
(when msg {:form-params msg})))]
39+
(when msg {:form-params msg})
40+
(when http-headers {:headers http-headers})))]
3741
(swap! session-cookies merge cookies)
3842
(fill body)))]
3943
(transport/->FnTransport

0 commit comments

Comments
 (0)