So continuing with our journey on the Http compression and decompression.
Today we are going to talk about the two important Http headers, which are except encoding and content
encoding.
So before we go about learning on how exactly it works, let me show you on how compression works.
So here I have a text file which is sshd underscore config dot txt.
So let's do a compression on this and see what level of compression can we achieve.
So let's do a LS and here you see it consists of 3.8 k worth of data.
So there are a lot of compression algorithms which are present.
So we'll be using GZip, which is supported by the Http protocol also.
So I'll say GZip nine followed by C sshd config and I'll say SSD dot js.
Now if we do.
And now you see the size difference between the uncompressed version and the compressed version.
It is actually very, very different.
So this is less than half the size, around 30% of the size of the uncompressed version.
So this is the reason why in Http protocol, the compression and decompression has been introduced.
So coming back to our main slide, let's understand on how exactly compression and decompression works
as far as Http protocol is concerned.
Okay.
So this is a get request from the client.
So it says get slash test.txt followed by the Http 1.1 host user agent.
And there is one more field over here which says accept encoding, GZip and deflate.
Now, there are a lot of encoding algorithms or as far as compression also is concerned, there are
a lot of algorithms.
There are three famous ones which are Http protocol supports.
One is the GZip.
Oh one is deflate and one is compress.
So these three are the most famous compression encoding algorithms which have been supported by the
Http protocol.
So we'll be using GZip, which is mostly used on the Internet.
Even deflate is used many times.
So in this get request, the client is saying or the client browser is saying that it is supporting
GZip and deflate with the zip encoding header.
So and it sends a get request.
Now the server will see the zip encoding header and now server knows that the client supports either
GZip or deflate.
Now on the server side, this is the test.txt which has following contents.
Now, as the server knows that the client supports GZip based compression, what the server will do
is the server will actually compress the test.txt and then send the compressed version of the file back
to the client.
Now the question is how will the client know whether the server has sent the compressed file based on
GZip or deflate algorithm?
So what server does is server sends a header called as content encoding, followed by the encoding algorithm,
which the server has used to encode the data.
So here we know that the server has used GZip to compress this particular data.
So the server will include the GZip directive in the content hyphen encoding header so that the client
knows that the data is being compressed with GZip based compression algorithm.
So once the client receives the data, it actually decompresses it with the gzip decoder.
I say gzip decoder.
And then the uncompressed version of the data is received.
So this is a basic overview on how exactly the compression and the decompression works with the excerpt
and content encoding headers.
So let's take a look into the low level data through Wireshark to see how exactly things work.
So.
I'll open Wireshark.
And we'll listen on the net interface.
Which is for VMware.
So let's say start.
So currently there are no data that is flowing in.
So I'll go to my Mozilla.
Okay, so let's open example.com slash sshd underscore config dot txt.
So this is the file which was present on the server.
And let's.
Click and you see the file is opening on the browser.
So going back to the Wireshark, let's see on what exactly has happened.
Let me do a TCP flow stream so we'll get a proper output.
So there are around 11 packets of data which got exchanged during this particular amount of time.
So when it starts with since anak-anak followed by the get request we have already seen on how exactly
this works.
So going back to the TCP follow stream here, you see the client has sent the get request followed by
the sshd underscore config and along with that the client has added an error which says accept encoding.
So accept encoding is the header followed by what type of encoding the client browser supports.
So Mozilla is saying that I am supporting GZip and deflate based encoding algorithms.
Now the server now knows that the browser can support GZip or deflate.
So what server does is it will compress the file with GZip.
So here it is saying content encoding GZip.
That means the file is being encoded or compressed with GZip.
And now it is telling the Mozilla that if you want to open the file, just unzip or just compress it
with the GZip utility.
And this all is the encoded value which is encoded or which is compressed by GZip based compression
algorithm.
So these are the two headers which are normally sent.
Now, one more important thing that you should remember is that if a client or if a modern client does
not send accept encoding header, then the server will assume that the client can understand all the
type of encoding algorithms which includes GZip, which includes deflate, which also includes compress.
So this is important thing to remember.
So this is one of the reasons why browser or the client always try to specify on what type of.
Encoding they support.
Now, this is the basics about the encoding and the content encoding header.
Now let's say if the content is being encoded by, say, deflate and the content encoding is GZip,
then the browser will actually try to compress it with deflate based and decoders, and then the decoding
will not work.
So always important to remember that.
These fields are very important.
And if there is any granularity as far as the content encoding is concerned, then the browser might
not be able to interpret the data.
One more important thing that I would like to share is that the content type.
Now, even though the data is in the form of GZip based file, the content type will always remain the
to the original file.
So the original file was text file which was encoded with GZip.
However, the content type will still not change.
So this is the original content type of the data.
So this is also something which is very important to remember.
So this is it about the basics of except encoding and content encoding.
So I hope this basics has been clear to you.
And this is it about this video.
I hope this has been informative for you and I'd like to thank you for viewing.