Building a http server, Computer Networking

Assignment Help:

IMPORTANT: The web server should be able to serve HTTP files only. You will not need to implement the directory listing and CGI-bin.

Purpose

The objective is to implement a HTTP server that will allow a HTTP client (a web browser like FireFox or Internet Explorer ) to connect to it and download files.

HTTP Protocol Overview

A HTTP client issues a 'GET' request to a server in order to retrieve a file. The general syntax of such a request is given below :

GET HTTP/1.0

{ }*

where :

  • stands for a whitespace character and,
  • stands for a carraige return-linefeed pair. i.e. a carriage return (ascii character 13) followed by a linefeed (ascii character 10).
  • is also represented as "\n\n".
  • gives us the name of the file requested by the client. This could be just a backslash ( / ) if the client is requesting the default file on the server.
  • { }* contains useful ( but not critical ) information sent by a client. These can be ignored for this project. Note that this part can be composed of several lines each seperated by a .
  • * - kleene star // regular expressions

Finally, observe that the client ends the request with two carriage return linefeed character pair:

The function of a HTTP server is to parse the above request from a client, identify the file being requested and send the file across to the client. However, before sending the actual document, the HTTP server must send a response header to the client. The following shows a typical response from a HTTP server when the requested file is found on the server:

HTTP/1.0 200 Document follows

Server:

Content-type:

{ }*

where :

  • identifies the manufacturer/version of the server. For this project, I will tell this in an email very soon but it should not affect the rest of the coding.
  • indicates to the client, the type of document being sent. This should be "text/html" for an html document, "image/gif" for a gif file, "text/plain" for plain text, etc.
  • {}* as before, contains some additional useful header information for the client to use. These may be ignored for this project.
  • is the actual document requested. Observe that this is separated from the response headers be two carraige return - linefeed pairs.

If the requested file cannot be found on the server, the server must send a response header indicating the error. The following shows a typical response:

HTTP/1.0 404 File Not Found

Server:

Content-type:

where :

  • indicates the type of document (i.e. error message in this case) being sent. Since you are going to send a plain text message, this should be set to text/plain.
  • is a human readable description of the error in plain text/html format indicating the error (e.g. Could not find the specified URL. The server returned an error).

Procedure and Algorithm Details

Stage 0:

The source of an example time server program called daytime-server are provided:

gunzip lab5-src.tar.gz

tar -xvf lab5-src.tar

Then build the server by typing make. Run the server by typing daytime-server without arguments to get information about how to use the server. Run the server and read the sources to see how it is implemented. Some of the functionality of the HTTP server that you will implement is already available in this server.

Stage 1:

Basic Server

You will implement an iterative HTTP server that implements the following basic algorithm:

  • Open Passive Socket.
  • Do Forever
  • Accept new TCP connection
  • Read request from TCP connection and parse it.
  • Frame the appropriate response header depending on whether the URL requested is found on the server or not.
  • Write the response header to TCP connection.
  • Write requested document (if found) to TCP connection.
  • Close TCP connection

The server that you will implement at this stage will not be concurrent, i.e., it will not serve more than one client at a time (it queues the remaining requests while processing each request). You can base your implementation on the example server given in [1] . The server should work as specified in the overview above. Make a copy of the daytime server and name it "myhttpd.cpp". Add the rules to the Makefile to build it.

Adding Concurrency

You will also add concurrency to the server. You will implement three concurrency modes. The concurrency mode will be passed as argument. The concurrency modes you will implement are the following:

-f :  Create a new process for each request

In this mode your HTTP server will fork a child process when a request arrives. The child process will process this request while the parent process will wait for another incoming request. You will also have to prevent the accumulation of inactive zombie processes. You can base your implementation on the server given in [3]

-t : Create a new thread for each request

In this mode your HTTP server will create a new thread to process each request that arrives. The thread will go away when the request is completed.

-p:  Pool of threads

In this mode your server will put first the master socket in listen mode and then it will create a pool of 5 threads where each thread will execute a procedure that has a while loop running forever which calls accept() and dispatches the request. The idea is to have an iterative server running in each thread. Having multiple threads calling accept() at the same time will work but it creates some overhead under Solaris (See [4]). To avoid having multiple threads calling accept() at the same time, use a MUTEX lock around the accept() call.

The format of the command should be:  

myhttpd [-f|-t|-p] []

 

If no flags are passed the server will be an iterative server like in the Basic Server section. If is not passed, you will choose your own default port number. Make sure it is larger than 1024 and less than 65536.

URL to File Mapping

In Apache and other web  servers, the mapping from URL documents to directories in the file system is done through a configuration file. In your project you will do this mapping programatically in the following way:

If document is icons/document in the URL, then it will serve the document from http-root-dir/icons/document.

If the document is cgi-bin/script, then your server will execute the scrip in http-root-dir/cgi-bin.

Otherwise, the document requested will be served from http-root-dir/htdocs. The document could be a subdirectory or a file in a subdirectory in htdocs.

IMPORTANT: A URL for your server should not contain http-root-dir or htdocs in it.

IMPORTANT: Make sure that a user should not be able to request/browse files above the htdocs/ cgi-bin/ or icons/ directories. You can use the "realpath" function to translate paths with ".." and other relative paths to absolute paths.

IMPORTANT: The default page when requesting https://host:port should be the index.html in htdocs.

Make sure that your server uses the http-root-dir and it loads by default the index.html from this directory. Test the simple, complex test.

Write a short README file that includes:

        a) Features in the handout that you have implemented av

        b) Features in the handout that you have not implemented

        c) Extra features

Write your program in a directory called lab5-src. Make sure that your server can be built by typing "make".

IMPORTANT: Do not include the http-root-dir in your submitted files.


Related Discussions:- Building a http server

Layer of security, Other than performance  issues, there could be security ...

Other than performance  issues, there could be security reasons for using something like xinetd.  Make simple design in which a new version of xinetd gives a layer of security.

General middleware in client server environment, What is General Middleware...

What is General Middleware in client server environment? Ans) It having the communication stacks, distributed directories, authentication services, network time, RPC, Queuing se

Threats to information can include, Threats to information can include ...

Threats to information can include Deletion of a file or files. Corruption, caused either by hardware problems or by a bug in the software. Theft of company data

Analysis of sort_bitonic, The bitonic sorting network needed log n number o...

The bitonic sorting network needed log n number of stages for performing the task of sorting the list. The first n-1 stages of the circuit are able to sort two n/2 numbers and the

Difference between routable and non- routable protocols, What is the differ...

What is the difference between routable and non- routable protocols? Ans) Routable protocols can work with a router and can be used to build huge networks. Non-Routable protocol

Format of hardware address, FORMAT OF HARDWARE ADDRESS:    It have ...

FORMAT OF HARDWARE ADDRESS:    It have of a numeric value and its size is chosen for specific network technology. The length of the message format is one to six bytes.

Message passing in pvm, Message Passing The PVM communication model giv...

Message Passing The PVM communication model gives asynchronous blocking receive, asynchronous blocking send and nonblocking receive functions. In our methodology, a blocking se

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd