|
3 | 3 |
|
4 | 4 | #pragma once |
5 | 5 |
|
| 6 | +// Include WString.h for F() macro support on Arduino platforms |
| 7 | +#ifdef ARDUINO |
| 8 | +#include <WString.h> |
| 9 | +#endif |
| 10 | + |
| 11 | +// Platform-specific string storage and return type |
| 12 | +#ifdef ARDUINO_ARCH_ESP8266 |
| 13 | + // On ESP8266, use PROGMEM storage and return __FlashStringHelper* |
| 14 | + #include <pgmspace.h> |
| 15 | + #define DECLARE_STR(name, value) static const char name##_PROGMEM[] PROGMEM = value |
| 16 | + #define STR(name) (reinterpret_cast<const __FlashStringHelper*>(name##_PROGMEM)) |
| 17 | + #define STR_RETURN_TYPE const __FlashStringHelper* |
| 18 | +#else |
| 19 | + // On other platforms, use regular constexpr for compile-time optimization |
| 20 | + #define DECLARE_STR(name, value) static constexpr const char *name = value |
| 21 | + #define STR(name) name |
| 22 | + #define STR_RETURN_TYPE const char* |
| 23 | +#endif |
| 24 | + |
6 | 25 | namespace asyncsrv { |
7 | 26 |
|
8 | 27 | static constexpr const char empty[] = ""; |
@@ -154,49 +173,49 @@ static constexpr const char T_text_xml[] = "text/xml"; |
154 | 173 | static constexpr const char T_video_mp4[] = "video/mp4"; |
155 | 174 | static constexpr const char T_video_webm[] = "video/webm"; |
156 | 175 |
|
157 | | -// Response codes |
158 | | -static constexpr const char T_HTTP_CODE_100[] = "Continue"; |
159 | | -static constexpr const char T_HTTP_CODE_101[] = "Switching Protocols"; |
160 | | -static constexpr const char T_HTTP_CODE_200[] = "OK"; |
161 | | -static constexpr const char T_HTTP_CODE_201[] = "Created"; |
162 | | -static constexpr const char T_HTTP_CODE_202[] = "Accepted"; |
163 | | -static constexpr const char T_HTTP_CODE_203[] = "Non-Authoritative Information"; |
164 | | -static constexpr const char T_HTTP_CODE_204[] = "No Content"; |
165 | | -static constexpr const char T_HTTP_CODE_205[] = "Reset Content"; |
166 | | -static constexpr const char T_HTTP_CODE_206[] = "Partial Content"; |
167 | | -static constexpr const char T_HTTP_CODE_300[] = "Multiple Choices"; |
168 | | -static constexpr const char T_HTTP_CODE_301[] = "Moved Permanently"; |
169 | | -static constexpr const char T_HTTP_CODE_302[] = "Found"; |
170 | | -static constexpr const char T_HTTP_CODE_303[] = "See Other"; |
171 | | -static constexpr const char T_HTTP_CODE_304[] = "Not Modified"; |
172 | | -static constexpr const char T_HTTP_CODE_305[] = "Use Proxy"; |
173 | | -static constexpr const char T_HTTP_CODE_307[] = "Temporary Redirect"; |
174 | | -static constexpr const char T_HTTP_CODE_400[] = "Bad Request"; |
175 | | -static constexpr const char T_HTTP_CODE_401[] = "Unauthorized"; |
176 | | -static constexpr const char T_HTTP_CODE_402[] = "Payment Required"; |
177 | | -static constexpr const char T_HTTP_CODE_403[] = "Forbidden"; |
178 | | -static constexpr const char T_HTTP_CODE_404[] = "Not Found"; |
179 | | -static constexpr const char T_HTTP_CODE_405[] = "Method Not Allowed"; |
180 | | -static constexpr const char T_HTTP_CODE_406[] = "Not Acceptable"; |
181 | | -static constexpr const char T_HTTP_CODE_407[] = "Proxy Authentication Required"; |
182 | | -static constexpr const char T_HTTP_CODE_408[] = "Request Time-out"; |
183 | | -static constexpr const char T_HTTP_CODE_409[] = "Conflict"; |
184 | | -static constexpr const char T_HTTP_CODE_410[] = "Gone"; |
185 | | -static constexpr const char T_HTTP_CODE_411[] = "Length Required"; |
186 | | -static constexpr const char T_HTTP_CODE_412[] = "Precondition Failed"; |
187 | | -static constexpr const char T_HTTP_CODE_413[] = "Request Entity Too Large"; |
188 | | -static constexpr const char T_HTTP_CODE_414[] = "Request-URI Too Large"; |
189 | | -static constexpr const char T_HTTP_CODE_415[] = "Unsupported Media Type"; |
190 | | -static constexpr const char T_HTTP_CODE_416[] = "Requested Range Not Satisfiable"; |
191 | | -static constexpr const char T_HTTP_CODE_417[] = "Expectation Failed"; |
192 | | -static constexpr const char T_HTTP_CODE_429[] = "Too Many Requests"; |
193 | | -static constexpr const char T_HTTP_CODE_500[] = "Internal Server Error"; |
194 | | -static constexpr const char T_HTTP_CODE_501[] = "Not Implemented"; |
195 | | -static constexpr const char T_HTTP_CODE_502[] = "Bad Gateway"; |
196 | | -static constexpr const char T_HTTP_CODE_503[] = "Service Unavailable"; |
197 | | -static constexpr const char T_HTTP_CODE_504[] = "Gateway Time-out"; |
198 | | -static constexpr const char T_HTTP_CODE_505[] = "HTTP Version Not Supported"; |
199 | | -static constexpr const char T_HTTP_CODE_ANY[] = "Unknown code"; |
| 176 | +// Response codes - using DECLARE_STR macro for platform-specific storage |
| 177 | +DECLARE_STR(T_HTTP_CODE_100, "Continue"); |
| 178 | +DECLARE_STR(T_HTTP_CODE_101, "Switching Protocols"); |
| 179 | +DECLARE_STR(T_HTTP_CODE_200, "OK"); |
| 180 | +DECLARE_STR(T_HTTP_CODE_201, "Created"); |
| 181 | +DECLARE_STR(T_HTTP_CODE_202, "Accepted"); |
| 182 | +DECLARE_STR(T_HTTP_CODE_203, "Non-Authoritative Information"); |
| 183 | +DECLARE_STR(T_HTTP_CODE_204, "No Content"); |
| 184 | +DECLARE_STR(T_HTTP_CODE_205, "Reset Content"); |
| 185 | +DECLARE_STR(T_HTTP_CODE_206, "Partial Content"); |
| 186 | +DECLARE_STR(T_HTTP_CODE_300, "Multiple Choices"); |
| 187 | +DECLARE_STR(T_HTTP_CODE_301, "Moved Permanently"); |
| 188 | +DECLARE_STR(T_HTTP_CODE_302, "Found"); |
| 189 | +DECLARE_STR(T_HTTP_CODE_303, "See Other"); |
| 190 | +DECLARE_STR(T_HTTP_CODE_304, "Not Modified"); |
| 191 | +DECLARE_STR(T_HTTP_CODE_305, "Use Proxy"); |
| 192 | +DECLARE_STR(T_HTTP_CODE_307, "Temporary Redirect"); |
| 193 | +DECLARE_STR(T_HTTP_CODE_400, "Bad Request"); |
| 194 | +DECLARE_STR(T_HTTP_CODE_401, "Unauthorized"); |
| 195 | +DECLARE_STR(T_HTTP_CODE_402, "Payment Required"); |
| 196 | +DECLARE_STR(T_HTTP_CODE_403, "Forbidden"); |
| 197 | +DECLARE_STR(T_HTTP_CODE_404, "Not Found"); |
| 198 | +DECLARE_STR(T_HTTP_CODE_405, "Method Not Allowed"); |
| 199 | +DECLARE_STR(T_HTTP_CODE_406, "Not Acceptable"); |
| 200 | +DECLARE_STR(T_HTTP_CODE_407, "Proxy Authentication Required"); |
| 201 | +DECLARE_STR(T_HTTP_CODE_408, "Request Time-out"); |
| 202 | +DECLARE_STR(T_HTTP_CODE_409, "Conflict"); |
| 203 | +DECLARE_STR(T_HTTP_CODE_410, "Gone"); |
| 204 | +DECLARE_STR(T_HTTP_CODE_411, "Length Required"); |
| 205 | +DECLARE_STR(T_HTTP_CODE_412, "Precondition Failed"); |
| 206 | +DECLARE_STR(T_HTTP_CODE_413, "Request Entity Too Large"); |
| 207 | +DECLARE_STR(T_HTTP_CODE_414, "Request-URI Too Large"); |
| 208 | +DECLARE_STR(T_HTTP_CODE_415, "Unsupported Media Type"); |
| 209 | +DECLARE_STR(T_HTTP_CODE_416, "Requested Range Not Satisfiable"); |
| 210 | +DECLARE_STR(T_HTTP_CODE_417, "Expectation Failed"); |
| 211 | +DECLARE_STR(T_HTTP_CODE_429, "Too Many Requests"); |
| 212 | +DECLARE_STR(T_HTTP_CODE_500, "Internal Server Error"); |
| 213 | +DECLARE_STR(T_HTTP_CODE_501, "Not Implemented"); |
| 214 | +DECLARE_STR(T_HTTP_CODE_502, "Bad Gateway"); |
| 215 | +DECLARE_STR(T_HTTP_CODE_503, "Service Unavailable"); |
| 216 | +DECLARE_STR(T_HTTP_CODE_504, "Gateway Time-out"); |
| 217 | +DECLARE_STR(T_HTTP_CODE_505, "HTTP Version Not Supported"); |
| 218 | +DECLARE_STR(T_HTTP_CODE_ANY, "Unknown code"); |
200 | 219 |
|
201 | 220 | static constexpr const char *T_only_once_headers[] = { |
202 | 221 | T_Accept_Ranges, T_Content_Length, T_Content_Type, T_Connection, T_CORS_ACAC, T_CORS_ACAH, T_CORS_ACAM, T_CORS_ACAO, |
|
0 commit comments