Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post processing #62

Open
anj00 opened this issue May 18, 2019 · 2 comments
Open

post processing #62

anj00 opened this issue May 18, 2019 · 2 comments

Comments

@anj00
Copy link

anj00 commented May 18, 2019

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

@wookay
Copy link
Owner

wookay commented May 18, 2019

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
Copy link
Author

anj00 commented May 18, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants