Fork me on GitHub

@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

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


@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.


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

👍 4

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


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


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.