CSc 423 Assignment 1

HEAD of the Line

Assigned
Due

Jan 22
55 pts
Feb 5
Use the Cleansocks interface to create a simple web 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. Like this:
[tom@tomslap asst]$ headinfo http://sandbox.mc.edu/~bennet/cs423v2/getsocks.html Server at 64.246.212.32 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 159.203.177.180 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 64.233.180.106 responds 200 OK Server type: type gws. Cookies: 1P_JAR: 2018-01-20-20 NID: 122=Ax664rh0Py23KP7jcwTDjkr2UFOsAUKo1S24HCbefYVPOXoBYql0eLSicyRQ_A7jYZ8HeHFTBy-MUbhHCAh8K16hqRyPARQGz2Qe8no32bdEr7gJlsR-d3_Nz25ZyazN [tom@tomslap asst]$ headinfo http://thehill.com/people/donald-trump Server at 23.205.120.48 responds 200 OK Server type: type nginx/1.12.1. Cookies: TH_ID: 2c78cd17dd23000057a7635a04010000715e0900

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. (The standard 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.

Submission

When your program is working, nicely commented and properly indented, submit it using the form here.