HTTP/1.0, HTTP/1.1, and HTTP/2.0

This is the 9th day of my participation in Gwen Challenge

preface

HTTP/2.0 protocol is configured in the Web server, take Tomcat for a try.

Tomcat 9 Configure HTTP/2.0

Run Tomcat, access HTTP :localhost:8080, use the developer tool to see that the protocol column is HTTP/1.1, which indicates that HTTP/1.1 is used. If you don’t have protocol, you can right click the properties bar and select

Generate a certificate

Currently, to use HTTP/2.0, browsers must enable SSL, so they need to obtain a certificate first

Windows system can refer to the tomcat + https://www.kancloud.cn/pimingzhao/web_serve/1414096 http2.0 configuration

I am using Windows Terminal, set up the Linux environment, so that you can directly use Linux command.

#If it's Ubuntu
openssl genrsa -out server.key 2048
openssl rsa -in server.key -out server.key
openssl req -new -x509 -key server.key -out ca.crt -days 3650
Copy the code

Copy the generated ca.crt and server.key to the Config directory of Tomcat

Open the Tomcat configuration file server.xml

    <! -- <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol" maxThreads="150" SSLEnabled="true" > <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" /> <SSLHostConfig> <Certificate certificateKeyFile="conf/localhost-rsa-key.pem" certificateFile="conf/localhost-rsa-cert.pem" certificateChainFile="conf/localhost-rsa-chain.pem" type="RSA" /> </SSLHostConfig> </Connector> -->
Copy the code

Change this paragraph to

	<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150" SSLEnabled="true" >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <! Change the path of the certificate -->
            <Certificate certificateKeyFile="conf/server.key"
                         certificateFile="conf/ca.crt"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
Copy the code

Restart Tomcat and visit https://localhost:8443/

You can see that Protocol becomes H2, which means HTTP/2.0 of TLS is used.

HTTP / 2.0 and HTTP / 1.1

Can see from the website https://http2.akamai.com/demo HTTP / 2.0 and HTTP / 1.1 differences in speed

HTTP1.1

  • A persistent connection
  • Request pipelining
  • Added cache handling (new fields such ascache-control)
  • increaseHostField, support breakpoint transmission, etc

HTTP2.0

  • Binary framing. Http1. x parsing is text-based. 2.0 divides the message message into smaller data frames and uses binary transmission instead of plaintext
  • Multiplexing (or connection sharing)
  • The head of compression
  • Server push

reference

HTTP2,

Juejin. Cn/post / 684490…