First we will define the root folder for our web server. Eg: C:\MyPersonalwebServer
,
and will create a Data directory underneath, our root directory Eg: C:\MyPersonalwebServer\Data
.
We will Create three files under data directory i.e.
Mimes.Dat
Vdirs.Dat
Default.Dat
Mime.Dat will have the mime type supported by our web server,
Syntax: <EXTENSION>; <MIME Type>e.g. .html; text/html
.htm; text/html
.gif; image/gif
.bmp; image/bmp
VDirs.Dat will have the virtual directory Information. Syntax:
<VirtualDir>; <PhysicalDir>
/; C:\myWebServerRoot/
/test/; C:\myWebServerRoot\Imtiaz\
Note: We have to include all the directories used by our web
server, for example, if the html page contains reference to images and we want
to display image, we need to include it also. e.g./images/; c:myWebServerRoot\Images\,
else that directory won't be
accessed..
Default.Dat will have the virtual directory Information; e.g.
default.html
default.htm
Index.html
Index.htm;
We will store all the information in plain text file for simplicity, we can use XML, registry or even hard code it. Before proceeding to our code let us first look the header information which browser will pass while requesting for our web site
Let say we request for test.html we type http://localhost:5050/test.html
(Remember to include port in the url), here what the web server gets..
GET /test.html HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
Accept-Language: en-usAccept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0; .NET CLR 1.0.2914)
Host: localhost:5050
Connection: Keep-Alive
Comments