My fork of the HTTPServer (working)

Dependents:   DGWWebServer LAN2

Committer:
screamer
Date:
Tue Nov 20 12:18:53 2012 +0000
Revision:
1:284f2df30cf9
Parent:
0:7a64fbb4069d
local changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 0:7a64fbb4069d 1 #ifndef HTTPATTRIBUTE_H
screamer 0:7a64fbb4069d 2 #define HTTPATTRIBUTE_H
screamer 0:7a64fbb4069d 3
screamer 0:7a64fbb4069d 4 #include "HTTPServer.h"
screamer 0:7a64fbb4069d 5
screamer 0:7a64fbb4069d 6 /**
screamer 0:7a64fbb4069d 7 * A simple HTTPHandler which will add new fields to the httpresult header.
screamer 0:7a64fbb4069d 8 * It can be used for adding caching strtegies.
screamer 0:7a64fbb4069d 9 */
screamer 0:7a64fbb4069d 10 class HTTPFields : public HTTPHandler {
screamer 0:7a64fbb4069d 11 public:
screamer 0:7a64fbb4069d 12 /**
screamer 0:7a64fbb4069d 13 * Create new HTTPFields
screamer 0:7a64fbb4069d 14 * @param prefix The prefix path on witch we will execute the Handler. Means add the fields.
screamer 0:7a64fbb4069d 15 * @param fields The Fields wicht are added to all Handlers with the same prefix and which are added after this one.
screamer 0:7a64fbb4069d 16 */
screamer 0:7a64fbb4069d 17 HTTPFields(const char *prefix, const char *fields) : HTTPHandler(prefix) {
screamer 0:7a64fbb4069d 18 _fields = fields;
screamer 0:7a64fbb4069d 19 }
screamer 0:7a64fbb4069d 20
screamer 0:7a64fbb4069d 21 private:
screamer 0:7a64fbb4069d 22 /**
screamer 0:7a64fbb4069d 23 * The Action methon should work on a Connection.
screamer 0:7a64fbb4069d 24 * If the result is HTTP_AddFields the Server will know that we modified the connection header.
screamer 0:7a64fbb4069d 25 * If the result is HTTP_Deliver the server will use this object to anwere the request.
screamer 0:7a64fbb4069d 26 *
screamer 0:7a64fbb4069d 27 * In this case we add new fields to the header.
screamer 0:7a64fbb4069d 28 */
screamer 0:7a64fbb4069d 29 virtual HTTPHandle action(HTTPConnection *con) const {
screamer 0:7a64fbb4069d 30 char *old = (char *)con->getHeaderFields();
screamer 0:7a64fbb4069d 31 int oldlen = strlen(old);
screamer 0:7a64fbb4069d 32 int atrlen = strlen(_fields);
screamer 0:7a64fbb4069d 33 char *fields = new char[atrlen+oldlen+3];
screamer 0:7a64fbb4069d 34 strcpy(fields,old);
screamer 0:7a64fbb4069d 35 fields[oldlen+0] = '\r';
screamer 0:7a64fbb4069d 36 fields[oldlen+1] = '\n';
screamer 0:7a64fbb4069d 37 strcpy(&fields[oldlen+2], _fields);
screamer 0:7a64fbb4069d 38 fields[atrlen+2+oldlen] = '\0';
screamer 0:7a64fbb4069d 39 con->setHeaderFields(fields);
screamer 0:7a64fbb4069d 40 if(*old) {
screamer 0:7a64fbb4069d 41 delete old;
screamer 0:7a64fbb4069d 42 }
screamer 0:7a64fbb4069d 43 return HTTP_AddFields;
screamer 0:7a64fbb4069d 44 }
screamer 0:7a64fbb4069d 45
screamer 0:7a64fbb4069d 46 const char *_fields;
screamer 0:7a64fbb4069d 47 };
screamer 0:7a64fbb4069d 48
screamer 0:7a64fbb4069d 49 #endif
screamer 0:7a64fbb4069d 50