Example of HTTPServer with additional features: * SNTPClient, DST rules * Link status indication * Local or SDCard-based WebServer * RPC-able class * Static and Dynamic HTML page
lwip/HTTPServer/HTTPFields.h@0:886e4b3119ad, 2010-01-03 (annotated)
- Committer:
- iva2k
- Date:
- Sun Jan 03 07:00:43 2010 +0000
- Revision:
- 0:886e4b3119ad
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iva2k | 0:886e4b3119ad | 1 | #ifndef HTTPATTRIBUTE_H |
iva2k | 0:886e4b3119ad | 2 | #define HTTPATTRIBUTE_H |
iva2k | 0:886e4b3119ad | 3 | |
iva2k | 0:886e4b3119ad | 4 | #include "HTTPServer.h" |
iva2k | 0:886e4b3119ad | 5 | |
iva2k | 0:886e4b3119ad | 6 | /** |
iva2k | 0:886e4b3119ad | 7 | * A simple HTTPHandler which will add new fields to the httpresult header. |
iva2k | 0:886e4b3119ad | 8 | * It can be used for adding caching strtegies. |
iva2k | 0:886e4b3119ad | 9 | */ |
iva2k | 0:886e4b3119ad | 10 | class HTTPFields : public HTTPHandler { |
iva2k | 0:886e4b3119ad | 11 | public: |
iva2k | 0:886e4b3119ad | 12 | /** |
iva2k | 0:886e4b3119ad | 13 | * Create new HTTPFields |
iva2k | 0:886e4b3119ad | 14 | * @param prefix The prefix path on witch we will execute the Handler. Means add the fields. |
iva2k | 0:886e4b3119ad | 15 | * @param fields The Fields wicht are added to all Handlers with the same prefix and which are added after this one. |
iva2k | 0:886e4b3119ad | 16 | */ |
iva2k | 0:886e4b3119ad | 17 | HTTPFields(const char *prefix, const char *fields) : HTTPHandler(prefix) { _fields = fields; } |
iva2k | 0:886e4b3119ad | 18 | HTTPFields(HTTPServer *server, const char *prefix, const char *fields) : HTTPHandler(prefix) { _fields = fields; server->addHandler(this); } |
iva2k | 0:886e4b3119ad | 19 | |
iva2k | 0:886e4b3119ad | 20 | private: |
iva2k | 0:886e4b3119ad | 21 | /** |
iva2k | 0:886e4b3119ad | 22 | * The Action methon should work on a Connection. |
iva2k | 0:886e4b3119ad | 23 | * If the result is HTTP_AddFields the Server will know that we modified the connection header. |
iva2k | 0:886e4b3119ad | 24 | * If the result is HTTP_Deliver the server will use this object to anwere the request. |
iva2k | 0:886e4b3119ad | 25 | * |
iva2k | 0:886e4b3119ad | 26 | * In this case we add new fields to the header. |
iva2k | 0:886e4b3119ad | 27 | */ |
iva2k | 0:886e4b3119ad | 28 | virtual HTTPHandle action(HTTPConnection *con) const { |
iva2k | 0:886e4b3119ad | 29 | char *old = (char *)con->getHeaderFields(); |
iva2k | 0:886e4b3119ad | 30 | int oldlen = strlen(old); |
iva2k | 0:886e4b3119ad | 31 | int atrlen = strlen(_fields); |
iva2k | 0:886e4b3119ad | 32 | char *fields = new char[atrlen+oldlen+3]; |
iva2k | 0:886e4b3119ad | 33 | strcpy(fields,old); |
iva2k | 0:886e4b3119ad | 34 | fields[oldlen+0] = '\r'; |
iva2k | 0:886e4b3119ad | 35 | fields[oldlen+1] = '\n'; |
iva2k | 0:886e4b3119ad | 36 | strcpy(&fields[oldlen+2], _fields); |
iva2k | 0:886e4b3119ad | 37 | fields[atrlen+2+oldlen] = '\0'; |
iva2k | 0:886e4b3119ad | 38 | con->setHeaderFields(fields); |
iva2k | 0:886e4b3119ad | 39 | if(*old) { |
iva2k | 0:886e4b3119ad | 40 | delete old; |
iva2k | 0:886e4b3119ad | 41 | } |
iva2k | 0:886e4b3119ad | 42 | return HTTP_AddFields; |
iva2k | 0:886e4b3119ad | 43 | } |
iva2k | 0:886e4b3119ad | 44 | |
iva2k | 0:886e4b3119ad | 45 | const char *_fields; |
iva2k | 0:886e4b3119ad | 46 | }; |
iva2k | 0:886e4b3119ad | 47 | |
iva2k | 0:886e4b3119ad | 48 | #endif |
iva2k | 0:886e4b3119ad | 49 |