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.

Committer:
leihen
Date:
Sun May 26 22:49:42 2013 +0000
Revision:
1:6b7472d5e9ee
Parent:
0:7a2421e63e74
Child:
2:8653bbcf7e58
Basic functionality demonstrated. One issue exists with error pages, which does not work 100%
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
leihen 0:7a2421e63e74 1 /* HTTPConnection.h */
leihen 0:7a2421e63e74 2 #ifndef __HTTPConnection_H__
leihen 0:7a2421e63e74 3 #define __HTTPConnection_H__
leihen 0:7a2421e63e74 4
leihen 0:7a2421e63e74 5 #include "mbed.h"
leihen 0:7a2421e63e74 6 #include "TCPSocketConnection.h"
leihen 0:7a2421e63e74 7
leihen 0:7a2421e63e74 8 #include <string>
leihen 0:7a2421e63e74 9 #include <map>
leihen 0:7a2421e63e74 10
leihen 1:6b7472d5e9ee 11 class HTTPServer;
leihen 1:6b7472d5e9ee 12
leihen 0:7a2421e63e74 13 enum HTTPRequestType
leihen 0:7a2421e63e74 14 {
leihen 0:7a2421e63e74 15 HTTP_RT_GET,
leihen 0:7a2421e63e74 16 HTTP_RT_POST,
leihen 0:7a2421e63e74 17 HTTP_RT_PUT,
leihen 0:7a2421e63e74 18 HTTP_RT_OPTIONS,
leihen 0:7a2421e63e74 19 HTTP_RT_HEAD,
leihen 0:7a2421e63e74 20 HTTP_RT_DELETE,
leihen 0:7a2421e63e74 21 HTTP_RT_TRACE,
leihen 0:7a2421e63e74 22 HTTP_RT_CONNECT
leihen 0:7a2421e63e74 23 };
leihen 0:7a2421e63e74 24
leihen 0:7a2421e63e74 25 struct HTTPMessage
leihen 0:7a2421e63e74 26 {
leihen 0:7a2421e63e74 27 HTTPRequestType request;
leihen 0:7a2421e63e74 28 std::string uri;
leihen 0:7a2421e63e74 29 std::string version;
leihen 0:7a2421e63e74 30 std::map<string, string> headers;
leihen 0:7a2421e63e74 31 };
leihen 0:7a2421e63e74 32
leihen 0:7a2421e63e74 33 /** class HTTPConnection, encapsulates one connection being made throught the HTTPServer
leihen 0:7a2421e63e74 34 *
leihen 0:7a2421e63e74 35 */
leihen 0:7a2421e63e74 36 class HTTPConnection {
leihen 0:7a2421e63e74 37 public:
leihen 0:7a2421e63e74 38 /** public constructor
leihen 0:7a2421e63e74 39 *
leihen 0:7a2421e63e74 40 */
leihen 0:7a2421e63e74 41 HTTPConnection ();
leihen 0:7a2421e63e74 42 ~HTTPConnection();
leihen 0:7a2421e63e74 43
leihen 0:7a2421e63e74 44 /** function to close this connection. To be called from internally.
leihen 0:7a2421e63e74 45 */
leihen 0:7a2421e63e74 46 void close();
leihen 0:7a2421e63e74 47
leihen 0:7a2421e63e74 48 /** query if this connection is closed and can be deleted.
leihen 0:7a2421e63e74 49 @returns true if connection is closed.
leihen 0:7a2421e63e74 50 */
leihen 0:7a2421e63e74 51 bool is_closed();
leihen 0:7a2421e63e74 52
leihen 0:7a2421e63e74 53 /**
leihen 0:7a2421e63e74 54 Polling function
leihen 0:7a2421e63e74 55 @returns -1 if connection is not required anymore. Can happen if a fault occured or if the connection is not needed anymore.
leihen 0:7a2421e63e74 56 */
leihen 0:7a2421e63e74 57 int poll();
leihen 0:7a2421e63e74 58
leihen 0:7a2421e63e74 59 protected:
leihen 1:6b7472d5e9ee 60 friend class HTTPServer;
leihen 1:6b7472d5e9ee 61
leihen 0:7a2421e63e74 62 TCPSocketConnection m_Tcp;
leihen 1:6b7472d5e9ee 63 HTTPMessage m_Msg;
leihen 0:7a2421e63e74 64
leihen 0:7a2421e63e74 65 int parse(const char *buffer);
leihen 0:7a2421e63e74 66 int parseHeader(const char *buffer);
leihen 0:7a2421e63e74 67 int receiveHeaders(const char* buffer, int nBuffSize);
leihen 0:7a2421e63e74 68 int receiveLine(char* szLine, int nMaxLen, int nTimeout = -1, char szLineTerm = '\n');
leihen 0:7a2421e63e74 69
leihen 0:7a2421e63e74 70 };
leihen 0:7a2421e63e74 71
leihen 0:7a2421e63e74 72 #endif // __HTTPConnection_H__