Starting from:

$30

CSE312-Homework 2-Static Site Solved



 

Now that you have the basics of your HTTP server running, let’s host static content using your server. A sample page is provided that you will host so you can focus on the functionality of your server. 

 

Sample site download

 

Objective 1: Host HTML/CSS/JavaScript
Host index.html, style.css, and functions.js from the sample site or host your own page if you completed the bonus objective. You should host each file at a path equal to its file name if you are using the sample site except index.html should be hosted at the root path.

 

Each file must be sent with the appropriate MIME type. You may assume that all files only contain ASCII characters.

Testing Procedure
Start your server using Docker
Open a browser and navigate to http://localhost:<local_port
 Verify that the browser displays the website
The image does not have to display for this objective
Check each HTTP response from your server for the correct MIME type
Verify that the “X-Content-Type-Options: nosniff” header is set on each response
 

Objective 2: UTF-8
Host the utf.txt file from the sample site as “text/plain” MIME type at the path “/utf.txt”. This file contains non-ASCII characters so the content length must be measured carefully. For full credit, you must find the content length programmatically and in a general way that will work for any file (ie. You won’t get full credit if you hardcode the content length of utf.txt).

Testing Procedure
Start your server using Docker
Open a browser and navigate to http://localhost:<local_port/utf.txt
Verify that the browser displays the entire string contained in the file
Verify that the browser is not still loading (This will occur if your content length is larger than the amount of content sent)
Verify in your code that the content length was computed and not hardcoded
 

 

Objective 3: Host Images
Host all of the images in the provided in the images directory of the sample site at the path /image/<image_name where <image_name is the filename of the requested image including the file extension.

Example: A request for the path /image/kitten.jpg should display this adorable image:

 

Testing Procedure
Start your server using Docker
Open a browser and navigate to http://localhost:<local_port
Verify that the image of a flamingo displays properly
Open a browser and navigate to http://localhost:<local_port/image/<image_name
<image_name can be any image provided in the sample site
Verify that the browser displays <image_name
Verify that the MIME type of your HTTP response is appropriate
Verify that the “X-Content-Type-Options: nosniff” header is set on the image response
Objective 4: Query String + HTML Templates
At the path “/images” accept a query string containing containing the keys-value pairs:



●      A key “name” containing a value that is user’s name

●      A key “images” containing a “+” separated list of image names that the user would like to view

○      Each image name will be the filename for the image without an extension and all request should be treated as requests for .jpg images

 

When such a request is received your server should serve an HTML page containing a greeting that includes the user’s name and all of the requested images.

 

Example: If the request is for “/images?images=cat+kitten+dog&name=Mitch” you will serve a page with a message welcoming Mitch and the images cat.jpg, kitten.jpg, and dog.jpg.

 

You may assume the query string will not include any percent-encoded characters.

Testing Procedure
Start your server using Docker
Open a browser and navigate to one of the following:
http://localhost:<local_port/images?name=<name&images<image_list
http://localhost:<local_port/images?images<image_list&name=<name
With any valid choice for <name and <image_list. The images in <image_list will match images in the provided sample site
Verify that the browser displays both a message greeting <name and all of the images from <image_list
Verify the MIME type of your HTTP response are appropriate
Bonus Objective: Front End Development
Create your own front end to replace the sample provided for this assignment. Write your own HTML, CSS, and JavaScript and host your image file(s).

Testing Procedure
Start your server using Docker
Open a browser and navigate to http://localhost:<local_port
Verify that the browser displays a website including HTML, CSS, JavaScript, and at least one image that are all different from the provided sample site
The image must be served by your server using a relative path (Do not set the src of the img to a full url)
Submission
Submit all files for your server to AutoLab in a .zip file ( A .rar or .tar file is not a .zip file!). Be sure to include:

 

●      A Dockerfile in the root directory

●      A file named “report.txt” in the root directory explaining the architecture of your code

●      All the provided web and image files from the sample site (Only images required if you completed the bonus objective)


More products