wookay/Bukdu.jl

post processing

anj00 opened this issue · 2 comments

anj00 commented

hello,
As I understand using pipeline one can setup preprocessing
https://github.com/wookay/Bukdu.jl/blob/master/examples/cors/ex2.jl

Is there a way to setup postprocessing? i.e. some action which can be called AFTER processing function returned (in the ex2.jl case that would be once function index(c::RESTController) returned. and say if postprocessor would add an extra header if value of output is 42 and different header if it is not 42)

In my server flow I realized I need to do same action not only on every function's input but the output as well. would be great to be able to setup it in one place, just like preprocessing is done using pipeline

it might be needed such as register_before_send in phoenix framework to support the post processing.
https://hexdocs.pm/plug/Plug.Conn.html#register_before_send/2

for a tricky, there's Bukdu.System.catch_response
https://wookay.github.io/docs/Bukdu.jl/System/#Bukdu.System.catch_response

function Bukdu.System.catch_response(route::Bukdu.Route, resp)
    if route.C === RESTController && route.action === index && resp.body == Vector{UInt8}("42")
        setheader(resp, "Extra" => "Header")
    end
end
anj00 commented

Thank you very much @wookay ! Totally solves my problem.

I guess the trick is that catch_response is mentioned in the debug section. yet it is perfectly usable as a post processor as well. I missed that.