Your task is to write a simple HTTP Server
Ask Expert

Be Prepared For The Toughest Questions

Practice Problems

Your task is to write a simple HTTP Server

1 Project Overview

The aim of this project is to familiarize you with socket programming, multi-threading, and the HTTP protocol. Your task is to write a basic HTTP server that responds correctly to a limited set of GET requests. The HTTP server must return valid response headers for a range of files and paths.

2 Project Details

Your task is to write a simple HTTP Server. There is only a limited range of content that needs to be served, and it only needs to respond to GET requests for static les. You can assume that GET requests are no longer than 2kB in size; note that this is larger than a typical MTU, and so you must be able to read in a multi-packet request.

Example content that needs to be served is:

Content                     File Extension

HTML                             .html

JPEG                               .jpg

CSS                                 .css

JavaScript                      .js

For these extensions, the correct MIME type should be reported (see https://mimetype.io/all-types). For all other extensions, or if there is no extension like Makefile, you can return a MIME type of application/octet-stream. You can assume that the requests are plain ASCII; you do not need to deal with Internationalized Resource Identifiers [https://en.wikipedia.org/wiki/Internationalized_Resource_ Identifier] and you do not need to deal with %-encoding [https://en.wikipedia.org/wiki/Percentencoding].

The minimum requirement is that the server implements HTTP 1.0, and as such, your server does not have to support pipelining or persistent connections. Your server should be able to handle multiple incoming requests by making use of Pthreads (or similar concurrent programming technique) to process and respond to each incoming request.

Your server program must use the following command line arguments:

ˆ protocol number: 4 for IPv4 and 6 for IPv6

ˆ port number

ˆ string path to root web directory

The port number will be the port the server will listen for connections on. The string path to the root web directory points to the directory that contains the content that is to be served. For example:

/home/comp30023/website

All paths requested by a client should be treated as relative to the path specied on the command line. For example, if a request was received with the path /css/style.css it would be expected to be found at:

/home/comp30023/website/css/style.css

The server must support responding with either a 200 response containing the requested le, or a 404 response if the requested le is not found. You do not need to handle requests with invalid headers (but the program should never crash), but paths to non-existent les may be requested, and if they are a 404 should be returned. Response headers should be valid and must included at a minimum:

ˆ Http Status

ˆ Content-type

2.1 Program execution / command line arguments

To run your server program on your VM prompt, type:

./server [protocol number] [port number] [path to web root]

where:

ˆ [protocol number] is 4 for IPv4 or 6 for IPv6

ˆ [port number] is a valid port number (e.g., 8080), and

ˆ [path to web root] is a valid absolute path (e.g., /home/comp30023/website)

Task 1. Server runs and sends valid responses Code must run on the marking VM without crashing (e.g., seg faulting) regardless of the inputs. Any code that crashes for any reason may be allocated a score of 0 overall (not just for this component). However, if your code crashes at the submission deadline, still submit it because some marks may be awarded.

Server sends a valid HTTP 200 response in reply to a GET request for an HTML le located in web root directory (not a sub-directory)

Server sends a valid HTTP 404 response in reply to a GET request for a le in the web root directory that does not exist or cannot be opened for reading

(If you are a purist, then if the le exists but cannot be opened for reading, then the program can alternatively return a 403 (Forbidden Error).

GET requests using path components ../ should return a 404 error. (Otherwise a query like ../secret would break out of the web root, unless handled specically.)

Task 2. Server MIME types and paths Server sends a valid HTTP 200 response with the correct MIME type in reply to a GET request for a le located in web root directory

Server sends a valid HTTP 200 response with the correct MIME type in reply to a GET request with a path below the web root for any of the specied le types (e.g. GET /css/style.css HTTP/1.0)

Task 3. IPv6 (The internet is shifting from IPv4 to IPv6, and we must too.)

The server can accept connections and perform Tasks 1 and 2 using IPv6

Task 4. Build quality Running make clean && make -B && ./server <command line arguments> should execute the submission. If this fails for any reason, you will be told the reason, and be allowed to resubmit (with the usual late penalty). If it still fails, you will get 0 for Tasks 14 and the extension. Test this by committing regularly, and checking the CI feedback. (If you need help, ask on the forum.)

A 0.5 mark penalty will be applied if compiling using -Wall yields a warning or if your final commit contains server, any other executable or .o files (see Practical 2).

The server need not exit. The automated test script will kill it at the end of the tests.

Task 5. Quality of software practices Factors considered include quality of code, based on the choice of variable names, comments, indentation, abstraction, modularity, and proper use of version control, based on the regularity of commit and push events, their content and associated commit messages.

Extension. Parallel downloads Server uses Pthreads (or similar concurrent programming technique, or epoll) to process incoming requests and sending responses. Do not fork multiple processes.

Server can process and respond to at least ve HTTP requests concurrently.

Hint
ComputerHTML is the Hyper Text Markup Language. It is the Web's most basic building block. It basically explains the web content's meaning and structure. Also, most of the other technologies besides HTML are basically used to describe the web page's appearance or presentation (CSS) or even the functionality or the behavior (JavaScript)....

Know the process

Students succeed in their courses by connecting and communicating with
an expert until they receive help on their questions

1
img

Submit Question

Post project within your desired price and deadline.

2
img

Tutor Is Assigned

A quality expert with the ability to solve your project will be assigned.

3
img

Receive Help

Check order history for updates. An email as a notification will be sent.

img
Unable to find what you’re looking for?

Consult our trusted tutors.

Developed by Versioning Solutions.