Download source files - 34 Kb
Introduction
Welcome to
W3Mfc, a collection of freeware MFC classes to implement a simple Web server.
The idea behind is W3Mfc was originally to learn about the Http protocol and how it is implemented on Win32.
It is not intended to be a replacement for IIS or Apache. Instead it is designed as a tool for learning or
in cases where deployment of a solution on IIS would be considered overkill or your product must run on
95/98 in addition to NT.
For detailed information about the HyperText Transfer Protocol you should read
RFC 1945, You can download this from a number of sites by searching for RFC and 1945 on
www.yahoo.com.
Another document that these classes refer to is RFC 2045 which defines MIME.
The classes which constitute W3Mfc are:
- CHttpServerSettings:
- This class contains the settings which are used to configure the web server. Example member variables
in this class include the virtual directories and the their default filenames. If you are developing a
stand alone web server based on W3Mfc, you could for example store all the variables for the
CHttpServerSettings instance in an ini file or in the registry.
- CHttpServer:
- This is the actual class which implements the web server. It has a number of very simple functions to
allow you to control the state of the web server such as Start and Stop. Internally a background
thread is spun off to handle the client connections.
- CHttpSocket:
- This is a simple C++/MFC encapsulation of an SDK socket.
- CHttpResponseHeader:
- This class helps in the handling of sending request headers when returning the HTTP responses to
clients. It provides a number of methods to allow standard Http headers to be added to the client
response.
- CHttpMimeManager:
- This class is used when returning client responses. It is used to determine to mime type of a file
given its extension type. This information is taken from the registry and is cached in this class. For
example files of .htm or .html will normally be of mime type "text/html".
- CHttpRequest:
- This class represents a request from a client. It contains information such as the URI of the request,
the Http Verb used and the Http version used for the request. A member of this type is stored in the
CHttpClient class.
- CHttpClient:
- This class is used in the CHttpServer class to handle client connections. It handles the parsing of
client requests and returning the appropriate response. A number of virtual functions are provided to
allow end user customisation.
Features
- HTTP/1.0 compliant.
- Uses the Windows registry to determine mime type thus simplifying configuration.
- Supports passthrough plaintext authentication for files located on NTFS volumes.
- Supports running under a configurable user account.
- Supports binding to a specific IP address.
- Supports multiple virtual directories.
- Supports directory listing.
- Server name returned can be easily configured.
- Supports server redirection by means of the HTTP 301 status code.
- Consumes very little system memory and CPU resources.
- Compact and easy to follow implementation.
- The interface provided is synchronous which provides an easier programming model than using
asynchronous sockets.
- The code does not rely on the MFC socket classes. These classes have a number of shortcomings, one of
which causes problems when they are used in NT services.
- The code can be used in a console application without any problems.
- The classes are fully Unicode compliant and include Unicode built options in the workspace file.
Usage
- To use the class in your code the following modules in your project:
- base64.cpp/h
- HttpClient.cpp/h
- HttpMimeManager.cpp/h
- HttpResponseHeader.cpp/h
- HttpSocket.cpp/h
- W3Mfc.cpp/h
You will also need to copy over all the resources from the w3mfc.rc file into your resource file.
- Your code will need to include MFC either statically or dynamically.
- You will need to have a functioning winsock stack installed and correctly initialised prior to starting
the web server. Depending on your application, this will involve calling either
WSAStartup()
or AfxSocketInit()
at startup of your application.
- You will also need to have afxtempl.h ,winsock.h or afxsock.h and afxpriv.h in your precompiled header.
The code will work just aswell in a GUI or console app. The code should also work in a multithreaded
application, although it has not be explicitly tested in this scenario.
- To see the class in action, have a look at the code in
InitInstance()
in the module
main.cpp on how to start up and stop the server.
History
V1.0 (4th May 1999)
V1.1 (29th June 1999)
- Implemented support for "HEAD" command.
- Sample provided now also displays the HTTP verb used.
- Sample provided now also displays the date and time of each request.
- Now fully supports multiple virtual directories.
- Now fully supports URL's with encoded characters.
- Implemented support for "DELETE" command.
- Now returns an "Allow:" HTTP header.
- Timeout for requests is now 90 seconds if built for debug.
- Now supports directory listing.
- User name is now displayed in the log window.
V1.11 (29th February 2000)
- Fixed a number of VC 6 level 4 warnings.
- Now empties any passwords transmitted once they are used.
- Now implements W3C Common Logfile logging to the console window.
To Do
GENERAL:
- Support for CGI.
- Support for ISAPI.
- Support for NSAPI.
- HTTP/1.1 support.
- TransmitFile support.
- Integrated search tool.
- Support for NCSA and Apache Server Side Includes (SSI).
- Multithreading / thread pool support to improve performance.
SECURITY:
- Support for SSL.
- NT authentication.
- PCT support.
- Integrated Certificate manager.
LOGGING:
- Support Apache compatible common logfile format log files.
- W3C extended log format.
- Log to ODBC database.
- Daily log files.
- Log file cycling.
- Log file archiving.
- Customizable log file formats.
- Real-time performance counters.
- NT Event Log logging
Contacting the Author
PJ Naughter
Email: pjn@indigo.ie
Web: http://www.naughter.com
29 February 2000