Skip to content

Commit 854e1e2

Browse files
plexusbbatsov
authored andcommitted
CHANGELOG and doc updates for content-type
Further document the content-type middleware.
1 parent c820901 commit 854e1e2

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master (unreleased)
44

5+
### New features
6+
7+
* [#548](https://github.com/clojure-emacs/cider-nrepl/pull/548): Make the content-type middleware extensible via multimethod
8+
59
## 0.27.4 (2021-12-15)
610

711
### Bugs fixed

doc/modules/ROOT/pages/nrepl-api/ops.adoc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ Returns::
158158

159159
=== `content-type-middleware`
160160

161-
Enhances the ``eval`` op by adding ``content-type`` and friends to some responses. Not an op in itself.
161+
Enhances the ``eval`` op by adding ``content-type`` and ``body`` to certain ``eval`` responses. Not an op in itself.
162+
163+
Depending on the type of the return value of the evaluation this middleware may kick in and include a representation of the result in the response, together with a MIME/Media type to indicate how it should be handled by the client. Comes with implementations for ``URI``, ``URL``, ``File``, and ``java.awt.Image``. More type handlers can be provided by the user by extending the ``cider.nrepl.middleware.content-type/content-type-response`` multimethod. This dispatches using ``clojure.core/type``, so ``:type`` metadata on plain Clojure values can be used to provide custom handling.
162164

163165
Required parameters::
164166
{blank}
@@ -168,7 +170,9 @@ Optional parameters::
168170

169171

170172
Returns::
171-
{blank}
173+
* `:body` The rich response document, if applicable.
174+
* `:content-type` The Media type (MIME type) of the reponse, structured as a pair, `[type {:as attrs}]`
175+
* `:content-transfer-encoding` The encoding of the response body (Optional, currently only one possible value `"base64"`)
172176

173177

174178
=== `debug-input`

doc/modules/ROOT/pages/nrepl-api/supplied_middleware.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
| `complete`
2828
| Code completion.
2929

30+
| `wrap-content-type`
31+
| -
32+
| No
33+
| `eval`
34+
| Rich content handling, return multimedia results beyond plain text from `eval`.
35+
3036
| `wrap-debug`
3137
| -
3238
| No

src/cider/nrepl/middleware/content_type.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
(defmethod content-type-response java.awt.Image [{^java.awt.Image image :value :as response}]
113113
(with-open [bos (ByteArrayOutputStream.)]
114114
(ImageIO/write image "png" ^OutputStream bos)
115-
(merge response (when (ImageIO/write ^RenderedImage value "png" ^OutputStream bos)
115+
(merge response (when (ImageIO/write ^RenderedImage image "png" ^OutputStream bos)
116116
(slurp-reply "" ["image/png" {}] (.toByteArray bos))))))
117117

118118
(defn content-type-transport
@@ -126,7 +126,7 @@
126126
(recv [_this timeout]
127127
(.recv transport timeout))
128128

129-
(send [this response]
129+
(send [_this response]
130130
(.send transport (content-type-response response)))))
131131

132132
(defn handle-content-type

0 commit comments

Comments
 (0)