Hey, everyone, and welcome back to the Knowledge Portal Video series.
And in today, we'll be speaking about the head method.
Now, we already had an overview about the head method in the earlier lectures when we ran Curl Hyphen
Command, however, I decided to just have a dedicated lecture so that it will become easier for us
to revise.
So when you talk about a response which a web server will send, there are two parts in the response.
One is the header fields and second is the message body.
And this is very important because whenever a web server will send a response, if the first thing that
it will show is the header field and after the header field, it will give us the message body if it
is required.
Now header field itself gives a lot of information like in here you say you see it is 200.
Okay.
That means the request has been successfully processed.
Along with that you have various other important information like the date.
So this is the date in which file was last updated or last modified.
You have a content type, you have the content length.
Content length is very important when you are sending a partial get request.
I hope you remember and you have a cache control which is public.
So these specific headers sometimes becomes quite important and there can be a possibility where client
just needs to know the header field and not the message body.
So if a client just wants to know the header field, then the head method is something which will be
useful.
So head method is used to fetch only the Http headers as part of the response.
Now, whenever a head method is used, so a head method is very identical to a get method, except that
the server must not return a message body in the response.
This is very important.
Whenever a head based header is sent to the web server, the web server should send the response but
without the message body.
Now the example is very simple You have a curl hyphen.
I followed by the URL of the server for which you are sending a head based request.
Perfect.
So let's do one thing.
Let's go ahead and I'll start Wireshark as well so that it will become much more simpler for us to see
on what exactly is happening.
I'll start.
And this time let me do a curl.
I say Dexter dot k p labs dot n say sample dot HTML.
And now you will see it returned only the header fields.
So I'll stop the wireshark
and let's put http so that it will become much more simpler.
So this is the Http.
Packet corresponding to a keyword request.
So if I do a http stream now, what you will see is what curl did.
Curl.
Instead of sending get it, send a head for slash sample dot HTML.
So now in response to this, what a web server did, web server sent only the response header.
It did not send the message body.
However, if you remove the hyphen I over here you will find that it now sent the response body as well.
And this is the basics about the Http head method.
Again, this becomes very very important because you need to know on what are the parameters which your
web server is accepting for a specific resource.
This also helps a lot in cache control as well as partial gets as well.
So we'll be looking into this once we go ahead and work with a web server.
Nginx in great detail.
So this is it about this lecture.
I hope the basic Http head header is understood and if you have any doubts, questions, suggestions,
feel free to connect us at Twitter, Facebook or LinkedIn or mail us at instructors at their labs dot
in.
Thanks for watching.