Fork me on GitHub
Leonid Korogodski17:05:17

Hey, everyone. I have a reverse proxy that currently uses http-kit, but I want to replace it with aleph because I want to be able to stream large files through the proxy, and http-kit insists on buffering the entire response before sending it back. However, I'm getting the following error:

2021-05-19T10:52:10,976 [aleph-netty-server-event-pool-5] ERROR aleph.http.core - error sending body of type  clojure.lang.PersistentArrayMap 
java.lang.IllegalArgumentException: Don't know how to convert class clojure.lang.PersistentArrayMap into (stream-of io.netty.buffer.ByteBuf)
	at byte_streams$convert.invokeStatic(byte_streams.clj:196)
	at byte_streams$convert.invoke(byte_streams.clj:162)
	at aleph.netty$to_byte_buf_stream.invokeStatic(netty.clj:203)
	at aleph.netty$to_byte_buf_stream.invoke(netty.clj:202)
	at aleph.http.core$send_streaming_body.invokeStatic(core.clj:318)
	at aleph.http.core$send_streaming_body.invoke(core.clj:273)
	at aleph.http.core$eval10167$send_message__10174$fn__10175.invoke(core.clj:535)
	at aleph.http.core$eval10167$send_message__10174.invoke(core.clj:534)
	at aleph.http.server$eval10262$send_response__10267$f__9568__auto____10273.invoke(server.clj:140)
	at aleph.http.server$eval10262$send_response__10267$fn__10275.invoke(server.clj:129)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(
	at io.netty.util.concurrent.SingleThreadEventExecutor$
	at io.netty.util.internal.ThreadExecutorMap$
	at manifold.executor$thread_factory$reify__4367$f__4368.invoke(executor.clj:47)
	at java.base/
The code in question is simple:
(http/request {:url          (create-url api request)
               :method       request-method
               :query-params query-params
               :headers      (create-headers request api)
               :body         body
               :as           :stream})
In this particular case, the method is GET, the body is nil, and there are no query params.


what are create-url and create-headers?


i'm suspecting you're accidentally passing a map as a parameter that aleph expects to be a (netty) bytebuf


which is probably body by the way

Leonid Korogodski17:05:44

Using 0.4.7-alpha7.


looks like that isn't from the request code you shared, but looks like you are trying to return the result of the request as an http response, and the error is from there

Leonid Korogodski18:05:09

Yes, of course. It's a reverse proxy.

Leonid Korogodski18:05:52

But why the error?


whatever request returns isn't something that aleph knows how to serve as an http response


if I had to guess (which I kind of do, because I don't really use aleph ever), request returns a deferred that yields a map, and aleph expects a deferred to just yield bytes to serve

Leonid Korogodski18:05:20

Yes. Strange that aleph wouldn't handle that.