您如何在Kemal after_all方法中访问路线的返回值?

问题描述 投票:1回答:1

从凯末尔文件中的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路由的任何示例,而且我似乎在包含它的上下文中找不到任何对象。我该怎么办?

crystal-lang kemal
1个回答
0
投票

您不能那样做。路由处理程序的返回值会立即发送到基础套接字。基本上没有办法检索或更改它。

相反,您应该考虑直接在显式代码中实现所需的内容。凯末尔处理程序不适合这样做。您只应将它们用于与HTTP协议相关的任务。

© www.soinside.com 2019 - 2024. All rights reserved.