What is HTTP & QUIC?
Tags: http, quic, protocol, transfer
Published: 2021-06-29 07:15:28

HTTP /0.9 ~/2 uses TCP

### HTTP /0.9

It has only one method, GET.

*Request*

```jsx
GET /index.html
```

*Response*

```html
<HTML>
Hello World
</HTML>
```

### HTTP /1.0

header is added. 

*Request*

```jsx
GET /index.html HTTP/1.0
User-Agent: NCSA_Mosic/2.0 (Windows 3.1)
```

*Response*

Because header defines Content-Type, now it can send other types of data

```html
200 OK
Date: Tue, 15 Nov 1995 05:12:22 GMT
Server: CERN/3.- libwww/2.17
Content-Type: text/html
<HTML>
Hello World
	<img src="/image.gif"/>
</HTML>
```

The characteristic of the HTTP /1.0 is `1 Request & 1 Response Per Connection.` This causes two main problems, 1. performance drops due to the new connection every time, and 2. cost inefficiency due to the server load.

### HTTP /1.1

To solve the version 1. 0's limitations, 1.1 provides the functionality called `Persistent Connection` which allows to receive multiple requests and send multiple responses for certain amount of times by using timeout parameters. Also, 1.1 applies `pipelining` which allows the server not to wait for the response, but to receive all requests in order and responses at once in order. This reduces the delay time of the communication  between the client and the server. 

However, `pipelining` function causes a major problem called `Head Of Line Blocking`. Basically, if three requests were happened, and the initial request takes time to resolve, then the rest needs to be wait for the initial request to be resolved and be ready to respond. 

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jxq68a2dy81xrkfy3l3p.png)

Also, multiple requests may have the same header info which introduce the header duplication issue.


![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ymsy2acfiwfrkjqmx8j5.png)
  

### HTTP /2

HTTP /2 focus on the performance improvements compares to the prior HTTP /1.X. This version does not replace the standard protocol, but gives a meaning of extension. Currently, Naver, facebook, Instagram, and many others applied HTTP 2 protocol.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/460r461g47stjr8iprw6.png)
 

We can find changes in the message transferring method. HTTP /2 uses binary framing layer, and this allows to improve the transfer speed and lower the possibility of causing errors. As you see the diagram above, HTTP 2.0's message is designed to use the frame unit and encoded as binary (parsing and transferring speed is improved, and less error than handling strings).

This frame structure allows to ignore the order of requests and responses, and combine and split the frames depends on their speeds. This request and response multiplexing resolve the `Head Of Line Blocking`.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pcxydc1a71ztk8vz119b.png)
 

How To Find out protocol from the Web browser
- Open inspector or development tool and choose network tab
- Right click on the network table and choose protocol to add to the table

Stream in HTTP /2 also allows to set priority. Server can push the data that the client doesn't ask for.

HTTP /2 uses header compression to reduce the header size. To compress the duplicated header, it uses Huffman Encoding. This reduces the header size by 85% in general and also reduce the page loading time. ([Testing in real time](https://imagekit.io/demo/http2-vs-http1))

### QUIC

QUIC is a transfer layer protocol like TCP and UDP. Google introduced the concept in 2013, and they use this as a default protocol for most of their products. QUIC is based on UDP. 

TCP header holds lots of data that enable the data integrity and trust, but because of this, the speed of process is slow. On the other hand, UDP doesn't really hold much of data in the header, so it gives much faster performance and speed compares to TCP, but doesn't guarantee the integrity, trust, and the order of data. UDP is designed for the data transfer only, and there is no extra functions. Thus, this allows engineers to implement and add the needs to it. Google modified the UDP protocol to enhance the performance as well as the data integrity and trust like TCP.

QUIC sends the message with the initial settings and save the settings into cache to use repeatedly for the future request without handshake. one of the caching method from QUIC is using Connection UUID. This unique ID allows users to maintain their connectivity even if the IP address of the client becomes changed.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q34zfivmnist8erk8q12.png)

QUIC is secured. TLS is applied to QUIC by default, and QUIC uses Source Address Token to protect from IP Spoofing and Replay Attack. QUIC uses individual stream line, and this enhances the multiplexing function. (TCP uses the single stream line with parallel processing).

By using QUIC, Google reduce the loading time by 3 % in google.com, and enhance the buffering issues by 30% in youtube.com.

### HTTP /3

HTTP 3(h3-29) was introduced in 2018, and it is based on QUIC, and Google is currently using it in their products.