大网数据广告活动
服务器运维问答

Running an API, if I correct a content-type header will that break things for customers?

· 52CE 我爱测

We're running an API with quite a few people using it. Due to some legacy clumsiness on my part, one of the endpoints is returning the wrong content-type header , js when it should be json . My question is, if we fix this by swap…

问题原文

原帖链接 · Harry Wood · CC BY-SA 3.0

We're running an API with quite a few people using it. Due to some legacy clumsiness on my part, one of the endpoints is returning the wrong content-type header, js when it should be json. My question is, if we fix this by swapping to return the correct value, how badly could it mess things up for our existing customers? Or to put it another way, would you expect many different HTTP client libraries to throw fatal errors when seeing such a change?

We're trying to decide if this is a change which we can just go ahead and make without sweating it too much, or we should carefully email all users and announce a multi-year deprecation period ...or something in between.

It probably depends a bit on what kind of different HTTP clients are in use, so I took a look at user agents. Answer: a lot of different ones! Here's some of the top ones:

"okhttp/3.2.0", "python-requests/2.10.0", "Ruby", "python-requests/2.7.0", "Mozilla/5.0", "Java/1.8.0_91", "python-requests/2.4.3", "okhttp/3.3.0", "Lucee", "Dalvik/2.1.0", "Google-HTTP-Java-Client/1.21.0", "PHP_appname", "NativeHost", "Java/1.7.0_67", "Apache-HttpClient/UNAVAILABLE", "Dalvik/1.6.0", "Web-sniffer/1.1.0", "unirest-objc/1.1"

Various different mobile and server side language libraries. Mostly not browsers running javascript, but some of those too.

Most people don't seem to notice that the content-type is wrong, but every now and then a new support request pops up complaining about this issue, so we'd like to fix it.

社区高分解答

原帖链接 · alzee · CC BY-SA 3.0

how badly could it mess things up for our existing customers?

It could completely sink their battleships if they've written code that relies on this Content-Type being incorrect.

I would not expect the libraries to throw errors, but I expect that in some cases strict libraries have had their behavior overridden to handle the incorrect MIME type.

If your API has a version/revision value in a request field somewhere, raise it, and in the new version return the correct type but continue to return the incorrect type in the older versions. If you don't have such a request field, now is a good time to add one.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-08-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。