Single instance HTTP Server using WiFly Interface.

Dependents:   WiFlyHTTPServerSample MultiThreadingHTTPServer

This is my implementation for a HTTP Server using the WiFly Interface. Please note that this is still under development.

It may still contain several bugs. I have tested it using a 1768 on an application board plus RN-XV board.

Currently there is only a FileSystem implemented. Also it is limited to GET request.

I try to extend it further so it will be more useful.

Btw, it does NOT work with RTOS, which seems not to be the Problem of my library.

Do not Forget to Import the WiFly Interface into your Project when using this library.

Change History:

REV5: - added support for basic RPC GET request functionality.

REV4: - added argument parsing from the request uri. - documentation extended and updated.

Revision:
3:d6224049b3bf
Parent:
2:8653bbcf7e58
Child:
4:d065642c32cc
--- a/HTTPConnection.h	Sun May 26 23:22:36 2013 +0000
+++ b/HTTPConnection.h	Tue May 28 01:56:14 2013 +0000
@@ -1,4 +1,25 @@
 /* HTTPConnection.h */
+/*
+Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
 #ifndef __HTTPConnection_H__
 #define __HTTPConnection_H__
 
@@ -10,60 +31,76 @@
 
 class HTTPServer;
 
-enum HTTPRequestType
+/** Type HTTPRequestType enumerates request types
+*/
+typedef enum 
 {
-    HTTP_RT_GET,
-    HTTP_RT_POST,
-    HTTP_RT_PUT,
-    HTTP_RT_OPTIONS,
-    HTTP_RT_HEAD,
-    HTTP_RT_DELETE,
-    HTTP_RT_TRACE,
-    HTTP_RT_CONNECT
-};
+    HTTP_RT_GET,        /*!< GET request */
+    HTTP_RT_POST,       /*!< POST request */
+    HTTP_RT_PUT,        /*!< PUT request */
+    HTTP_RT_OPTIONS,    /*!< OPTIONS request */
+    HTTP_RT_HEAD,       /*!< HEAD request */
+    HTTP_RT_DELETE,     /*!< DELETE request */
+    HTTP_RT_TRACE,      /*!< TRACE request */
+    HTTP_RT_CONNECT     /*!< CONNECT request */
+} HTTPRequestType;
 
-struct HTTPMessage
-{
-    HTTPRequestType             request;
-    std::string                 uri;
-    std::string                 version;
-    std::map<string, string>    headers;
-};
 
 /** class HTTPConnection, encapsulates one connection being made throught the HTTPServer
  *
  */
 class HTTPConnection {
     public:
-    /** public constructor
-     *
-     */
-    HTTPConnection ();
-    ~HTTPConnection();
-    
-    /** function to close this connection. To be called from internally.
-    */
-    void close();
-    
-    /** query if this connection is closed and can be deleted.
-    @returns true if connection is closed.
-    */
-    bool is_closed();
-    
-    /**
-    Polling function
-    @returns -1 if connection is not required anymore. Can happen if a fault occured or if the connection is not needed anymore.
-    */
-    int poll();
+        
+        /** HTTPMessage contains all the details of the request received by external HTTP client.
+        */
+        typedef struct 
+        {
+            /** Specifies the request type received
+            */
+            HTTPRequestType             request;
+            /** The uri associated with the request.
+            */
+            std::string                 uri;
+            /** Contains the HTTP/1.1 or HTTP/1.0 version requested by client.
+            */
+            std::string                 version;
+            /** Map of headers provided by the client in the form <HeaderName>:<HeaderValue>
+            */
+            std::map<std::string, std::string>    headers;
+        } HTTPMessage;
+        /** Public constructor for HTTPConnection objects.
+         *
+         */
+        HTTPConnection ();
+        
+        /** Destructor for HTTPConnection objects.
+        *
+        */
+        ~HTTPConnection();
+        
+        /** Query if this connection is already closed and can be deleted.
+        @returns true, if connection is closed.
+        */
+        bool is_closed();
+        
+        /** Polling function for the connection.
+        * @returns -1 if connection is not required anymore. In the current version of this library this should be the normal case. This may change in future versions.
+        */
+        int poll();
     
     protected:
+        
+        /** Function to close this connection. To be called from internally.
+        */
+        void close();
+
         friend class HTTPServer;
                         
         TCPSocketConnection m_Tcp;
         HTTPMessage m_Msg;
-        
         int parse(char *buffer);
-        int parseHeader(const char *buffer);
+        int parseHeader(char *buffer);
         int receiveHeaders(const char* buffer, int nBuffSize);
         int receiveLine(char* szLine, int nMaxLen, int nTimeout = -1, char szLineTerm = '\n');