HEAD of the Line
Use the Cleansocks
interface to create a
client that takes a single URL on the command line, and reports
the IP address, response code, server type
and cookies set when fetching the document.
[tom@tomslap asst]$ headinfo http://sandbox.mc.edu/~bennet/cs423v2/getsocks.html
Server at 22.214.171.124 responds 200 OK
Server type: type Apache/2.4.29 (Fedora).
No cookies were set.
[tom@tomslap asst]$ headinfo http://www.mc.edu
Server at 126.96.36.199 responds 301 Moved Permanently
Server type: type Apache/2.4.6 (CentOS).
No cookies were set.
[tom@tomslap asst]$ headinfo http://www.google.com
Server at 188.8.131.52 responds 200 OK
Server type: type gws.
[tom@tomslap asst]$ headinfo http://thehill.com/people/donald-trump
Server at 184.108.40.206 responds 200 OK
Server type: type nginx/1.12.1.
Your application must extract the host name and path from the URL and
send an HTTP HEAD request to the indicated machine. Parse the response headers
to get the information you need to report.
The relevant header names are Server and
Set-Cookie. The Server will appear once or not at all. If it
does not appear, just say that the server type is “Unknown”.
A server may set no cookies, or it may set more than one, so the
Set-Cookie header may appear any number of times. If it does not
appear, state that no cookies were set, otherwise list them all.
You should list the name and value for each one (see below).
If some networking error prevents the reception of any response from the
server, or the server's response cannot be parsed as an HTTP response, print
an appropriate error message. Otherwise, give the numeric response code and
message from the response (even if it is an error), then print the type of
server, and list any cookies set by the server.
Network errors are thrown as exceptions by cleansocks, so you will need
to catch them and
print the value of the exception's .what() method.
[tom@tomslap asst]$ headinfo http://www.forgetit.calm
Error: [IPaddress::lookup(www.forgetit.calm)] Name or service not known
You need only consider very simple URLs. Accept only http URLs, and don't
look for port number or passwords. If the URL is not simple or can't
be parsed, just report an error and exit.
The value of the SetCookie header is a string which gives the name and
value of the cookie. The form is something like this:
SetCookie: name=value; other stuff
Where the ; other stuff
may or may not be present.
calls this part “unparsed attributes,” even though the client
must parse it. We'll discard it.)
If you find a ; in the cookie string, discard the (first) ; and everything after
it. If you don't find an =, then the cookie is invalid, and you should
discard the whole thing. Otherwise, the name of the cookie is the portion
of the string up to the first =, and the value is the portion after the
first =. “First” is important here, because the value may
contain additional equal signs. (Google seems to love these.) The
standard says that either the name or value is allowed to be empty, but
I don't know that I've seen this actually happen.
When your program is working, nicely commented and properly indented,
submit it using the form