Single instance HTTP Server using WiFly Interface.
Dependents: WiFlyHTTPServerSample MultiThreadingHTTPServer
HTTPConnection.h
00001 /* HTTPConnection.h */ 00002 /* 00003 Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de) 00004 00005 Permission is hereby granted, free of charge, to any person obtaining a copy 00006 of this software and associated documentation files (the "Software"), to deal 00007 in the Software without restriction, including without limitation the rights 00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 copies of the Software, and to permit persons to whom the Software is 00010 furnished to do so, subject to the following conditions: 00011 00012 The above copyright notice and this permission notice shall be included in 00013 all copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 THE SOFTWARE. 00022 */ 00023 #ifndef __HTTPConnection_H__ 00024 #define __HTTPConnection_H__ 00025 00026 #include "mbed.h" 00027 00028 #include <string> 00029 #include <map> 00030 00031 class HTTPServer; 00032 00033 /** Type HTTPRequestType enumerates request types 00034 */ 00035 typedef enum 00036 { 00037 HTTP_RT_GET, /*!< GET request */ 00038 HTTP_RT_POST, /*!< POST request */ 00039 HTTP_RT_PUT, /*!< PUT request */ 00040 HTTP_RT_OPTIONS, /*!< OPTIONS request */ 00041 HTTP_RT_HEAD, /*!< HEAD request */ 00042 HTTP_RT_DELETE, /*!< DELETE request */ 00043 HTTP_RT_TRACE, /*!< TRACE request */ 00044 HTTP_RT_CONNECT /*!< CONNECT request */ 00045 } HTTPRequestType; 00046 00047 /** class HTTPConnection, encapsulates one connection being made throught the HTTPServer 00048 * 00049 */ 00050 class HTTPConnection { 00051 public: 00052 00053 /** HTTPMessage contains all the details of the request received by external HTTP client. 00054 */ 00055 typedef struct 00056 { 00057 /** Specifies the request type received 00058 */ 00059 HTTPRequestType request; 00060 /** The uri associated with the request. 00061 */ 00062 std::string uri; 00063 /** Contains the HTTP/1.1 or HTTP/1.0 version requested by client. 00064 */ 00065 std::string version; 00066 /** Map of headers provided by the client in the form <HeaderName>:<HeaderValue> 00067 */ 00068 std::map<std::string, std::string> headers; 00069 /** Map of arguments that came with the uri string 00070 */ 00071 std::map<std::string, std::string> args; 00072 } HTTPMessage; 00073 00074 /** Public constructor for HTTPConnection objects. 00075 * 00076 */ 00077 HTTPConnection (); 00078 00079 /** Destructor for HTTPConnection objects. 00080 * 00081 */ 00082 ~HTTPConnection(); 00083 00084 /** Query if this connection is already closed and can be deleted. 00085 @returns true, if connection is closed. 00086 */ 00087 bool is_closed(); 00088 00089 protected: 00090 00091 /** Function to close this connection. To be called from internally. 00092 */ 00093 void close(); 00094 00095 HTTPMessage m_Msg; 00096 00097 /** parse a HTTP request line from the content of the buffer. 00098 * @param buffer : the request received from the client in the form <RequestType> <uri> <Http Version> 00099 * @returns -1 if the request is invalid or 0 if the request is valid 00100 */ 00101 int parse(char *buffer); 00102 int receiveHeaders(const char* buffer, int nBuffSize); 00103 00104 00105 /** parse the receoved \c uri_string for arguments which will be stored in the \c args map. 00106 * @parse uri_string : the uri string which was received from the client. 00107 * @parse args : the args map which will receive the argument:value touples from the \c uri_string. 00108 * @returns -1 if an error occured, otherwise returns 0. 00109 */ 00110 int parseUriArgs(char *uri_string, map<string,string>& args); 00111 00112 }; 00113 00114 #endif // __HTTPConnection_H__
Generated on Tue Jul 12 2022 16:18:49 by 1.7.2