Click here to Skip to main content
15,891,248 members
Articles / Desktop Programming / MFC

Extendable Webserver

Rate me:
Please Sign up or sign in to vote.
3.67/5 (8 votes)
6 Mar 2003CPOL2 min read 80.9K   1.7K   21  
An example of an extendible webserver using PJ Naughter's MFC library
/*
Module : HTTPREQUEST.H
Purpose: Defines the interface for the CHttpRequest classes
Created: PJN / 30-09-2001
History: None

Copyright (c) 1999 - 2003 by PJ Naughter.  
All rights reserved.

*/


/////////////////////////////// Defines ///////////////////////////////////////

#ifndef __HTTPREQUEST_H__
#define __HTTPREQUEST_H__




/////////////////////////////// Includes //////////////////////////////////////

#ifndef W3MFC_NO_SSPI_SUPPORT
  #ifndef __SSPI_H__
  #include <sspi.h>
  #pragma message("To avoid this message please put SSPI.h in your PCH")
  #endif
#endif




/////////////////////////////// Classes ///////////////////////////////////////

//Class which represents a request from a HTTP client
class CHttpRequest
{
public:
//Constructors / Destructors
  CHttpRequest();
  virtual ~CHttpRequest();

//Enums for m_Verb
	enum HttpVerb
  {
		HTTP_VERB_POST      = 0,
		HTTP_VERB_GET       = 1,
		HTTP_VERB_HEAD      = 2,
		HTTP_VERB_PUT       = 3,
		HTTP_VERB_LINK      = 4,
		HTTP_VERB_DELETE    = 5,
		HTTP_VERB_UNLINK    = 6,
		HTTP_VERB_UNKNOWN   = 7,
	};

//Enums for Authorization type
  enum HttpAuthorization
  {
    HTTP_AUTHORIZATION_ANONYMOUS = 0,
    HTTP_AUTHORIZATION_PLAINTEXT = 1,
    HTTP_AUTHORIZATION_NTLM      = 2,
  };  

//Methods
  CHttpRequest& operator=(const CHttpRequest& request);

//Member variables
  BYTE*             m_pRawRequest;                 //The raw request 
  DWORD             m_dwRawRequestSize;            //The raw request size
  BYTE*             m_pRawEntity;                  //The raw entity-body if any
  DWORD             m_dwRawEntitySize;             //The raw entity-body size if any
  int               m_nContentLength;              //The content length of the entity body
  CString           m_sRequest;                    //The Full request line e.g. "GET / HTTP/1.0"
  sockaddr_in       m_ClientAddress;               //The IP address where the request originated from
  HttpVerb          m_Verb;                        //GET, PUT etc
  CString           m_sURL;                        //The URL of the request
  CString           m_sExtra;                      //Any part of the URL after the "?"
  DWORD             m_dwHttpVersion;               //The HTTP Version Number of the HTTP client request
                                                   //encoded as MAKELONG(Minor, Major)
  BOOL              m_bIfModifiedSincePresent;     //Is the If-Modified-Since header present
  SYSTEMTIME        m_IfModifiedSince;             //The actual If-Modified-Since header
  HttpAuthorization m_AuthorizationType;           //What authorization method is being used
  CString           m_sUsername;                   //username if Authentication is being used
  CString           m_sPassword;                   //password if plaintext authorization is being used
  CString           m_sRemoteHost;                 //the domain name of the client (if reverse DNS is enabled otherwise empty)
  CString           m_sContentType;                //the content type of the entity body
  BOOL              m_bKeepAlive;                  //TRUE if the "Connection: Keep-Alive" header has been set 
  CString           m_sAuthenticationResponse;     //The data to send down in Authentication responses
  BOOL              m_bFirstAuthenticationRequest; //Is this the first part of an authenticating request which requires SSPI
#ifndef W3MFC_NO_SSPI_SUPPORT
  CtxtHandle        m_ContentHandle;               //The SSPI context handle for this request
#endif
  BOOL              m_bAuthenticationComplete;     //Is the Authentication phase complete
  CString           m_sAuthorityName;              //The authenticating authority if using SSPI authentication e.g. this would be the domain name
};


#endif //__HTTPREQUEST_H__

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
ETA
Software Developer (Senior)
Netherlands Netherlands
I'm a 31 year old full-time programmer ('76).
(Currently: Lead Software System Designer)

Comments and Discussions