且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

httpS和http/2有什么区别?

更新时间:2023-08-18 15:59:52

HTTP -客户端(例如Web浏览器)用来向服务器(例如Web服务器)请求资源的协议.

HTTP - A protocol used by clients (e.g. web browsers) to request resources from servers (e.g. web servers).

HTTPS -一种加密HTTP的方式.它基本上使用SSL/TLS将HTTP消息包装为加密格式.当通过未加密的HTTP为网站提供服务时,Web越来越趋向于HTTPS,并且Web浏览器也开始发出越来越多的警告.除非您有很好的理由不这样做,否则请在您现在创建的任何网站上使用HTTPS.

HTTPS - A way of encrypting HTTP. It basically wraps HTTP messages up in an encrypted format using SSL/TLS. The web is moving towards HTTPS more and more and web browsers are starting to put more and more warnings when a website is served over unencrypted HTTP. Unless you have a very good reason not to, use HTTPS on any websites you create now.

深入研究HTTP,我们拥有:

Digging into HTTP more we have:

HTTP/1.1 -这是HTTP的流行格式,直到最近.这是一个基于文本的协议,并且效率低下-尤其是在请求大量资源(例如典型的网页)时. HTTP/1.1消息可以是未加密的(网站地址以http://开头),也可以使用HTTPS加密(网站地址以https://开头).客户端使用URL的开头来确定要使用的协议,如果未提供,通常默认为http://.

HTTP/1.1 - this was the prevalent format of HTTP until recently. It is a text based protocol and has some inefficiencies in it - especially when requesting lots of resources like a typical web page. HTTP/1.1 messages can be unencrypted (where web site addresses start http://) or encrypted with HTTPS (where web site address start with https://). The client uses the start of the URL to decide which protocol to use, usually defaulting to http:// if not provided.

HTTP/2 -2015年发布的HTTP的新版本,通过从基于文本的协议转移到明确定义每个字节的二进制协议,解决了一些性能问题.这对于客户端和服务器而言更容易解析,为错误留出了更少的空间,并且还允许多路复用. HTTP/2与HTTP/1.1一样,可以通过未加密(http://)和加密(https://)通道使用,但是Web浏览器仅通过HTTPS支持它,在此情况下,是决定使用HTTP/1.1还是HTTP/2作为连接开始时HTTPS协商的一部分.

HTTP/2 - a new version of HTTP released in 2015 which addresses some of the performance issues by moving away from a text based protocol to a binary protocol where each byte is clearly defined. This is easier to parse for clients and servers, leaves less room for errors and also allows multiplexing. HTTP/2, like HTTP/1.1, is available over unencrypted (http://) and encrypted (https://) channels but web browsers only support it over HTTPS, where it is decided whether to use HTTP/1.1 or HTTP/2 as part of the HTTPS negotiation at the start of the connection.

在以下情况下,约有三分之一的网站使用HTTP/2写作.但是,并非所有客户端都支持HTTP/2,因此您应该尽可能支持HTTPS上的HTTP/1.1和HTTPS上的HTTP/2(我相信节点在使用http模块时会自动为您执行此操作).我不认为HTTP/1.1会在不久的将来被淘汰.您还应该考虑通过未加密的HTTP支持HTTP/1.1,然后重定向到HTTPS版本(然后将视情况使用HTTP/1.1或HTTP/2). Node前面的Web服务器(如Apache或Nginx)使此操作变得容易.

HTTP/2 is used by about a third of all websites at the time of writing. However not all clients support HTTP/2 so you should support HTTP/1.1 over HTTPS and HTTP/2 over HTTPS where possible (I believe node automatically does this for you when using the http module). I do not believe HTTP/1.1 will be retired any time soon. You should also consider supporting HTTP/1.1 over unencrypted HTTP and then redirect to HTTPS version (which will then use HTTP/1.1 or HTTP/2 as appropriate). A web server like Apache or Nginx in front of Node makes this easy.

HTTP/3 -HTTP的下一版本,目前正在开发中.预计将在2019年完成,但可能要到2020年,您才能在Web服务器和节点等语言中看到此功能.它将建立在称为QUIC的基于UDP的传输之上(而不是HTTP/1.1和HTTP/2所基于的基于TCP的协议).该协议将在协议中包含HTTPS的一部分,因此HTTP/3仅可通过HTTPS使用.

HTTP/3 - the next version of HTTP, currently under development. It is expected to be finalised in 2019 though it will likely be 2020 before you see this available in web servers and languages like node. It will be built on top of a UDP based transport called QUIC (rather than the TCP based protocol that HTTP/1.1 and HTTP/2 are based on top of). It will include part of HTTPS in the protocol so HTTP/3 will only be available over HTTPS.

简而言之,您应该在HTTPS上使用HTTP/1.1,并且如果易于实现的话,也应该考虑使用HTTP/2(并非总是可能,因为它尚不普遍,但是可以实现),将来您可能会使用HTTP/3.

In short you should use HTTP/1.1 over HTTPS, should consider HTTP/2 as well if easy to implement (not always possible as not quite ubiquitous yet - but getting there) and in future you might be using HTTP/3.

如果您要进行Web开发,我建议您对所有这些技术(到目前为止可能还没有HTTP/3)有一个深刻的了解.它将使您站稳脚跟.

I suggest you get a firm understanding of all of these technologies (except maybe HTTP/3 just yet) if you want to do web development. It will stand you in good stead.