Subversion Repositories ESP8266_P1_Meter

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 raymond 1
// SPDX-License-Identifier: LGPL-3.0-or-later
2
// Copyright 2016-2026 Hristo Gochkov, Mathieu Carbou, Emil Muratov, Will Miles
3
 
4
#pragma once
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
 
25
namespace asyncsrv {
26
 
27
#ifdef ARDUINO
28
using ::emptyString;
29
#else
30
inline const String emptyString{};
31
#endif
32
 
33
static constexpr const char empty[] = "";
34
 
35
static constexpr const char T__opaque[] = "\", opaque=\"";
36
static constexpr const char T_100_CONTINUE[] = "100-continue";
37
static constexpr const char T_13[] = "13";
38
static constexpr const char T_ACCEPT[] = "Accept";
39
static constexpr const char T_Accept_Ranges[] = "Accept-Ranges";
40
static constexpr const char T_attachment[] = "attachment; filename=\"";
41
static constexpr const char T_AUTH[] = "Authorization";
42
static constexpr const char T_auth_nonce[] = "\", qop=\"auth\", nonce=\"";
43
static constexpr const char T_BASIC[] = "Basic";
44
static constexpr const char T_BASIC_REALM[] = "Basic realm=\"";
45
static constexpr const char T_BEARER[] = "Bearer";
46
static constexpr const char T_BODY[] = "body";
47
static constexpr const char T_Cache_Control[] = "Cache-Control";
48
static constexpr const char T_chunked[] = "chunked";
49
static constexpr const char T_close[] = "close";
50
static constexpr const char T_cnonce[] = "cnonce";
51
static constexpr const char T_Connection[] = "Connection";
52
static constexpr const char T_Content_Disposition[] = "Content-Disposition";
53
static constexpr const char T_Content_Encoding[] = "Content-Encoding";
54
static constexpr const char T_Content_Length[] = "Content-Length";
55
static constexpr const char T_Content_Type[] = "Content-Type";
56
static constexpr const char T_Content_Location[] = "Content-Location";
57
static constexpr const char T_Cookie[] = "Cookie";
58
static constexpr const char T_CORS_ACAC[] = "Access-Control-Allow-Credentials";
59
static constexpr const char T_CORS_ACAH[] = "Access-Control-Allow-Headers";
60
static constexpr const char T_CORS_ACAM[] = "Access-Control-Allow-Methods";
61
static constexpr const char T_CORS_ACAO[] = "Access-Control-Allow-Origin";
62
static constexpr const char T_CORS_ACMA[] = "Access-Control-Max-Age";
63
static constexpr const char T_CORS_O[] = "Origin";
64
static constexpr const char T_data_[] = "data: ";
65
static constexpr const char T_Date[] = "Date";
66
static constexpr const char T_DIGEST[] = "Digest";
67
static constexpr const char T_DIGEST_[] = "Digest ";
68
static constexpr const char T_ETag[] = "ETag";
69
static constexpr const char T_event_[] = "event: ";
70
static constexpr const char T_EXPECT[] = "Expect";
71
static constexpr const char T_FALSE[] = "false";
72
static constexpr const char T_filename[] = "filename";
73
static constexpr const char T_gzip[] = "gzip";
74
static constexpr const char T_Host[] = "host";
75
static constexpr const char T_HTTP_1_0[] = "HTTP/1.0";
76
static constexpr const char T_HTTP_100_CONT[] = "HTTP/1.1 100 Continue\r\n\r\n";
77
static constexpr const char T_id__[] = "id: ";
78
static constexpr const char T_IMS[] = "If-Modified-Since";
79
static constexpr const char T_INM[] = "If-None-Match";
80
static constexpr const char T_inline[] = "inline";
81
static constexpr const char T_keep_alive[] = "keep-alive";
82
static constexpr const char T_Last_Event_ID[] = "Last-Event-ID";
83
static constexpr const char T_Last_Modified[] = "Last-Modified";
84
static constexpr const char T_LOCATION[] = "Location";
85
static constexpr const char T_LOGIN_REQ[] = "Login Required";
86
static constexpr const char T_MULTIPART_[] = "multipart/";
87
static constexpr const char T_name[] = "name";
88
static constexpr const char T_nc[] = "nc";
89
static constexpr const char T_no_cache[] = "no-cache";
90
static constexpr const char T_nonce[] = "nonce";
91
static constexpr const char T_none[] = "none";
92
static constexpr const char T_opaque[] = "opaque";
93
static constexpr const char T_qop[] = "qop";
94
static constexpr const char T_realm[] = "realm";
95
static constexpr const char T_realm__[] = "realm=\"";
96
static constexpr const char T_response[] = "response";
97
static constexpr const char T_retry_[] = "retry: ";
98
static constexpr const char T_retry_after[] = "Retry-After";
99
static constexpr const char T_nn[] = "\n\n";
100
static constexpr const char T_rn[] = "\r\n";
101
static constexpr const char T_rnrn[] = "\r\n\r\n";
102
static constexpr const char T_Server[] = "Server";
103
static constexpr const char T_Transfer_Encoding[] = "Transfer-Encoding";
104
static constexpr const char T_TRUE[] = "true";
105
static constexpr const char T_UPGRADE[] = "Upgrade";
106
static constexpr const char T_uri[] = "uri";
107
static constexpr const char T_username[] = "username";
108
static constexpr const char T_WS[] = "websocket";
109
static constexpr const char T_WWW_AUTH[] = "WWW-Authenticate";
110
static constexpr const char T_X_Expected_Entity_Length[] = "X-Expected-Entity-Length";
111
 
112
// HTTP Methods
113
static constexpr const char T_GET[] = "GET";
114
static constexpr const char T_POST[] = "POST";
115
static constexpr const char T_PUT[] = "PUT";
116
static constexpr const char T_DELETE[] = "DELETE";
117
static constexpr const char T_PATCH[] = "PATCH";
118
static constexpr const char T_HEAD[] = "HEAD";
119
static constexpr const char T_OPTIONS[] = "OPTIONS";
120
static constexpr const char T_PROPFIND[] = "PROPFIND";
121
static constexpr const char T_LOCK[] = "LOCK";
122
static constexpr const char T_UNLOCK[] = "UNLOCK";
123
static constexpr const char T_PROPPATCH[] = "PROPPATCH";
124
static constexpr const char T_MKCOL[] = "MKCOL";
125
static constexpr const char T_MOVE[] = "MOVE";
126
static constexpr const char T_COPY[] = "COPY";
127
static constexpr const char T_UNKNOWN[] = "UNKNOWN";
128
static constexpr const char T_CONNECT[] = "CONNECT";
129
static constexpr const char T_TRACE[] = "TRACE";
130
static constexpr const char T_SEARCH[] = "SEARCH";
131
static constexpr const char T_BIND[] = "BIND";
132
static constexpr const char T_REBIND[] = "REBIND";
133
static constexpr const char T_UNBIND[] = "UNBIND";
134
static constexpr const char T_ACL[] = "ACL";
135
static constexpr const char T_PURGE[] = "PURGE";
136
static constexpr const char T_LINK[] = "LINK";
137
static constexpr const char T_UNLINK[] = "UNLINK";
138
 
139
// Req content types
140
static constexpr const char T_RCT_NOT_USED[] = "RCT_NOT_USED";
141
static constexpr const char T_RCT_DEFAULT[] = "RCT_DEFAULT";
142
static constexpr const char T_RCT_HTTP[] = "RCT_HTTP";
143
static constexpr const char T_RCT_WS[] = "RCT_WS";
144
static constexpr const char T_RCT_EVENT[] = "RCT_EVENT";
145
static constexpr const char T_ERROR[] = "ERROR";
146
 
147
// extensions & MIME-Types
148
static constexpr const char T__avif[] = ".avif";    // AVIF: Highly compressed images. Compatible with all modern browsers.
149
static constexpr const char T__csv[] = ".csv";      // CSV: Data logging and configuration
150
static constexpr const char T__css[] = ".css";      // CSS: Styling for web interfaces
151
static constexpr const char T__gif[] = ".gif";      // GIF: Simple animations. Legacy support
152
static constexpr const char T__gz[] = ".gz";        // GZ: compressed files
153
static constexpr const char T__htm[] = ".htm";      // HTM: Web interface files
154
static constexpr const char T__html[] = ".html";    // HTML: Web interface files
155
static constexpr const char T__ico[] = ".ico";      // ICO: Favicons, system icons. Legacy support
156
static constexpr const char T__jpg[] = ".jpg";      // JPEG/JPG: Photos. Legacy support
157
static constexpr const char T__js[] = ".js";        // JavaScript: Interactive functionality
158
static constexpr const char T__json[] = ".json";    // JSON: Data exchange format
159
static constexpr const char T__mp4[] = ".mp4";      // MP4: Proprietary format. Worse compression than WEBM.
160
static constexpr const char T__mjs[] = ".mjs";      // MJS: JavaScript module format
161
static constexpr const char T__opus[] = ".opus";    // OPUS: High compression audio format
162
static constexpr const char T__pdf[] = ".pdf";      // PDF: Universal document format
163
static constexpr const char T__png[] = ".png";      // PNG: Icons, logos, transparency. Legacy support
164
static constexpr const char T__svg[] = ".svg";      // SVG: Vector graphics, icons (scalable, tiny file sizes)
165
static constexpr const char T__ttf[] = ".ttf";      // TTF: Font file. Legacy support
166
static constexpr const char T__txt[] = ".txt";      // TXT: Plain text files
167
static constexpr const char T__webm[] = ".webm";    // WebM: Video. Open source, optimized for web. Compatible with all modern browsers.
168
static constexpr const char T__webp[] = ".webp";    // WebP: Highly compressed images. Compatible with all modern browsers.
169
static constexpr const char T__woff[] = ".woff";    // WOFF: Font file. Legacy support
170
static constexpr const char T__woff2[] = ".woff2";  // WOFF2: Better compression. Compatible with all modern browsers.
171
static constexpr const char T__xml[] = ".xml";      // XML: Configuration and data files
172
static constexpr const char T_application_javascript[] = "application/javascript";  // Obsolete type for JavaScript
173
static constexpr const char T_application_json[] = "application/json";
174
static constexpr const char T_application_msgpack[] = "application/msgpack";
175
static constexpr const char T_application_octet_stream[] = "application/octet-stream";
176
static constexpr const char T_application_pdf[] = "application/pdf";
177
static constexpr const char T_app_xform_urlencoded[] = "application/x-www-form-urlencoded";
178
static constexpr const char T_audio_opus[] = "audio/opus";
179
static constexpr const char T_font_ttf[] = "font/ttf";
180
static constexpr const char T_font_woff[] = "font/woff";
181
static constexpr const char T_font_woff2[] = "font/woff2";
182
static constexpr const char T_image_avif[] = "image/avif";
183
static constexpr const char T_image_gif[] = "image/gif";
184
static constexpr const char T_image_jpeg[] = "image/jpeg";
185
static constexpr const char T_image_png[] = "image/png";
186
static constexpr const char T_image_svg_xml[] = "image/svg+xml";
187
static constexpr const char T_image_webp[] = "image/webp";
188
static constexpr const char T_image_x_icon[] = "image/x-icon";
189
static constexpr const char T_text_css[] = "text/css";
190
static constexpr const char T_text_csv[] = "text/csv";
191
static constexpr const char T_text_event_stream[] = "text/event-stream";
192
static constexpr const char T_text_html[] = "text/html";
193
static constexpr const char T_text_javascript[] = "text/javascript";
194
static constexpr const char T_text_plain[] = "text/plain";
195
static constexpr const char T_text_xml[] = "text/xml";
196
static constexpr const char T_video_mp4[] = "video/mp4";
197
static constexpr const char T_video_webm[] = "video/webm";
198
 
199
// Response codes - using DECLARE_STR macro for platform-specific storage
200
DECLARE_STR(T_HTTP_CODE_100, "Continue");
201
DECLARE_STR(T_HTTP_CODE_101, "Switching Protocols");
202
DECLARE_STR(T_HTTP_CODE_200, "OK");
203
DECLARE_STR(T_HTTP_CODE_201, "Created");
204
DECLARE_STR(T_HTTP_CODE_202, "Accepted");
205
DECLARE_STR(T_HTTP_CODE_203, "Non-Authoritative Information");
206
DECLARE_STR(T_HTTP_CODE_204, "No Content");
207
DECLARE_STR(T_HTTP_CODE_205, "Reset Content");
208
DECLARE_STR(T_HTTP_CODE_206, "Partial Content");
209
DECLARE_STR(T_HTTP_CODE_207, "Multi Status");
210
DECLARE_STR(T_HTTP_CODE_300, "Multiple Choices");
211
DECLARE_STR(T_HTTP_CODE_301, "Moved Permanently");
212
DECLARE_STR(T_HTTP_CODE_302, "Found");
213
DECLARE_STR(T_HTTP_CODE_303, "See Other");
214
DECLARE_STR(T_HTTP_CODE_304, "Not Modified");
215
DECLARE_STR(T_HTTP_CODE_305, "Use Proxy");
216
DECLARE_STR(T_HTTP_CODE_307, "Temporary Redirect");
217
DECLARE_STR(T_HTTP_CODE_400, "Bad Request");
218
DECLARE_STR(T_HTTP_CODE_401, "Unauthorized");
219
DECLARE_STR(T_HTTP_CODE_402, "Payment Required");
220
DECLARE_STR(T_HTTP_CODE_403, "Forbidden");
221
DECLARE_STR(T_HTTP_CODE_404, "Not Found");
222
DECLARE_STR(T_HTTP_CODE_405, "Method Not Allowed");
223
DECLARE_STR(T_HTTP_CODE_406, "Not Acceptable");
224
DECLARE_STR(T_HTTP_CODE_407, "Proxy Authentication Required");
225
DECLARE_STR(T_HTTP_CODE_408, "Request Time-out");
226
DECLARE_STR(T_HTTP_CODE_409, "Conflict");
227
DECLARE_STR(T_HTTP_CODE_410, "Gone");
228
DECLARE_STR(T_HTTP_CODE_411, "Length Required");
229
DECLARE_STR(T_HTTP_CODE_412, "Precondition Failed");
230
DECLARE_STR(T_HTTP_CODE_413, "Request Entity Too Large");
231
DECLARE_STR(T_HTTP_CODE_414, "Request-URI Too Large");
232
DECLARE_STR(T_HTTP_CODE_415, "Unsupported Media Type");
233
DECLARE_STR(T_HTTP_CODE_416, "Requested Range Not Satisfiable");
234
DECLARE_STR(T_HTTP_CODE_417, "Expectation Failed");
235
DECLARE_STR(T_HTTP_CODE_429, "Too Many Requests");
236
DECLARE_STR(T_HTTP_CODE_500, "Internal Server Error");
237
DECLARE_STR(T_HTTP_CODE_501, "Not Implemented");
238
DECLARE_STR(T_HTTP_CODE_502, "Bad Gateway");
239
DECLARE_STR(T_HTTP_CODE_503, "Service Unavailable");
240
DECLARE_STR(T_HTTP_CODE_504, "Gateway Time-out");
241
DECLARE_STR(T_HTTP_CODE_505, "HTTP Version Not Supported");
242
DECLARE_STR(T_HTTP_CODE_507, "Insufficient Storage");
243
DECLARE_STR(T_HTTP_CODE_ANY, "Unknown code");
244
 
245
static constexpr const char *T_only_once_headers[] = {
246
  T_Accept_Ranges,     T_Content_Length,   T_Content_Type, T_Connection, T_CORS_ACAC, T_CORS_ACAH,     T_CORS_ACAM, T_CORS_ACAO,
247
  T_CORS_ACMA,         T_CORS_O,           T_Date,         T_DIGEST,     T_ETag,      T_Last_Modified, T_LOCATION,  T_retry_after,
248
  T_Transfer_Encoding, T_Content_Location, T_Server,       T_WWW_AUTH
249
};
250
static constexpr size_t T_only_once_headers_len = sizeof(T_only_once_headers) / sizeof(T_only_once_headers[0]);
251
static constexpr size_t T__GZ_LEN = sizeof(T__gz) - 1;
252
}  // namespace asyncsrv