Simple Web Client
Due: 5:00am, Friday, October 4, 2024
Get the Assignment Code
Login to your university Unix account and copy the assignment code to a location under your home directory:
The starter code for this assignment is on the Linux server here:
/export/home/public/schwesin/cpsc328/assignments/project3
Description
The purpose of this assignment is to create a web client that can make simple HTTP GET requests. The form of the request is similar to this:
GET / HTTP/1.1\r\n
Host: example.com\r\n
Connection: close\r\n
\r\n
where example.com
would be replaced with the value of the host command line
argument. It is important to note that each line of the request ends with a
Carriage Return - Linefeed (CRLF) sequence and that then end of the request has
a single CRLF (this is how we know the header portion of the request is done.)
If we are requesting a specific resource, it would be indicated in the first line of the request as the path to the file:
GET /path/to/file.html HTTP/1.1\r\n
Here is the general flow of the program:
Create a socket: this is a combination of
getaddrinfo
andsocket
and the values of the-h
,-p
, and-f
command line arguments.Connect the socket with
connect
Build and send the HTTP request with
send
; if the verbose flag is set, then print the request to standard out. This requires splitting the URL into the host and path parts.Receive the HTTP response with
recv
Close the socket with
close
Specifications
The name of the compiled program must be
webclient
.The input to the program must be in the form of command line arguments as follows:
-h <string>
host (default localhost)-p <string>
port (default 80)-f <string>
file path (default /)-v
verbose: print the HTTP request
The following rules must be added to the provided Makefile:
- Add a rule to build an executable named
webclient
. This must be the default action of the Makefile. - Add a rule called
clean
to remove any temporary files and thewebclient
executable.
- Add a rule to build an executable named
If the implementation language is Python, the
socket.create_connection
function is forbidden and theurllib
module is forbidden.
Turning in the Assignment
To turn in the assignment, execute the submit script by running the command
make submit
from within the project3
directory.
Grading Criteria
- Consistent coding style
- Modular design
- Correct implementation of the specification
- Correct error checking of library calls