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 20:13:28 2013 +0000
Revision:
0:7a2421e63e74
Child:
1:6b7472d5e9ee
First draft, which does not actually handle a request.
; Framework is working though.

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