Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of lwip by
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) { _fields = fields; } 00018 HTTPFields(HTTPServer *server, const char *prefix, const char *fields) : HTTPHandler(prefix) { _fields = fields; server->addHandler(this); } 00019 00020 private: 00021 /** 00022 * The Action methon should work on a Connection. 00023 * If the result is HTTP_AddFields the Server will know that we modified the connection header. 00024 * If the result is HTTP_Deliver the server will use this object to anwere the request. 00025 * 00026 * In this case we add new fields to the header. 00027 */ 00028 virtual HTTPHandle action(HTTPConnection *con) const { 00029 char *old = (char *)con->getHeaderFields(); 00030 int oldlen = strlen(old); 00031 int atrlen = strlen(_fields); 00032 char *fields = new char[atrlen+oldlen+3]; 00033 strcpy(fields,old); 00034 fields[oldlen+0] = '\r'; 00035 fields[oldlen+1] = '\n'; 00036 strcpy(&fields[oldlen+2], _fields); 00037 fields[atrlen+2+oldlen] = '\0'; 00038 con->setHeaderFields(fields); 00039 if(*old) { 00040 delete old; 00041 } 00042 return HTTP_AddFields; 00043 } 00044 00045 const char *_fields; 00046 }; 00047 00048 #endif 00049
Generated on Tue Jul 12 2022 16:07:04 by
1.7.2
