Is HTTP content negotiation being used by browsers and servers in practice?

删除回忆录丶 提交于 2019-12-08 04:05:20

问题


I'm learning about HTTP content negotiation at the moment. I already understand the basic way client and server are able to negotiate a representation for the content requested.

I could not find out, though, what content negotiation is actually good for. Are real world browsers actively using any of this? I understand they are sending some headers such as Accept but their content and meaning seems vaguely defined to be.

I also wonder if real-world web applications can make use of HTTP content negotiation. Would a realistic web application ever return different data based on these headers? How could a server meaningfully decide based on the q-factor?

My goal is to understand how real web apps work in this regard so that I can better decide which parts of HTTP content negotiation I want to learn and use.

Maybe the answer is just that this is not being used in practice which would be a valid answer to me. Concrete examples for use cases would also help.


回答1:


It's definitely used a lot, for instance to negotiate formats (using "Accept", such as for image/webp), compression codings (using "Accept-Encoding", such as for brotli) or different languages (using "Accept-Language").




回答2:


Yes. It is surely used for multi-language pages (a web site displaying different pages for French & English users)

I would also imagine that some web interface to a version control system could use the Accept: header to display (when showing some C source file) either the raw C file or some HTML formatted version of it.



来源:https://stackoverflow.com/questions/44720631/is-http-content-negotiation-being-used-by-browsers-and-servers-in-practice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!