203 Non-Authoritative Information
用法
203 Non-Authoritative Information 状态码首先确认请求已成功。原始状态码不会被保留。客户端无法判断源服务器返回的是 200、201 还是另一个成功码。
注意
出于这一原因,203 Non-Authoritative Information 状态码有时不被推荐使用。如今已废弃的、带有代码 214(Transformation Applied)的 Warning 请求头曾作为一种替代方案,用于在保留原始状态码的同时标示发生了转换。Warning 请求头已从 HTTP 标准中移除。
示例
客户端通过一个中间代理服务器请求资源。源服务器以纯文本形式存储该资源。代理在将响应转发给客户端之前,先将资源转换为 JSON 格式。
请求
GET /instructions HTTP/1.1
Host: example.com
来自源服务器的响应
HTTP/1.1 200 OK
Content-Type: text/plain; charset=UTF-8
Content-Length: 250
<message body in text format>
代理返回给客户端的响应
HTTP/1.1 203 Non-Authoritative Information
Content-Type: application/json
Content-Length: 265
{"response":"<message body embedded in JSON>"}
替代方案(遗留)
已废弃
Warning 请求头已被废弃,现属遗留用法。此方案不推荐用于新的实现。
代理不使用 203 Non-Authoritative Information 状态码,而是添加一个带有代码 214(Transformation Applied)的 Warning 请求头,从而保留原始状态码。
代理使用 Warning 请求头的响应
HTTP/1.1 200 OK
Content-Type: application/json
Warning: 214 proxy.example.re "Response converted to JSON format"
Content-Length: 265
{"response":"<message body embedded in JSON>"}
当使用 Warning 请求头代替 203 Non-Authoritative Information 状态码时,原始状态码得以保留,客户端据此相应地处理响应。
代码参考
.NET
HttpStatusCode.NonAuthoritativeInformation
Rust
http::StatusCode::NON_AUTHORITATIVE_INFORMATION
Rails
:non_authoritative_information
Go
http.StatusNonAuthoritativeInfo
Symfony
Response::HTTP_NON_AUTHORITATIVE_INFORMATION
Python3.5+
http.HTTPStatus.NON_AUTHORITATIVE_INFORMATION
Java
java.net.HttpURLConnection.HTTP_NOT_AUTHORITATIVE
Apache HttpComponents Core
org.apache.hc.core5.http.HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION
Angular
@angular/common/http/HttpStatusCode.NonAuthoritativeInformation