Bukdu.jl icon indicating copy to clipboard operation
Bukdu.jl copied to clipboard

post processing

Open anj00 opened this issue 6 years ago • 2 comments

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

anj00 avatar May 18 '19 13:05 anj00

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

wookay avatar May 18 '19 14:05 wookay

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.

anj00 avatar May 18 '19 19:05 anj00