What is difference between httpS and http/2?

被刻印的时光 ゝ 提交于 2020-07-05 03:04:39

问题


I'm trying to understand what is difference between https and http/2?

If i'm going to build node.js/express app, what should i use?

Can i use https with http/2?

Maybe if i use https, i don't need http/2 because it's the same or https use http/2 under the hood?

I'm confused.

Someone is linked to me "difference between HTTP 1.1 and HTTP 2.0 [closed]", but i understand differense between HTTP and HTTP2. I'm asking about HTTPS and HTTP/2


回答1:


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

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.

Digging into HTTP more we have:

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 - 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 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 - 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.

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.

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.



来源:https://stackoverflow.com/questions/53488601/what-is-difference-between-https-and-http-2

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