Port of LwIP performed by Ralf in 2010. Not recommended for use with recent mbed libraries, but good demos of raw LwIP possible
Dependents: LwIP_raw_API_serverExample tiny-dtls
HTTPServer/HTTPFields.h@0:0791c1fece8e, 2012-09-18 (annotated)
- Committer:
- RodColeman
- Date:
- Tue Sep 18 14:41:24 2012 +0000
- Revision:
- 0:0791c1fece8e
[mbed] converted /Eth_TCP_Wei_Server/lwip
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RodColeman | 0:0791c1fece8e | 1 | #ifndef HTTPATTRIBUTE_H |
RodColeman | 0:0791c1fece8e | 2 | #define HTTPATTRIBUTE_H |
RodColeman | 0:0791c1fece8e | 3 | |
RodColeman | 0:0791c1fece8e | 4 | #include "HTTPServer.h" |
RodColeman | 0:0791c1fece8e | 5 | |
RodColeman | 0:0791c1fece8e | 6 | /** |
RodColeman | 0:0791c1fece8e | 7 | * A simple HTTPHandler which will add new fields to the httpresult header. |
RodColeman | 0:0791c1fece8e | 8 | * It can be used for adding caching strtegies. |
RodColeman | 0:0791c1fece8e | 9 | */ |
RodColeman | 0:0791c1fece8e | 10 | class HTTPFields : public HTTPHandler { |
RodColeman | 0:0791c1fece8e | 11 | public: |
RodColeman | 0:0791c1fece8e | 12 | /** |
RodColeman | 0:0791c1fece8e | 13 | * Create new HTTPFields |
RodColeman | 0:0791c1fece8e | 14 | * @param prefix The prefix path on witch we will execute the Handler. Means add the fields. |
RodColeman | 0:0791c1fece8e | 15 | * @param fields The Fields wicht are added to all Handlers with the same prefix and which are added after this one. |
RodColeman | 0:0791c1fece8e | 16 | */ |
RodColeman | 0:0791c1fece8e | 17 | HTTPFields(const char *prefix, const char *fields) : HTTPHandler(prefix) { _fields = fields; } |
RodColeman | 0:0791c1fece8e | 18 | HTTPFields(HTTPServer *server, const char *prefix, const char *fields) : HTTPHandler(prefix) { _fields = fields; server->addHandler(this); } |
RodColeman | 0:0791c1fece8e | 19 | |
RodColeman | 0:0791c1fece8e | 20 | private: |
RodColeman | 0:0791c1fece8e | 21 | /** |
RodColeman | 0:0791c1fece8e | 22 | * The Action methon should work on a Connection. |
RodColeman | 0:0791c1fece8e | 23 | * If the result is HTTP_AddFields the Server will know that we modified the connection header. |
RodColeman | 0:0791c1fece8e | 24 | * If the result is HTTP_Deliver the server will use this object to anwere the request. |
RodColeman | 0:0791c1fece8e | 25 | * |
RodColeman | 0:0791c1fece8e | 26 | * In this case we add new fields to the header. |
RodColeman | 0:0791c1fece8e | 27 | */ |
RodColeman | 0:0791c1fece8e | 28 | virtual HTTPHandle action(HTTPConnection *con) const { |
RodColeman | 0:0791c1fece8e | 29 | char *old = (char *)con->getHeaderFields(); |
RodColeman | 0:0791c1fece8e | 30 | int oldlen = strlen(old); |
RodColeman | 0:0791c1fece8e | 31 | int atrlen = strlen(_fields); |
RodColeman | 0:0791c1fece8e | 32 | char *fields = new char[atrlen+oldlen+3]; |
RodColeman | 0:0791c1fece8e | 33 | strcpy(fields,old); |
RodColeman | 0:0791c1fece8e | 34 | fields[oldlen+0] = '\r'; |
RodColeman | 0:0791c1fece8e | 35 | fields[oldlen+1] = '\n'; |
RodColeman | 0:0791c1fece8e | 36 | strcpy(&fields[oldlen+2], _fields); |
RodColeman | 0:0791c1fece8e | 37 | fields[atrlen+2+oldlen] = '\0'; |
RodColeman | 0:0791c1fece8e | 38 | con->setHeaderFields(fields); |
RodColeman | 0:0791c1fece8e | 39 | if(*old) { |
RodColeman | 0:0791c1fece8e | 40 | delete old; |
RodColeman | 0:0791c1fece8e | 41 | } |
RodColeman | 0:0791c1fece8e | 42 | return HTTP_AddFields; |
RodColeman | 0:0791c1fece8e | 43 | } |
RodColeman | 0:0791c1fece8e | 44 | |
RodColeman | 0:0791c1fece8e | 45 | const char *_fields; |
RodColeman | 0:0791c1fece8e | 46 | }; |
RodColeman | 0:0791c1fece8e | 47 | |
RodColeman | 0:0791c1fece8e | 48 | #endif |
RodColeman | 0:0791c1fece8e | 49 |