34 { 12,
"UNSUBSCRIBE" },
42WS_METHOD ws_method_from_str(
const char* str)
47 if (memcmp(p->txt, str, p->sz) == 0)
48 return (WS_METHOD)(p - ws_method_table);
51 return WS_METHOD_UNKNOWN;
54const char* ws_method_to_str(WS_METHOD m)
56 return ws_method_table[(unsigned)m].txt;
62 { 34,
"application/x-www-form-urlencoded" },
63 { 25,
"application/octet-stream" },
68WS_CTYPE ws_ctype_from_str(
const char* str)
73 if (memcmp(p->txt, str, p->sz) == 0)
74 return (WS_CTYPE)(p - ws_ctype_table);
77 return WS_CTYPE_UNKNOWN;
80const char* ws_ctype_to_str(WS_CTYPE t)
82 return ws_ctype_table[(unsigned)t].txt;
93WS_CENCODING ws_cencoding_from_str(
const char* str)
98 if (memcmp(p->txt, str, p->sz) == 0)
99 return (WS_CENCODING)(p - ws_cencoding_table);
102 return WS_CENCODING_UNKNOWN;
105const char* ws_cencoding_to_str(WS_CENCODING e)
107 return ws_cencoding_table[(unsigned)e].txt;
110typedef struct {
unsigned sz;
const char* txt;
const char* upper_txt; }
WS_HEADER_TABLE;
112 { 7,
"Accept",
"ACCEPT" },
113 { 15,
"Accept-Charset",
"ACCEPT-CHARSET" },
114 { 16,
"Accept-Encoding",
"ACCEPT-ENCODING" },
115 { 16,
"Accept-Language",
"ACCEPT-LANGUAGE" },
116 { 14,
"Accept-Ranges",
"ACCEPT-RANGES" },
117 { 14,
"Authorization",
"AUTHORIZATION" },
118 { 14,
"Cache-Control",
"CACHE-CONTROL" },
119 { 11,
"Connection",
"CONNECTION" },
120 { 17,
"Content-Encoding",
"CONTENT-ENCODING" },
121 { 15,
"Content-Length",
"CONTENT-LENGTH" },
122 { 17,
"Content-Location",
"CONTENT-LOCATION" },
123 { 15,
"Content-Range",
"CONTENT-RANGE" },
124 { 13,
"Content-Type",
"CONTENT-TYPE" },
125 { 5,
"ETag",
"ETAG" },
126 { 8,
"Expires",
"EXPIRES" },
127 { 5,
"Host",
"HOST" },
128 { 9,
"If-Match",
"IF-MATCH" },
129 { 14,
"If-None-Match",
"IF-NONE-MATCH" },
130 { 11,
"Keep-Alive",
"KEEP-ALIVE" },
131 { 14,
"Last-Modified",
"LAST-MODIFIED" },
132 { 9,
"Location",
"LOCATION" },
133 { 6,
"Range",
"RANGE" },
134 { 7,
"Server",
"SERVER" },
135 { 18,
"Transfer-Encoding",
"TRANSFER-ENCODING" },
136 { 11,
"User-Agent",
"USER-AGENT" },
137 { 17,
"WWW-Authenticate",
"WWW-AUTHENTICATE" },
138 { 16,
"X-Forwarded-For",
"X-FORWARDED-FOR" },
139 { 17,
"X-Forwarded-Host",
"X-FORWARDED-HOST" },
140 { 18,
"X-Forwarded-Proto",
"X-FORWARDED-PROTO" },
141 { 10,
"X-Real-IP",
"X-REAL-IP" },
145WS_HEADER ws_header_from_upperstr(
const char* upperstr)
150 if (memcmp(p->upper_txt, upperstr, p->sz) == 0)
151 return (WS_HEADER)(p - ws_header_table);
154 return WS_HEADER_UNKNOWN;
157const char* ws_header_to_str(WS_HEADER h)
159 return ws_header_table[(unsigned)h].txt;
162const char* ws_header_to_upperstr(WS_HEADER h)
164 return ws_header_table[(unsigned)h].upper_txt;
167typedef struct {
int num;
unsigned sz;
const char* numstr;
const char* msgstr; }
WS_STATUS_TABLE;
170 { 200, 4,
"200",
"OK" },
171 { 201, 4,
"201",
"Created" },
172 { 202, 4,
"202",
"Accepted" },
173 { 203, 4,
"203",
"Non-Authoritative Information" },
174 { 204, 4,
"204",
"No content" },
175 { 205, 4,
"205",
"Reset Content" },
176 { 206, 4,
"206",
"Partial content" },
177 { 207, 4,
"207",
"Multi-Status" },
178 { 208, 4,
"208",
"Already Reported" },
181 { 301, 4,
"301",
"Moved permanently" },
182 { 302, 4,
"302",
"Moved temporarily" },
183 { 303, 4,
"303",
"See Other" },
184 { 304, 4,
"304",
"Not modified" },
185 { 305, 4,
"305",
"Use Proxy" },
186 { 306, 4,
"306",
"RESERVED" },
187 { 307, 4,
"307",
"Temporary Redirect" },
188 { 308, 4,
"308",
"Permanent Redirect" },
191 { 400, 4,
"400",
"Bad request" },
192 { 401, 4,
"401",
"Unauthorized" },
193 { 402, 4,
"402",
"Payment Required" },
194 { 403, 4,
"403",
"Forbidden" },
195 { 404, 4,
"404",
"Not found" },
196 { 405, 4,
"405",
"Method Not Allowed" },
197 { 406, 4,
"406",
"Not Acceptable" },
198 { 407, 4,
"407",
"Proxy Authentication Required" },
199 { 408, 4,
"408",
"Request Timeout" },
200 { 409, 4,
"409",
"Conflict" },
201 { 410, 4,
"410",
"Gone" },
202 { 411, 4,
"411",
"Length Required" },
203 { 412, 4,
"412",
"Precondition Failed" },
204 { 413, 4,
"413",
"Content Too Large" },
205 { 414, 4,
"414",
"URI Too Long" },
206 { 415, 4,
"415",
"Unsupported Media Type" },
207 { 416, 4,
"416",
"Range Not Satisfiable" },
208 { 417, 4,
"417",
"Expectation Failed" },
209 { 418, 4,
"418",
"I'm a teapot" },
211 { 421, 4,
"421",
"Misdirected Request" },
212 { 422, 4,
"422",
"Unprocessable Content" },
213 { 423, 4,
"423",
"Locked" },
214 { 424, 4,
"424",
"Failed Dependency" },
215 { 425, 4,
"425",
"Too Early" },
216 { 426, 4,
"426",
"Upgrade Required" },
218 { 428, 4,
"428",
"Precondition Required" },
219 { 429, 4,
"429",
"Too Many Requests" },
221 { 431, 4,
"431",
"Request Header Fields Too Large" },
223 { 451, 4,
"451",
"Unavailable For Legal Reasons" },
226 { 500, 4,
"500",
"Internal server error" },
227 { 501, 4,
"501",
"Not implemented" },
228 { 502, 4,
"502",
"Bad gateway" },
229 { 503, 4,
"503",
"Service unavailable" },
230 { 504, 4,
"504",
"Gateway Timeout" },
231 { 505, 4,
"505",
"HTTP Version Not Supported" },
232 { 506, 4,
"506",
"Variant Also Negotiates" },
233 { 507, 4,
"507",
"Insufficient Storage" },
234 { 508, 4,
"508",
"Loop Detected" },
236 { 510, 4,
"510",
"Not Extended" },
237 { 511, 4,
"511",
"Network Authentication Required" },
240 { 100, 4,
"100",
"Continue" },
241 { 101, 4,
"101",
"Switching Protocols" },
242 { 102, 4,
"102",
"Processing" },
243 { 103, 4,
"103",
"Early Hints" },
245 { 0, 0, NULL , NULL }
249WS_STATUS ws_status_from_num(
int num)
255 return (WS_STATUS)(p - ws_status_table);
258 return WS_STATUS_UNKNOWN;
261WS_STATUS ws_status_from_numstr(
const char* numstr)
266 if (memcmp(p->numstr, numstr, p->sz) == 0)
267 return (WS_STATUS)(p - ws_status_table);
270 return WS_STATUS_UNKNOWN;
273int ws_status_to_num(WS_STATUS s)
275 return ws_status_table[(unsigned) s].num;
278const char* ws_status_to_numstr(WS_STATUS s)
280 return ws_status_table[(unsigned) s].numstr;
283const char* ws_status_to_msgstr(WS_STATUS s)
285 return ws_status_table[(unsigned) s].msgstr;