Hey, everyone, and welcome back to the Knowledge Portal Video series.
Now, today we will be speaking about partial get request.
So let's get started with a very similar example that we have been discussing since past few lectures.
So you have a client.
So consider this as a web browser or a Telnet.
And on the right hand side you have a web server which has a file called as documentary dot mp4.
Now, when a client makes a request to the web server of type, get so you have a get request on the
documentary.mp for what a web server will do is that it will fetch the entire file and send it back
to the client.
Now what happens if a client wants to see only first five minutes or first let's assume 20s of documentary
and before the client does not really want to see the entire content, just first 20s of the content.
So what client will do along with the get request?
This is the first mandatory step.
Client will also specify that I want to watch only first 20s.
So this is what client will specify to the web server.
Now web server in response will say that here is the first 20s of the data and instead of sending the
entire file, web server will send only partial part of that specific file.
Now, if you look into the response header, you have Http 1.1 and instead of 200, okay, you have
206 partial content.
So this header specifies that the content which is being sent is only partial and it is not the entire
file.
So this is about the partial get request.
So going back to a theoretical perspective, partial get method is used to retrieve only specific content
instead of the entire file.
So if you look into the example over here, you have get request followed by movie dot mp4.
You have the http 1.1 protocol host is Dexter labs in and range is bytes 0 to 1 024.
This basically means only send me the first 1024 bytes of the movie dot mp4.
So once the web server receives this request, instead of sending the entire file, it was it will just
send the first 1024 bytes of the file which is being requested.
Now, one important thing to remember over here is that the partial get was introduced in the Http protocol
version 1.1.
So if you try to do it with 1.0 or 0.9, this will not work.
It got introduced in 1.1.
So if you want to have a partial get, you need to use Http 1.1.
So one important thing to remember.
So this is about the theoretical part.
Let's go to our favorite lab section so that we can actually see on how this really works.
So what I'll do.
I'll type Dexter dot Labs dot in and I'll type partial dot txt.
So if you see over here, the response has content numbers from 1 to 100.
So these are all the numbers which is present in this partial dot txt file.
Now, instead of using classic telnet this time we'll be using one more client which is very famous
called as curl.
So if you do a curl.
Let's say Dexter dot labs dot n slash partial dot txt.
Curl will give you a similar output.
So you see, you got numbers from 1 to 100.
Now Curl is very famous for its flexibility and customization features that it offers.
So I can actually print out the response headers only.
So if you do a hyphen I it will only print out the response headers and not the entire file.
So let me show you on how that actually works so that it becomes much more clear.
Let me start the Wireshark capture and I'll fire up the curl.
So you got the response.
Now I'll stop the Wireshark packet capture.
And this is the request which was made, which is get slash partial dot txt on.
1.1.
So I'll right click here and I'll follow the http stream.
So if you look into the request which curl automatically created.
So whenever you type this command, whenever you type, this command curl will automatically formulate
a get request for us.
However, in case of Telnet, ideally we had seen on how we can write a get request manually.
So curl created a request a get method for partial dot txt.
The protocol is http 1.1 and the host is Dexter Labs dot n.
And this request.
This entire request was sent to the web server listening on Dexter Labs.
Once the web server received this request, it responded back with the Http 1.1 200.
Okay.
200.
Okay.
Means the request that was sent by the curl was successfully processed.
And this is the reason why you have 200.
Okay.
Followed by the other headers.
It also tells us what is the version of web server which is being listened, which is nginx in our case
after this response headers.
So these are called as the request headers.
These are called as the response headers.
After this response headers, the web server which is Nginx, responded with the actual content of the.
Bicycle dot txt file.
So when you do a curl hyphen i what will really happen is that curl will only give us these particular
headers.
It will not send us the content.
Which of the file which was been requested.
Only the response headers.
And you might ask do I really need response headers?
And the answer is very well.
So let's print the response headers and see on what kind of information it provides.
Now, the first information it provides is whether the request was executed successfully or not.
And since the response headers is 200, okay, it means that this request was successfully executed.
Then you have the server which is Nginx.
Now, next important header that will be discussing is the content type which says text slash plain,
which basically says that this file, the partial dot txt or file is of type text.
Then it tells about the content length.
It says that the file which is being requested is of of size 292 bytes.
So we can actually find the size of the file even without requesting it.
This is very important.
Okay.
292 bytes and the last important header is the exit ranges which is of type byte.
Now this is very this specific header is very important when it comes to partial get requests because
this signifies which ranges does the server accept.
So let's let me show you so that it will become much more clear.
So I'll do a curl hyphen hyphen header.
I'll say range range would be bytes 0 to 24 Dexter dot labs dot n slash partial dot txt.
So now what this specifies is that curl will send a get request with a header range and the range is
bytes 0 to 20.
That means just I just need the first 20 bytes of the partial dot txt file.
So this is what it really signifies.
So if I press enter you will see instead of entire file it is only sending me the first 20 bytes of
the partial dot txt file.
So let's do one thing.
Let's fire up the wireshark so that we can see the request headers.
Okay.
And
I'll press.
And you got the first 20 bytes.
So now if I'll stop over here.
Let's go a bit down.
This is our stream.
I'll do a follow Http stream.
So now if you'll see, when we entered this command, when we entered the Curl command, we also specified
a an additional header which it should send to a web server.
And this is the header.
Now Curl will add that header.
So if you see over here, Curl has added one more header called as range with bytes 0 to 20 and this
is what the hyphen hyphen header command actually does.
After this specific request was sent, the Nginx server sent a Http response.
You see 206 partial content.
That means the content that is being sent is of partial type.
It is not the entire file.
Along with that, it tells the content length of the new content which was being sent.
And in the content range header you will see byte is 0 to 20 slash to 92, which signifies out of 292
bytes of the partial dot txt.
Only the bytes ranging from 0 to 20 have been sent back to the client.
Now you can actually modify these value as well, so I can put 20 to 40.
And now you see accordingly you get the information.
Now, this is a commonly used in a downloading website, like there are various websites where you download
files from, and some of these websites will not allow you to resume file for free users.
However, some websites will allow to resume files for free users.
So how they actually do it is that let's assume I'm a free user and I have downloaded content from 0
to 20 bytes, so this much amount of content got downloaded and my internet got disconnected.
So after my internet resumed again, I would ideally want to download file from 20, say, let's say
from 20 to the last byte, which is let's assume to 90.
However, since I'm a free user, what the downloading website does is it will not allow you or it will
not respond with the range header.
It will ask you to start downloading from the absolute zero.
However, for premium users who have paid money, it will allow the range header.
And if you want to resume your downloading from the 21st byte, that will be possible.
So this is how the file downloading websites can block free users from resuming the operations.
So this is it.
About this lecture.
I hope the partial Http get method is understood by you.
And again, if you have any doubts, suggestions, questions, feel free to connect us at Twitter,
Facebook or LinkedIn or mail us at instructors at the Rate Labs dot n.
Thanks for watching.