Skip to content

Commit 8fc4596

Browse files
committed
Show location and size instead of unrecognized binary content
1 parent f32a08c commit 8fc4596

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/cider/nrepl/middleware/slurp.clj

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,23 @@
7575
(if-class java.util.Base64
7676
(.encodeToString (Base64/getEncoder) buff)))
7777

78-
(defn slurp-reply [content-type buff]
78+
(defn slurp-reply [location content-type buff]
7979
(let [^String real-type (first content-type)
80+
binary? (= "application/octet-stream" real-type)
8081
text? (.contains real-type "text")]
81-
(if-not text?
82+
(cond
83+
binary?
8284
{:content-type content-type
83-
:content-transfer-encoding "base64"
84-
:body (base64-bytes buff)}
85+
:body (str "#binary[location=" location ",size=" (count buff) "]")}
86+
87+
text?
88+
{:content-type content-type
89+
:body (String. buff "utf-8")}
90+
91+
:default
8592
{:content-type content-type
86-
:body (String. buff "utf-8")})))
93+
:content-transfer-encoding "base64"
94+
:body (base64-bytes buff)})))
8795

8896
(defn slurp-url-to-content+body
8997
"Attempts to parse and then to slurp a URL, producing a content-typed response."
@@ -92,10 +100,9 @@
92100
(catch MalformedURLException e nil))]
93101
(if (= (.getProtocol url) "file") ;; expected common case
94102
(let [^Path p (Paths/get (.toURI url))
95-
content-type (normalize-content-type
96-
(get-file-content-type p))
103+
content-type (normalize-content-type (get-file-content-type p))
97104
buff (Files/readAllBytes p)]
98-
(slurp-reply content-type buff))
105+
(slurp-reply p content-type buff))
99106

100107
;; It's not a file, so just try to open it on up
101108
(let [conn (.openConnection url)
@@ -110,7 +117,7 @@
110117
(when (<= 0 b)
111118
(.write os b)
112119
(recur))))
113-
(slurp-reply content-type (.toByteArray os))))))
120+
(slurp-reply url content-type (.toByteArray os))))))
114121

115122
;; FIXME (arrdem 2018-04-11):
116123
;; Remove this if-class when we have jdk1.8 min

0 commit comments

Comments
 (0)