您如何访问 Kemal after_all 方法中路由的 return 值?
How do you access the return value of the route in Kemal after_all method?
如何从 Kemal 文件中的 after_all 处理程序修改路由的响应?
[见下面的例子]
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
文档中没有任何 after_all 路由的示例,我似乎无法在包含它的上下文中找到任何对象。我该怎么做?
你不能那样做。路由处理程序的 return 值立即发送到底层套接字。基本上没有办法检索或更改它。
相反,您应该考虑直接在显式代码中实现您想要的内容。不适用于此的 Kemal 处理程序。您应该只将它们用于与 HTTP 协议相关的任务。
如何从 Kemal 文件中的 after_all 处理程序修改路由的响应? [见下面的例子]
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
文档中没有任何 after_all 路由的示例,我似乎无法在包含它的上下文中找到任何对象。我该怎么做?
你不能那样做。路由处理程序的 return 值立即发送到底层套接字。基本上没有办法检索或更改它。
相反,您应该考虑直接在显式代码中实现您想要的内容。不适用于此的 Kemal 处理程序。您应该只将它们用于与 HTTP 协议相关的任务。