📄 http.h
字号:
@return TRUE if there is still more to load. */ virtual BOOL LoadData( PHTTPRequest & request, // Information on this request. PCharArray & data // Data used in reply. ); /** Get a block of text data (eg HTML) that the resource contains. The default behaviour is to assert, one of #LoadText()# or #LoadData()# functions must be overridden for correct operation. @return String for loaded text. */ virtual PString LoadText( PHTTPRequest & request // Information on this request. ); /** This is called after the text has been loaded and may be used to customise or otherwise mangle a loaded piece of text. Typically this is used with HTML responses. The default action for this function is to do nothing. */ virtual void OnLoadedText( PHTTPRequest & request, // Information on this request. PString & text // Data used in reply. ); /** Get a block of data (eg HTML) that the resource contains. The default action for this function is to do nothing and return success. @return TRUE if the connection may persist, FALSE if the connection must close */ virtual BOOL Post( PHTTPRequest & request, // Information on this request. const PStringToString & data, // Variables in the POST data. PHTML & replyMessage // Reply message for post. ); protected: /** See if the resource is authorised given the mime info */ virtual BOOL CheckAuthority( PHTTPServer & server, // Server to send response to. const PHTTPRequest & request, // Information on this request. const PHTTPConnectionInfo & conInfo // Information on the connection ); static BOOL CheckAuthority( PHTTPAuthority & authority, PHTTPServer & server, const PHTTPRequest & request, const PHTTPConnectionInfo & connectInfo ); /** common code for GET and HEAD commands */ virtual BOOL OnGETOrHEAD( PHTTPServer & server, // HTTP server that received the request const PURL & url, // Universal Resource Locator for document. const PMIMEInfo & info, // Extra MIME information in command. const PHTTPConnectionInfo & conInfo, BOOL IsGet ); /// Base URL for the resource, may accept URLS with a longer hierarchy PURL baseURL; /// MIME content type for the resource PString contentType; /// Authorisation method for the resource PHTTPAuthority * authority; /// COunt of number of times resource was accessed. volatile DWORD hitCount;};//////////////////////////////////////////////////////////////////////////////// PHTTPString/** This object describes a HyperText Transport Protocol resource which is a string kept in memory. For instance a pre-calculated HTML string could be set in this type of resource. */class PHTTPString : public PHTTPResource{ PCLASSINFO(PHTTPString, PHTTPResource) public: /** Contruct a new simple string resource for the HTTP space. If no MIME content type is specified then a default type is "text/html". */ PHTTPString( const PURL & url // Name of the resource in URL space. ); PHTTPString( const PURL & url, // Name of the resource in URL space. const PHTTPAuthority & auth // Authorisation for the resource. ); PHTTPString( const PURL & url, // Name of the resource in URL space. const PString & str // String to return in this resource. ); PHTTPString( const PURL & url, // Name of the resource in URL space. const PString & str, // String to return in this resource. const PString & contentType // MIME content type for the file. ); PHTTPString( const PURL & url, // Name of the resource in URL space. const PString & str, // String to return in this resource. const PHTTPAuthority & auth // Authorisation for the resource. ); PHTTPString( const PURL & url, // Name of the resource in URL space. const PString & str, // String to return in this resource. const PString & contentType, // MIME content type for the file. const PHTTPAuthority & auth // Authorisation for the resource. ); // Overrides from class PHTTPResource /** Get the headers for block of data (eg HTML) that the resource contains. This will fill in all the fields of the <CODE>outMIME</CODE> parameter required by the resource and return the status for the load. @return TRUE if all OK, FALSE if an error occurred. */ virtual BOOL LoadHeaders( PHTTPRequest & request // Information on this request. ); /** Get a block of text data (eg HTML) that the resource contains. The default behaviour is to assert, one of #LoadText()# or #LoadData()# functions must be overridden for correct operation. @return String for loaded text. */ virtual PString LoadText( PHTTPRequest & request // Information on this request. ); // New functions for class. /** Get the string for this resource. @return String for resource. */ const PString & GetString() { return string; } /** Set the string to be returned by this resource. */ void SetString( const PString & str // New string for the resource. ) { string = str; } protected: PString string;};//////////////////////////////////////////////////////////////////////////////// PHTTPFile/** This object describes a HyperText Transport Protocol resource which is a single file. The file can be anywhere in the file system and is mapped to the specified URL location in the HTTP name space defined by the #PHTTPSpace# class. */class PHTTPFile : public PHTTPResource{ PCLASSINFO(PHTTPFile, PHTTPResource) public: /** Contruct a new simple file resource for the HTTP space. If no MIME content type is specified then a default type is used depending on the file type. For example, "text/html" is used of the file type is ".html" or ".htm". The default for an unknown type is "application/octet-stream". */ PHTTPFile( const PString & filename // file in file system and URL name. ); PHTTPFile( const PString & filename, // file in file system and URL name. const PHTTPAuthority & auth // Authorisation for the resource. ); PHTTPFile( const PURL & url, // Name of the resource in URL space. const PFilePath & file // Location of file in file system. ); PHTTPFile( const PURL & url, // Name of the resource in URL space. const PFilePath & file, // Location of file in file system. const PString & contentType // MIME content type for the file. ); PHTTPFile( const PURL & url, // Name of the resource in URL space. const PFilePath & file, // Location of file in file system. const PHTTPAuthority & auth // Authorisation for the resource. ); PHTTPFile( const PURL & url, // Name of the resource in URL space. const PFilePath & file, // Location of file in file system. const PString & contentType, // MIME content type for the file. const PHTTPAuthority & auth // Authorisation for the resource. ); // Overrides from class PHTTPResource /** Create a new request block for this type of resource. @return Pointer to instance of PHTTPRequest descendant class. */ virtual PHTTPRequest * CreateRequest( const PURL & url, // Universal Resource Locator for document. const PMIMEInfo & inMIME, // Extra MIME information in command. PHTTPServer & socket ); /** Get the headers for block of data (eg HTML) that the resource contains. This will fill in all the fields of the <CODE>outMIME</CODE> parameter required by the resource and return the status for the load. @return TRUE if all OK, FALSE if an error occurred. */ virtual BOOL LoadHeaders( PHTTPRequest & request // Information on this request. ); /** Get a block of data that the resource contains. @return TRUE if more to load. */ virtual BOOL LoadData( PHTTPRequest & request, // Information on this request. PCharArray & data // Data used in reply. ); /** Get a block of text data (eg HTML) that the resource contains. The default behaviour is to assert, one of #LoadText()# or #LoadData()# functions must be overridden for correct operation. @return String for loaded text. */ virtual PString LoadText( PHTTPRequest & request // Information on this request. ); protected: PHTTPFile( const PURL & url, // Name of the resource in URL space. int dummy ); // Constructor used by PHTTPDirectory PFilePath filePath;};class PHTTPFileRequest : public PHTTPRequest{ PCLASSINFO(PHTTPFileRequest, PHTTPRequest) public: PHTTPFileRequest( const PURL & url, // Universal Resource Locator for document. const PMIMEInfo & inMIME, // Extra MIME information in command. PHTTPServer & server ); PFile file;};//////////////////////////////////////////////////////////////////////////////// PHTTPDirectory/** This object describes a HyperText Transport Protocol resource which is a set of files in a directory. The directory can be anywhere in the file system and is mapped to the specified URL location in the HTTP name space defined by the #PHTTPSpace# class. All subdirectories and files are available as URL names in the HTTP name space. This effectively grafts a file system directory tree onto the URL name space tree. See the #PMIMEInfo# class for more information on the mappings between file types and MIME types. */class PHTTPDirectory : public PHTTPFile{ PCLASSINFO(PHTTPDirectory, PHTTPFile) public: PHTTPDirectory( const PURL & url, /// Name of the resource in URL space. const PDirectory & dir /// Location of file in file system. ); PHTTPDirectory( const PURL & url, /// Name of the resource in URL space. const PDirectory & dir, /// Location of file in file system. const PHTTPAuthority & auth /// Authorisation for the resource. ); // Construct a new directory resource for HTTP. // Overrides from class PHTTPResource /** Create a new request block for this type of resource. @return Pointer to instance of PHTTPRequest descendant class. */ virtual PHTTPRequest * CreateRequest( const PURL & url, // Universal Resource Locator for document. const PMIMEInfo & inMIME, // Extra MIME information in command. PHTTPServer & socket ); /** Get the headers for block of data (eg HTML) that the resource contains. This will fill in all the fields of the <CODE>outMIME</CODE> parameter required by the resource and return the status for the load. @return TRUE if all OK, FALSE if an error occurred. */ virtual BOOL LoadHeaders( PHTTPRequest & request /// Information on this request. ); /** Get a block of text data (eg HTML) that the resource contains. The default behaviour is to assert, one of #LoadText()# or #LoadData()# functions must be overridden for correct operation. @return String for loaded text. */ virtual PString LoadText( PHTTPRequest & request /// Information on this request. ); /** Enable or disable access control using .access files. A directory tree containing a _access file will require authorisation to allow access. This file has contains one or more lines, each containing a username and password seperated by a ":" character. The parameter sets the realm used for authorisation requests. An empty realm disables auhtorisation. */ void EnableAuthorisation(const PString & realm); /** Enable or disable directory listings when a default directory file does not exist */ void AllowDirectories(BOOL enable = TRUE); protected: BOOL CheckAuthority( PHTTPServer & server, // Server to send response to. const PHTTPRequest & request, // Information on this request. const PHTTPConnectionInfo & conInfo // Information on the connection ); BOOL FindAuthorisations(const PDirectory & dir, PString & realm, PStringToString & authorisations); PDirectory basePath; PString authorisationRealm; BOOL allowDirectoryListing;};class PHTTPDirRequest : public PHTTPFileRequest{ PCLASSINFO(PHTTPDirRequest, PHTTPFileRequest) public: PHTTPDirRequest( const PURL & url, // Universal Resource Locator for document. const PMIMEInfo & inMIME, // Extra MIME information in command. PHTTPServer & server ); PString fakeIndex; PFilePath realPath;};#endif// End Of File ///////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -