aleph

alexyakushev 2019-07-17T06:38:21.053Z

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

👍 1
alexyakushev 2019-07-17T06:40:19.053800Z

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

2019-07-17T06:59:13.054Z

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

2019-07-17T07:00:48.055Z

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

👍 1
alexyakushev 2019-07-17T11:05:19.055600Z

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

alexyakushev 2019-07-17T11:06:32.056400Z

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

alexyakushev 2019-07-17T11:07:40.057100Z

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.