是否可以修改与 HTTP 状态代码一起发送的文本?

发布于 2024-12-15 06:11:51 字数 327 浏览 2 评论 0原文

我正在我的网站上实施“测试模式”,该模式将禁止访问正在构建的某些页面,使它们只能由管理员访问以进行私人测试。我计划使用 401 状态代码,因为该页面确实存在,但不允许他们使用它,并且他们可能会或可能不会通过身份验证,但只有某些用户(基本上是我)仍然会被允许访问该页面。

我想知道的是 HTTP/1.1 401 部分后面的文本是否重要?它是否必须是未经授权的,或者基本上可以是您想在其后面添加的任何内容,只要 401 仍然适合该错误?我想发送一条消息,例如暂时不可用,以表明该页面通常对所有访问者可用,但正在进行重建,暂时不可用。我应该这样做还是不这样做?

I'm implementing a 'testing mode' with my website which will forbid access to certain pages while they are undergoing construction, making them only accessible to administrators for private testing. I was planning on using the 401 status code, since the page does exist but they are not allowed to use it, and they may or may not be authenticated, yet only certain users (basically me) would still be allowed to access the page.

The thing I'm wondering is if the text after the HTTP/1.1 401 part mattered? Does it have to be Unauthorized or can it basically be whatever you want to put after it, so long as the 401 is still appropriate for the error? I wanted to send a message such as Temporarily Unavailable to indicate that the page is normally available to all visitors, but is undergoing reconstruction and is temporarily unavailable. Should I do this or not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

瑾夏年华 2024-12-22 06:11:51

你可以改变它们。

状态消息(技术上称为“原因短语”)只是建议,并且“可以在不影响协议的情况下进行更改”。

请参阅http://www.w3.org/Protocols/rfc2616/ rfc2616-sec6.html#sec6.1.1

但是,您应该:-)仍然正确使用代码并给出有意义的消息。仅当您的情况符合 RFC 规定的 401 规定时才使用 401。

You may change them.

The status messages (technically called "reason phrases") are only recommendations and "MAY be changed without affecting the protocol)."

See http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1.1

However, you SHOULD :-) still use the codes properly and give meaningful messages. Only use a 401 if your condition is what the RFC says a 401 should be.

抠脚大汉 2024-12-22 06:11:51

是的,原因短语可以更改。它不会影响消息的含义。

但如果需要说“暂时不可用”,则需要将其设为5xx(服务器)代码。 503 似乎就在这里(参见 RFC 2616,第 10.5.4 节)。

Yes, the reason phrase can be changed. It doesn't affect the meaning of the message.

But if you need to say "temporarily unavailable", you need to make it 5xx (server) code. 503 seems right here (see RFC 2616, Section 10.5.4).

疑心病 2024-12-22 06:11:51

您可以更改文本(很少有 http 客户端会注意到它),但最好使用最适用的响应代码。毕竟,指示失败的原因是各种响应代码的用途。

也许这适合:

404 Not Found 无法找到所请求的资源,但可能是
将来再次可用。[2]客户的后续请求
是允许的。

You MAY change the text (very few http clients pay any attention to it), but it is better to use the most applicable response code. Afterall, indicating the reason for failure is how the various response codes were intended to be used.

Perhaps this fits:

404 Not Found The requested resource could not be found but may be
available again in the future.[2] Subsequent requests by the client
are permissible.

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