f

Dependencies:   mbed

Fork of lwip by mbed unsupported

Committer:
idijoeteque
Date:
Thu Aug 03 10:24:16 2017 +0000
Revision:
1:803fdc96fbd7
Parent:
0:5e1631496985
hello

Who changed what in which revision?

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