Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the java program (at the end of the page) to create a simple HTTP Server

ID: 3651132 • Letter: M

Question

Modify the java program (at the end of the page) to create a simple HTTP Server program.



A client program, a web browser,should make a request to server to retrieve a resource, and server should returns the requested resource or responds with the correct error code, in the case of an error. implement only using the GET and HEAD requests for the server.



The first line of the HTTP request format shown below.



GET /index.html HTTP/1.0

^ ^ ^

| | |

<Request-method> Requested-file <http-version>



After processing the request, server returns the response in the following format.



<status line>

<header lines>

<blank line>

<data>



An example response message would look like the following:



HTTP/1.0 200 OK

Server: My Simple Web Server version 1.0

Content-Length: 32

Content-Type: text/html



<html><body>Hello.</body></html>



program should return one of the following error codes if the request does not succeed.


400 Bad Request

404 Not Found

505 HTTP Version Not Supported



The Server, Content-Length, and Content-Type header lines are the parts of the response header lines for this assignment. Server is the name of server Content-Length is the number of bytes in the requested document; and Content-Type is the type of the document requested. provide the Content-Type header line only for one of the following three document types: text/html, text/plain, and image/gif. If the requested file is of a different type, omit the Content-Type header line. The content type can be determined from the extension of the requested file.

Below is some description of the program:

server process starts up
server creates listening socket at some specific port
server accepts incoming connection
server reads the HTTP request
server processes the request
server sends response back to client
server repeats steps 3 to 6 indefinitely


Program Specification:


1) program should be modular. For example, it can have separate functions to parse the HTTP request, to send the response header, and to send the requested document data, etc.



2) The program allow a user to specify a port number. This can be done by providing the port number as part of a command line argument to the program, by letting the program ask for the port number interactively, or by making the program read the port number from a configuration file. You can specify the port number in the client browser (while testing) by appending the port number following the colon character, as shown below.

http://localhost:80/index.html

Note that localhost is the name of your local computer. You can also

use the IP address 127.0.0.1 instead of localhost when you test your server.



3) Port 80 should be used as the default port when the port is not specified by the user.



4) The server should run indefinitely, sequentially receiving one request after the other.



5) The program should look for requested files from a specific document root folder. It is ok to hard-code this location in the program.



6) If the requested document ends with the

Explanation / Answer

def import lib require lib rescue LoadError `gem install #{lib}` require lib end import 'sinatra' import 'json'

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote