So welcome back to the Knowledge Portal Video series.
So we have finally reached the stage where we can actually talk about the content negotiation in the
Http protocol.
So let's explore on what it is.
So let's take an example where this is a client or a web browser, and this is a video streaming server,
something similar to YouTube.
Now, there are a lot of videos in this video streaming server, and each video is associated with three
qualities.
One is for RTP, one is 720p and one is 1080p.
Now, whenever a client requests come to this particular server asking for a video, how will a video
server determine on what is the quality of the video?
It has to serve to the client.
So one of the techniques is based on the user agent string.
So it was assumed that the mobile clients always had a slower connection than a typical broadband.
So whenever a video streaming server used to get a request with a user agent based on a mobile, then
they tried to serve the lowest quality.
So in this case, the quality that would be served would be typically for ATP.
However, if a user region is based on a desktop browser, then the video streaming server can actually
send video based on 720 or 1080p quality.
So that really depends on.
What algorithm the video streaming server uses.
So.
One of the ways in which a video streaming server can determine the quality that it has to serve is
based on the client itself.
So client, along with the video URL, will also specify on what is the quality of video that it wants
to be served.
So in this example, if you see the client is saying that I want to watch a documentary, preferred
version is 1080p 720p is less preferred.
So that means the client is willing to accept 720p however it wants to watch video based on the 1080p
quality.
So here there is no mention of four ATP, so client would not like to watch A4P based quality.
So now it becomes easier for a video streaming server to determine that.
What is the quality of the video that it would like to serve to the client?
And this is the preferred version, because generally nowadays even mobile phones are starting to have
a 4G base network.
So even they have a very fast Internet connection.
So the way in which a server can determine on what is the type of content that it wants to serve is
based on the relative quality factor, which Http protocol provides.
Now, the relative quality factor B is based on the Q parameter scale.
So Q parameter basically ranges from 0 to 1.
Zero means least preferred.
Or I can also say not preferred, and one means most preferred.
So if we take an example of the.
The one that we have already discussed over here to the parameter scale, we can determine that ten
ATP would be associated with one value.
So one means most preferred.
However, 720p is less preferred, so it can come somewhere in between.
So we can assume it can be it can have a score of 0.5.
That means less preferred.
So let's take an example.
Then it will become much more clearer.
So there is a the first example is related to website which has multi-language based content.
So a browser in the Excel language header is saying that it prefers the.
In GB, which is British English and Ian as well.
Now notice that the language is associated with a Q parameter.
So the Q parameter is basically the one that we were talking about here, which ranges from 0 to 1.
Zero means least preferred or not preferred, and one means most preferred.
So if there is no parameter associated here, that means that it defaults to one.
So as there is no parameter associated with DIA, a dia is Danish.
That means DIA is associated with parameter one.
So if we translate this then the client browser is preferring Danish language.
Of content.
If Danish language of content is not there, then it is even ready to accept British English.
So the second preference is British English with 0.8 parameter score and the third is 0.7, which is
English.
So if we translate it, then it comes to I prefer Danish language of contents.
If Danish language is not available, then even British.
British English is also okay.
If British English is also not available, then you can even serve me normal English contents.
And this is how the Q parameter works.
One more example over here is that.
It.
The client is willing to accept page which is based on text slash HTML.
So these are the mime types.
We already discussed the mime types, so as there are no parameter associated over here, it means that
all of these are associated with default value one.
So here for application slash XML, the Q parameter is 0.9.
So this is the second preference and the second preference is not available.
Then for any other the Q parameter is 0.8.
So this is how a client browser can tell to a server on what are its own preferences.
And this is why it is called as content negotiation, because there is a negotiation of content that
takes place.
So as we have already seen, the.
Basics of content negotiation.
Let's open up Wireshark and see.
On what exactly happens in the background.
So I'll start my wireshark and.
Along with that, let's open our Internet Explorer and let's go to example.com and go to example.com,
slash my website dot HTML.
Okay, So this is a content and this is a image file that has come.
So if I stop the packet capture.
Let's go to.
Get my website.
So this is the stream and let's follow the stream.
Okay.
So let me show you.
If we look over here in the image source, when the server is making a get request for my Z dot PNG
in the accept header, there is a.
The Q parameter is associated.
So if we see over here for image slash PNG, as there is no Q parameter, it means it defaults to one.
Even for the second mime type, it defaults to one.
However, for any other mime type, say image slash gif or image slash jpeg, etcetera, the q parameter
associated is 0.8.
However, if even this is not available, then the server the client is ready to accept any type any
mime type with Q parameter 0.5.
So.
In this way, the client is telling to the server that I would prefer to have a PNG based image.
If it is not available, then it goes to second, then the one with the lower Q parameter scores.
So this is one of the ways in which the client can tell to the server about its own preferences.
And in this way the content negotiation takes place.
Now, the content negotiation even works as far as language is concerned.
So here, as you see, as there is only one language, that means the client would prefer to have a
content based on Ian slash us that is English based on us.
So this language has a parameter of one as there is not defined by default.
So this is one of the ways in which the Q parameter can help in the content negotiation.
Even if you go to YouTube, there is a lot of content negotiation that takes place.
To see what type of video quality a client would prefer.
So this is it about the Q parameter and the basic content negotiation.
I hope this video has been useful for you, and I'd like to thank you for viewing.