A version of LWIP, provided for backwards compatibility.

Dependents:   AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HTTPFields.h Source File

HTTPFields.h

00001 #ifndef HTTPATTRIBUTE_H
00002 #define HTTPATTRIBUTE_H
00003 
00004 #include "HTTPServer.h"
00005 
00006 /**
00007  * A simple HTTPHandler which will add new fields to the httpresult header.
00008  * It can be used for adding caching strtegies.
00009  */
00010 class HTTPFields : public HTTPHandler {
00011   public:
00012     /**
00013      * Create new HTTPFields
00014      * @param prefix The prefix path on witch we will execute the Handler. Means add the fields.
00015      * @param fields The Fields wicht are added to all Handlers with the same prefix and which are added after this one.
00016      */
00017     HTTPFields(const char *prefix, const char *fields) : HTTPHandler(prefix) {
00018       _fields = fields;
00019     }
00020 
00021   private:
00022     /**
00023      * The Action methon should work on a Connection.
00024      * If the result is HTTP_AddFields the Server will know that we modified the connection header.
00025      * If the result is HTTP_Deliver the server will use this object to anwere the request.
00026      *
00027      * In this case we add new fields to the header.
00028      */
00029     virtual HTTPHandle action(HTTPConnection *con) const {
00030       char *old = (char *)con->getHeaderFields();
00031       int oldlen = strlen(old);
00032       int atrlen = strlen(_fields);
00033       char *fields = new char[atrlen+oldlen+3];
00034       strcpy(fields,old);
00035       fields[oldlen+0] = '\r';
00036       fields[oldlen+1] = '\n';
00037       strcpy(&fields[oldlen+2], _fields);
00038       fields[atrlen+2+oldlen] = '\0';
00039       con->setHeaderFields(fields);
00040       if(*old) {
00041         delete old;
00042       }
00043       return HTTP_AddFields;
00044     }
00045 
00046     const char *_fields;
00047 };
00048 
00049 #endif
00050