【发布时间】:2011-01-13 18:37:23
【问题描述】:
我正在阅读HTTP Header Field Definitions 以正确解析接受标头,但我对接受扩展字段定义感到困惑。它们是指示接受标头优先级的一部分,这将给出以下顺序:
text/html;level=1;param=other
// Less specific :
text/html;level=1
// Less specific:
text/html
// Even less specific
text/*
如果客户端请求 text/html;level=1 但我只有 text/html 的内容提供程序,我不确定会发生什么。我是发送 text/html 内容还是 406(不可接受)错误?
【问题讨论】:
-
请注意,根据 RFC,在您提供的示例中 level=1 和 param=other 是媒体范围参数,并且没有接受扩展。接受扩展是质量值之后的任何东西,据我所知,在实践中几乎完全未使用。
-
接受参数在 API 版本控制中越来越流行,例如
Accept: application/json;version=1。根据RFC7231,q=质量因子完全是可选的。 -
@MarkSlater 是正确的。来自 RFC7231:
The "q" parameter is necessary if any extensions (accept-ext) are present, since it acts as a separator between the two parameter sets.
标签: http http-headers