Fork me on GitHub
#pedestal
<
2017-11-10
>
bill20:11:34

I’m using a body-params interceptor to populate the request’s :json-params. ✓ (I’m a noob) What if I want to get at the request’s :body as a String? I see the :body isa HttpInputOverHTTP: https://www.eclipse.org/jetty/javadoc/current/org/eclipse/jetty/server/HttpInputOverHTTP.html But I don’t know out to get a String or a Reader out of that thing. Rather than digging directly into the Java stuff, I wondered if there was some interceptor or helper type fn to do that… (I realize that in general, I may be dealing with a MIME multi-part request and oy I just don’t want that complication, but I do, nevertheless need the content of the first part, as a String)

bill21:11:43

I’ve seen the “echo” handler but it punts on the issue: http://pedestal.io/guides/your-first-api

bill21:11:07

hmm HttpInputOverHTTP isa InputStream

kenny23:11:24

I have a route that looks like this:

["/subscribe" :get [(http-sse/start-event-stream stream-ready)] :route-name :subscribe]
where stream-ready is defined like this:
(require '[clojure.core.async :as async])
(require '[io.pedestal.http.sse :as sse])

(defn stream-ready
  [event-chan ctx]
  (async/go-loop []
    (async/<! (async/timeout 1000))
    (sse/send-event event-chan "example" "test")
    (recur)))
In the browser I created an EventSource object and set the onmessage handler to just print out the event result. I get a new event message once per second. The event data looks something like this "[B@100394d9", however. That looks a whole lot like how Clojure prints out Byte arrays. I'm wondering if Pedestal is incorrectly serializing SSE messages. These are the Pedestal dependencies that I have:
[io.pedestal/pedestal.service "0.5.3"]
[io.pedestal/pedestal.route "0.5.3"]
[io.pedestal/pedestal.jetty "0.5.3"]