Fork me on GitHub
#aleph
<
2019-07-17
>
alexyakushev06:07:21

@geraldodev content-type-response is a standard Ring middleware that accepts a handler request -> response and returns an updated handler request -> response. Response in assumed to be a steady here-and-now value, so the middleware can access it and modify at will. Aleph, however, allows the handler to return not only response, but also (deferred response). Ring middleware out-of-the-box doesn't know what to do with deferreds, that it has to chain callbacks onto them rather than call functions directly. So, this defer function transforms a regular Ring middleware into deferred-aware middleware.

👍 4
alexyakushev06:07:19

Answering your exact question, (handler req) can be invoked directly because req cannot be a deferred, it's always a concrete value.

dimovich06:07:13

@geraldodev The request comes in as a Netty request, while the response is a Deferred, so that's why we're chaining only the response, to be able to access its content.

dimovich07:07:48

@alexyakushev wonder if its possible to use Ring's async handler arity to chain the deferred callbacks, instead of changing the middleware handlers.

👍 4
alexyakushev11:07:19

I never tried Ring async arity, so I'm not sure how complete and usable it is.

alexyakushev11:07:32

@dimovich The request actually comes as a Ring request, it is transformed from Netty request to Ring request inside Aleph.

alexyakushev11:07:40

Or you can say it's a NettyRequest implementation-wise, but for the purposes of using Ring it's a valid up-to-spec Ring request.