是否不鼓励自定义 Rack 环境变量?
我想在 Rack 环境中存储一些值,以避免在每个中间件中重新计算值。是否不鼓励设置自己的 Rack 环境变量? 示例:
- SERVER_NAME
- SERVER_PORTrack.errors
- my_namespace.my_key
- my_namespace.second_key
- ]
- [等
I would like to store some values in the Rack environment to avoid re-calculating the values in every middleware. Is it discouraged to set your own Rack environment variables?
Examples:
- SERVER_NAME
- SERVER_PORT
- rack.errors
- my_namespace.my_key
- my_namespace.second_key
- [etc.]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道对此事有任何“官方”意见。如果我是你,我会采用几个流行的 Rack 模块,查看它们的代码并尝试从中推断出“最佳实践”。
不管怎样,归根结底,唯一重要的是你的软件是否做了它应该做的事情并且做得很好。其余的都无关紧要。
I am not aware of any 'official' opinion on this matter. If I were you, I would take a couple of popular Rack modules, look at their code and try to infer 'best practices' from there.
Anyway, in the end of the day the only thing that matters is if your software does what it should and does it well. The rest is irrelevant.
不鼓励自定义机架环境。
这在机架规范中进行了讨论:http://rack.rubyforge.org/doc/SPEC.html如下:
Custom Rack environments are NOT discouraged.
This is discussed in the Rack Spec: http://rack.rubyforge.org/doc/SPEC.html as follows: