是否可以修改与 HTTP 状态代码一起发送的文本?
我正在我的网站上实施“测试模式”,该模式将禁止访问正在构建的某些页面,使它们只能由管理员访问以进行私人测试。我计划使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以改变它们。
状态消息(技术上称为“原因短语”)只是建议,并且“可以在不影响协议的情况下进行更改”。
请参阅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.
是的,原因短语可以更改。它不会影响消息的含义。
但如果需要说“暂时不可用”,则需要将其设为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).
您可以更改文本(很少有 http 客户端会注意到它),但最好使用最适用的响应代码。毕竟,指示失败的原因是各种响应代码的用途。
也许这适合:
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: