- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
一个 HTTP 请求可以包含一个 Accept
header ,指示客户端可接受的响应媒体类型。服务器应通过提供具有与请求的媒体类型(之一)相匹配的 Content-Type
的响应来尊重请求。媒体类型可能包括参数。 HTTP 是否要求此内容协商过程遵守参数?
也就是说,如果客户端请求
Accept: application/vnd.example; version=2
(这里的version
参数的值为2
),服务器可以服务媒体类型application/vnd.example; version=1
,但不是application/vnd.example; version=2
,服务器是否可以提供响应
Content-Type: application/vnd.example; version=1
服务器是否可以提供标记的响应
Content-Type: application/vnd.example; version=2
但响应的主体实际上被编码为媒体类型application/vnd.example;版本=1
?也就是说,响应的媒体类型参数是对响应主体的不准确描述?
似乎Spring MVC 4.1.0在进行内容协商时不尊重媒体类型参数,并给出响应的媒体类型参数是响应主体的不准确描述的响应。这似乎是因为 org.springframework.util.MimeType.isCompatibleWith(MimeType)
方法没有检查 MimeType
对象的参数。
最佳答案
相关标准,RFC 7231 section 3.1.1.1 ,关于媒体类型的说明如下:
The type/subtype MAY be followed by parameters in the form ofname=value pairs.
因此,Accept
和Content-Type
header 可能包含媒体类型参数。它补充说:
The presence or absence of aparameter might be significant to the processing of a media-type,depending on its definition within the media type registry.
这表明使用参数类型的服务器代码应该注意它们,而不是简单地丢弃它们,因为对于某些媒体类型,它们将很重要。它必须在是否考虑媒体类型参数是否重要方面实现一些智能。
因此,Spring MVC 4.1.0 在进行内容协商时完全忽略参数似乎是错误的:类 org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor
不正确使用 org.springframework.util.MimeType.isCompatibleWith(MimeType)
,或者 MimeType.isCompatibleWith(MimeType)
方法不正确。如果您为 Spring 提供几个 HTTP 消息转换器,这些转换器仅在其支持的媒体类型的参数上有所不同,Spring 将不会可靠地选择媒体类型与请求的媒体类型完全匹配的 HTTP 消息转换器。
在section 3.1.1.5 ,它描述了 Content-Type
header ,它说:
The indicated media type defines both the dataformat and how that data is intended to be processed by a recipient
由于媒体类型的参数通常会改变数据格式,因此 Spring MVC 4.1.0 的行为是错误的,因为它提供的参数是对响应主体的不准确描述:方法 AbstractMessageConverterMethodProcessor .getMostSpecificMediaType(MediaType, MediaType)
错误地返回 acceptType
而不是 produceTypeToUse
当两种类型同样具体时。
然而,section 3.4.1 ,其中讨论了内容协商(主动协商),注释:
A user agent cannot rely on proactive negotiation preferences beingconsistently honored, since the origin server might not implementproactive negotiation for the requested resource or might decide thatsending a response that doesn't conform to the user agent'spreferences is better than sending a 406 (Not Acceptable) response.
因此,服务器是允许给出一个与请求的媒体类型参数不完全匹配的响应,作为它不能提供精确匹配时的后备匹配。也就是说,它可能会选择用 application/vnd.example 进行响应; version=1
响应主体,带有 Content-Type: application/vnd.example; version=1
header ,尽管请求说 Accept: application/vnd.example; version=2
,当且仅当生成有效的application/vnd.example; version=2
响应是不可能的。
Spring 的这种明显不正确的行为已经有一个 Spring 错误报告,SPR-10903 . Spring 开发人员将其关闭为“按设计工作”,并指出
I don't know any rule for comparing media types with their parameters effectively. It really depends on the media type...If you're actually trying to achieve REST versioning through media types, it seems that the most common solution is to use different media types, since their format obviously changed between versions:
- "
application/vnd.spring.foo.v1+json
"- "
application/vnd.spring.foo.v2+json
"
关于http - HTTP 内容协商是否尊重媒体类型参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32071006/
我在 R Markdown 文档中设置全局选项时遇到问题。下面是一个简单的例子。在这种情况下,我试图设置 global.par = TRUE .期望是任何 par()我在一个夹头中制作的规范被带到后续
Cloudflare 正在缓存我的请求,但它忽略了语言 header 。 示例请求: URL : https://api.example.com/v1/places/?param=1¶m=2
我正在尝试创建一个分面条形图,每个分面的百分比加起来为 100。对此的解决方案似乎是 group 的组合和 ..density.. .如何 - 在我看来 group与 fill 冲突. 数据: tes
我正在开发一个 C# 应用程序,该应用程序试图遵守其运行系统的时间格式。如果 Windows 控制面板更改为 24 小时格式,这就是应用程序显示时间的格式。无论如何,它成功地做到了这一点,除了只有在应
我用过 Vundle安装 editorconfig-vim插件。它正确加载并列在 :scriptnames 中.但是当我创建一个新文件时,比如 x.js ,缩进设置不是从 ~/.editorconfi
我曾尝试使用不同的方法自行解决这个问题,但没有一个给我预期的结果。 当我在我的项目的数据库中保存一个文本类型的变量时,问题就出现了。它用换行符保存它,事实上,当我尝试从我的一个 View 中编辑它时,
让我头疼的代码是这样的: $('#timeline .selected').removeClass('selected'); 它在 IE8 中无法正常运行。这些类确实被正确删除,但不知何故该元素仍然具
在处理 java 中的 Swing 对象(还有 JFX,但我稍后会担心这个问题)时,我遇到了一个让我摸不着头脑的问题。 这是我用来在程序中打开字体的代码。这是相当标准的。 public static
我正在为电子商务购物车使用 SOAP API,但我似乎无法让 session 在不同的页面中持续存在。 作为示例,我在下面有一些测试代码(带有一堆调试消息),它将一个项目添加到购物车,然后查看购物车。
我有一个 fieldset与 legend可能加载了很长的字符串。 我想要 legend尊重 fieldset 的宽度并且只使用了 50% 的空间。 目前,如果legend太长它仍然只占fieldse
我有一个完整城市的 3D 模型,想展示一个 这些建筑物的等距 View 。我为此使用 gnuplot 多边形, 因为我不认为我可以将 pm3d 用于具有坐标的多边形 不在一个明确定义的网格上。多边形以
我理解 Clojure 的 *assert*变量可用于关闭断言,但我所做的一切似乎都不起作用。 (defn foo [a] {:pre [(pos? a)]} (assert (even? a
我有一个带有 DependencyProperty 和 CoerceValueCallback 的控件。此属性绑定(bind)到模型对象上的属性。 当将控件属性设置为导致强制的值时,绑定(bind)会
可以通过将它们放置在 smcs.rsp 中来创建全局定义,当您点击播放时 - 您会注意到代码的这些部分被点击,并且一切都表现得好像它应该的那样。 但是,在 MonoDevelop 中编辑源代码时,它无
总的来说,我非常努力尊重模块的隐私(如果变量以下划线为前缀,我不会使用它)。然而,我有一个极端的情况,它看起来相当“安全”。 这是演示 ( my previous question ) parser=
我有一个悬停动画的 div(我正在使用 jquery 的 .hover() 方法)。 div 包含一个带有选择的表单。打开选择并悬停在选项上会使 IE9 将其解释为“取消悬停”父 div,导致第二个悬
如果 max_user_connections 连接已打开,是否有方法告诉 Entity Framework 等待? 我想我可以捕获异常并重试或保留一个计数器,但这最多感觉很糟糕。 我的 Azure
在我的测试中,BitmapFactory.decodeFile() 创建的 Bitmap 不遵循 EXIF header 。 例如,当我调用 Bitmap.getWidth() 时,设备拍摄的肖像图像
请帮助我了解如何解决这个问题。 这是我的路由文件 (auth-routes.js) const userControllers = require('../controllers/user') mod
我的应用程序有时会注入(inject) 标记到网站中,然后创建一个新的 带有亲戚的标签 src 例如设置并注入(inject) 导致浏览器从 http://localhost:8080/chapter
我是一名优秀的程序员,十分优秀!