简体   繁体   English

是否存在根据定义无效的mime类型?

[英]Is there a mime-type that is invalid by definition?

I am writing an http middleware using Node.js that responds to requests with a certain content-type set as header. 我正在使用Node.js编写一个http中间件,该中间件以某种特定的内容类型作为标头来响应请求。 Now I'd like to unit test that the middleware does not respond to requests with the "wrong" content-type. 现在,我想进行单元测试,以使中间件不响应内容类型为“错误”的请求。

Of course, I can basically use any content-type for this that is not intended to be supported by my component, but I was wondering whether there is a content-type that is intended to be used in this cases (similar to the domain example.com which is for illustrative purposes only and can be used in documentation. 当然,我基本上可以为此组件使用任何不支持的内容类型,但是我想知道是否在这种情况下要使用一种内容类型(类似于域示例) .com仅用于说明目的,可以在文档中使用。

Is there something such as content/invalid or something like this? 是否存在诸如content/invalid东西?

In short: no. 简而言之:不。 You can have a "personal" or "vanity" mime type by prepending with prs. 您可以在prs前面加上“个人”或“虚荣”的哑剧类型。 Media Type Specification, Personal/Vanity type ...but there is no mime that is, by definition, invalid. 媒体类型规范,个人/空缺类型 ...但根据定义,没有哑剧是无效的。 There are obsolete and deleted ones, but they are not by definition invalid. 有过时的和已删除的,但根据定义它们不是无效的。

So you can pretty much do whatever you want, such as content/prs.golo.impossibru or use an oxymoron, like content/swift-government-action - or whatever. 因此,您几乎可以做任何您想做的事情,例如content/prs.golo.impossibru或使用矛盾之词,例如content/swift-government-action content/prs.golo.impossibru等等。 It's kind of like how in some languages 'foo' and 'bar' are such common example variable names, where in other languages that just isn't done. 这有点像在某些语言中,“ foo”和“ bar”是这样常见的示例变量名,而在其他语言中,这是没有做到的。 In mime types there just appears to be no such convention. 在mime类型中,似乎没有这种约定。

This is at least partially because its almost never the mime type that is invalid, because if an error will occur it's usually that the mime is one thing but the content actually sent does not match it. 这至少部分是因为它几乎永远不会是无效的哑剧类型,因为如果发生错误,通常是哑剧是一回事,但实际发送的内容与之不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM