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.

HTTPConnection.h

Committer:
leihen
Date:
2013-05-26
Revision:
1:6b7472d5e9ee
Parent:
0:7a2421e63e74
Child:
2:8653bbcf7e58

File content as of revision 1:6b7472d5e9ee:

/* HTTPConnection.h */
#ifndef __HTTPConnection_H__
#define __HTTPConnection_H__

#include "mbed.h"
#include "TCPSocketConnection.h"

#include <string>
#include <map>

class HTTPServer;

enum HTTPRequestType
{
    HTTP_RT_GET,
    HTTP_RT_POST,
    HTTP_RT_PUT,
    HTTP_RT_OPTIONS,
    HTTP_RT_HEAD,
    HTTP_RT_DELETE,
    HTTP_RT_TRACE,
    HTTP_RT_CONNECT
};

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();
    
    protected:
        friend class HTTPServer;
                        
        TCPSocketConnection m_Tcp;
        HTTPMessage m_Msg;
        
        int parse(const char *buffer);
        int parseHeader(const char *buffer);
        int receiveHeaders(const char* buffer, int nBuffSize);
        int receiveLine(char* szLine, int nMaxLen, int nTimeout = -1, char szLineTerm = '\n');

};

#endif // __HTTPConnection_H__