1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-06 05:21:22 +03:00

PROGMEM footprint cleanup for responseCodeToString (#6950)

* PROGMEM footprint cleanup for responseCodeToString

Doing returns with String/FlashStringHelper conversion for every
case means that the code for doing that is duplicated, which
is wasteful. doing it only once saves about 250 bytes (50%) of
code size.

* Remove "I'm a teapot" error code

* Add inline code comment to explain rationale
This commit is contained in:
Dirk Mueller 2019-12-27 23:02:57 +01:00 committed by Develo
parent 698ffc3498
commit bea9cfc3a0
2 changed files with 133 additions and 46 deletions

View File

@ -695,49 +695,136 @@ void ESP8266WebServerTemplate<ServerType>::_finalizeResponse() {
} }
template <typename ServerType> template <typename ServerType>
const String ESP8266WebServerTemplate<ServerType>::responseCodeToString(const int code) { String ESP8266WebServerTemplate<ServerType>::responseCodeToString(const int code) {
switch (code) { // By first determining the pointer to the flash stored string in the switch
case 100: return F("Continue"); // statement and then doing String(FlashStringHelper) return reduces the total code
case 101: return F("Switching Protocols"); // size of this function by over 50%.
case 200: return F("OK"); const __FlashStringHelper *r;
case 201: return F("Created"); switch (code)
case 202: return F("Accepted"); {
case 203: return F("Non-Authoritative Information"); case 100:
case 204: return F("No Content"); r = F("Continue");
case 205: return F("Reset Content"); break;
case 206: return F("Partial Content"); case 101:
case 300: return F("Multiple Choices"); r = F("Switching Protocols");
case 301: return F("Moved Permanently"); break;
case 302: return F("Found"); case 200:
case 303: return F("See Other"); r = F("OK");
case 304: return F("Not Modified"); break;
case 305: return F("Use Proxy"); case 201:
case 307: return F("Temporary Redirect"); r = F("Created");
case 400: return F("Bad Request"); break;
case 401: return F("Unauthorized"); case 202:
case 402: return F("Payment Required"); r = F("Accepted");
case 403: return F("Forbidden"); break;
case 404: return F("Not Found"); case 203:
case 405: return F("Method Not Allowed"); r = F("Non-Authoritative Information");
case 406: return F("Not Acceptable"); break;
case 407: return F("Proxy Authentication Required"); case 204:
case 408: return F("Request Time-out"); r = F("No Content");
case 409: return F("Conflict"); break;
case 410: return F("Gone"); case 205:
case 411: return F("Length Required"); r = F("Reset Content");
case 412: return F("Precondition Failed"); break;
case 413: return F("Request Entity Too Large"); case 206:
case 414: return F("Request-URI Too Large"); r = F("Partial Content");
case 415: return F("Unsupported Media Type"); break;
case 416: return F("Requested range not satisfiable"); case 300:
case 417: return F("Expectation Failed"); r = F("Multiple Choices");
case 418: return F("I'm a teapot"); break;
case 500: return F("Internal Server Error"); case 301:
case 501: return F("Not Implemented"); r = F("Moved Permanently");
case 502: return F("Bad Gateway"); break;
case 503: return F("Service Unavailable"); case 302:
case 504: return F("Gateway Time-out"); r = F("Found");
case 505: return F("HTTP Version not supported"); break;
default: return F(""); case 303:
} r = F("See Other");
break;
case 304:
r = F("Not Modified");
break;
case 305:
r = F("Use Proxy");
break;
case 307:
r = F("Temporary Redirect");
break;
case 400:
r = F("Bad Request");
break;
case 401:
r = F("Unauthorized");
break;
case 402:
r = F("Payment Required");
break;
case 403:
r = F("Forbidden");
break;
case 404:
r = F("Not Found");
break;
case 405:
r = F("Method Not Allowed");
break;
case 406:
r = F("Not Acceptable");
break;
case 407:
r = F("Proxy Authentication Required");
break;
case 408:
r = F("Request Timeout");
break;
case 409:
r = F("Conflict");
break;
case 410:
r = F("Gone");
break;
case 411:
r = F("Length Required");
break;
case 412:
r = F("Precondition Failed");
break;
case 413:
r = F("Request Entity Too Large");
break;
case 414:
r = F("URI Too Long");
break;
case 415:
r = F("Unsupported Media Type");
break;
case 416:
r = F("Range not satisfiable");
break;
case 417:
r = F("Expectation Failed");
break;
case 500:
r = F("Internal Server Error");
break;
case 501:
r = F("Not Implemented");
break;
case 502:
r = F("Bad Gateway");
break;
case 503:
r = F("Service Unavailable");
break;
case 504:
r = F("Gateway Timeout");
break;
case 505:
r = F("HTTP Version not supported");
break;
default:
r = F("");
break;
}
return String(r);
} }

View File

@ -169,7 +169,7 @@ public:
return contentLength; return contentLength;
} }
static const String responseCodeToString(const int code); static String responseCodeToString(const int code);
protected: protected:
void _addRequestHandler(RequestHandlerType* handler); void _addRequestHandler(RequestHandlerType* handler);