是否不鼓励自定义 Rack 环境变量?

发布于 2024-12-21 14:52:54 字数 221 浏览 3 评论 0原文

我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒浓于脸红 2024-12-28 14:52:54

我不知道对此事有任何“官方”意见。如果我是你,我会采用几个流行的 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.

一抹苦笑 2024-12-28 14:52:54

不鼓励自定义机架环境。

这在机架规范中进行了讨论:http://rack.rubyforge.org/doc/SPEC.html如下:

服务器或应用程序也可以在环境中存储自己的数据。键必须至少包含一个点,并且应具有唯一的前缀。前缀架。保留用于机架核心发行版和其他可接受的规范,不得以其他方式使用。环境不得包含键 HTTP_CONTENT_TYPE 或 HTTP_CONTENT_LENGTH(使用不带 HTTP_ 的版本)。 CGI 键(命名时不带句点)必须具有字符串值。有以下限制。 。 .

Custom Rack environments are NOT discouraged.

This is discussed in the Rack Spec: http://rack.rubyforge.org/doc/SPEC.html as follows:

The server or the application can store their own data in the environment, too. The keys must contain at least one dot, and should be prefixed uniquely. The prefix rack. is reserved for use with the Rack core distribution and other accepted specifications and must not be used otherwise. The environment must not contain the keys HTTP_CONTENT_TYPE or HTTP_CONTENT_LENGTH (use the versions without HTTP_). The CGI keys (named without a period) must have String values. There are the following restrictions . . .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文