The library with which to configure a Web Socket Server on a Mbed. This lib was coded by a day at least one year before when this description is written. It will be updated adopting mbed os 5.
handlers/ResponseMessenger.h@2:ccaae77f91b8, 2018-03-03 (annotated)
- Committer:
- aktk
- Date:
- Sat Mar 03 19:01:29 2018 +0000
- Revision:
- 2:ccaae77f91b8
Put out the HTTP_SERVER lib and copy&pasted just the handler directory from the lib to this.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aktk | 2:ccaae77f91b8 | 1 | /* ResponseMessenger.h */ |
aktk | 2:ccaae77f91b8 | 2 | #ifndef RESPONSE_MESSENGER_H |
aktk | 2:ccaae77f91b8 | 3 | #define RESPONSE_MESSENGER_H |
aktk | 2:ccaae77f91b8 | 4 | #include "mbed.h" |
aktk | 2:ccaae77f91b8 | 5 | #include "string.h" |
aktk | 2:ccaae77f91b8 | 6 | #include "EthernetInterface.h" |
aktk | 2:ccaae77f91b8 | 7 | #include "FileHandler.h" |
aktk | 2:ccaae77f91b8 | 8 | #include <stdlib.h> |
aktk | 2:ccaae77f91b8 | 9 | using namespace std; |
aktk | 2:ccaae77f91b8 | 10 | |
aktk | 2:ccaae77f91b8 | 11 | class ResponseMessenger |
aktk | 2:ccaae77f91b8 | 12 | { |
aktk | 2:ccaae77f91b8 | 13 | enum { |
aktk | 2:ccaae77f91b8 | 14 | REASON_PHRASE_SIZE = 32, |
aktk | 2:ccaae77f91b8 | 15 | HEADER_FIELDS_SIZE = 2048 |
aktk | 2:ccaae77f91b8 | 16 | }; |
aktk | 2:ccaae77f91b8 | 17 | public: |
aktk | 2:ccaae77f91b8 | 18 | ResponseMessenger(); |
aktk | 2:ccaae77f91b8 | 19 | ~ResponseMessenger(); |
aktk | 2:ccaae77f91b8 | 20 | int resetHeader(); |
aktk | 2:ccaae77f91b8 | 21 | int setStatusLine(int,const char*); |
aktk | 2:ccaae77f91b8 | 22 | int setHeaderField(const char*, const char*); |
aktk | 2:ccaae77f91b8 | 23 | int setHeaderField(const char*, int); |
aktk | 2:ccaae77f91b8 | 24 | int rmHeaderField(const char*); |
aktk | 2:ccaae77f91b8 | 25 | int getStatusCode(); |
aktk | 2:ccaae77f91b8 | 26 | /** |
aktk | 2:ccaae77f91b8 | 27 | * Function to send response messages. |
aktk | 2:ccaae77f91b8 | 28 | * just header only |
aktk | 2:ccaae77f91b8 | 29 | * @return char |
aktk | 2:ccaae77f91b8 | 30 | * @retval error code |
aktk | 2:ccaae77f91b8 | 31 | */ |
aktk | 2:ccaae77f91b8 | 32 | char sendHTTPResponse(TCPSocketConnection&); |
aktk | 2:ccaae77f91b8 | 33 | /** |
aktk | 2:ccaae77f91b8 | 34 | * Function to send response messages. |
aktk | 2:ccaae77f91b8 | 35 | * @return char |
aktk | 2:ccaae77f91b8 | 36 | * @retval error code |
aktk | 2:ccaae77f91b8 | 37 | */ |
aktk | 2:ccaae77f91b8 | 38 | char sendHTTPResponse(TCPSocketConnection&, FileHandler&); |
aktk | 2:ccaae77f91b8 | 39 | private: |
aktk | 2:ccaae77f91b8 | 40 | // Status-Line |
aktk | 2:ccaae77f91b8 | 41 | static const char http_ver[9]; |
aktk | 2:ccaae77f91b8 | 42 | int status_code; |
aktk | 2:ccaae77f91b8 | 43 | char reason_phrase[REASON_PHRASE_SIZE]; |
aktk | 2:ccaae77f91b8 | 44 | // Header Field buffer |
aktk | 2:ccaae77f91b8 | 45 | // - General Header |
aktk | 2:ccaae77f91b8 | 46 | // - Response Header |
aktk | 2:ccaae77f91b8 | 47 | // - Entity Header |
aktk | 2:ccaae77f91b8 | 48 | char header_field_buffer[HEADER_FIELDS_SIZE]; |
aktk | 2:ccaae77f91b8 | 49 | }; |
aktk | 2:ccaae77f91b8 | 50 | |
aktk | 2:ccaae77f91b8 | 51 | #endif |