crystal-lang - 如何在 Kemal after_all 方法中访问路由的返回值?
问题描述
从 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 路由的示例,而且我似乎无法在包含它的上下文中找到任何对象。我该怎么做?
解决方案
你不能那样做。路由处理程序的返回值立即发送到底层套接字。基本上没有办法检索或更改它。
相反,您应该考虑直接在显式代码中实现您想要的。Kemal 处理程序不是为此而设计的。您应该只将它们用于与 HTTP 协议相关的任务。
推荐阅读
- java - Java并发:可重置启用/禁用等待条件
- javascript - 我收到 SyntaxError:WordPress 主题中的解析器错误
- r - spatstat 不均匀 K-、F- 和 G- 函数中的意外行为
- python - 如何用特定键而不是键盘中断异常停止无限循环?
- javascript - 使用本地存储查找返回用户的特定用户名
- javascript - 在 datepicker 中选择日期后,在我的年龄字段中获取 NaN
- angular - 模板解析错误:意外字符“EOF”
- python - Cesium - ImportError:无法导入名称重新提升
- php - 在命令窗口中为 Aria 项目使用 curl 我得到了我想要的但在 PHP 文件中它返回空字符串
- amazon-web-services - 如果我将弹性 IP 关联到我正在运行的 EC2 实例,它是否会丢弃其当前的公共 IP?