Reputation: 1081
From the after_all handler in a Kemal file, how do I modify the response from the route? [See example below]
VERSION = "0.1.0"
require "kemal"
# Configure kemal parameters
serve_static false
get "/" do
"Hello world!"
end
after_all do |env|
# Would like to inject something here that turns "Hello world!" into "HELLO WORLD!",
# but I'm not sure how to get the original ("Hello world!") in this scope.
end
Kemal.run
The documentation doesn't have any examples of after_all routes, and I can't seem to find any object in the context that contains it. How would I do this?
Upvotes: 1
Views: 81
Reputation: 5661
You can't do that. The route handler's return value is immediately sent to the underlying socket. There's basically no way to retrieve or change it.
Instead, you should consider implementing what you want directly in explicit code. Kemal handlers that are not meant for this. You should only use them for tasks related to HTTP protocol.
Upvotes: 1