39 #ifdef MHD_LINUX_SOLARIS_SENDFILE 40 #include <sys/sendfile.h> 42 #if defined(HAVE_FREEBSD_SENDFILE) || defined(HAVE_DARWIN_SENDFILE) 43 #include <sys/types.h> 44 #include <sys/socket.h> 55 #define HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n" 65 #define REQUEST_TOO_BIG "<html><head><title>Request too big</title></head><body>Your HTTP header was too big for the memory constraints of this webserver.</body></html>" 67 #define REQUEST_TOO_BIG "" 78 #define REQUEST_LACKS_HOST "<html><head><title>"Host:" header required</title></head><body>In HTTP 1.1, requests must include a "Host:" header, and your HTTP 1.1 request lacked such a header.</body></html>" 80 #define REQUEST_LACKS_HOST "" 91 #define REQUEST_MALFORMED "<html><head><title>Request malformed</title></head><body>Your HTTP request was syntactically incorrect.</body></html>" 93 #define REQUEST_MALFORMED "" 103 #define INTERNAL_ERROR "<html><head><title>Internal server error</title></head><body>Please ask the developer of this Web server to carefully read the GNU libmicrohttpd documentation about connection management and blocking.</body></html>" 105 #define INTERNAL_ERROR "" 112 #define DEBUG_CLOSE MHD_NO 117 #define DEBUG_SEND_DATA MHD_NO 123 #define MHD_SENFILE_CHUNK_ (0x20000) 128 #define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000) 130 #ifdef HAVE_FREEBSD_SENDFILE 135 static int freebsd_sendfile_flags_;
140 static int freebsd_sendfile_flags_thd_p_c_;
146 MHD_conn_init_static_ (
void)
152 long sys_page_size = sysconf (_SC_PAGESIZE);
153 if (0 > sys_page_size)
155 freebsd_sendfile_flags_ = SF_NODISKIO;
156 freebsd_sendfile_flags_thd_p_c_ = SF_NODISKIO;
160 freebsd_sendfile_flags_ =
162 freebsd_sendfile_flags_thd_p_c_ =
214 else if (i > (
size_t)ret)
268 else if (i > (
size_t)ret)
275 #if defined(_MHD_HAVE_SENDFILE) 289 #ifndef HAVE_SENDFILE64 290 const uint64_t max_off_t = (uint64_t)
OFF_T_MAX;
292 const uint64_t max_off_t = (uint64_t)OFF64_T_MAX;
294 #ifdef MHD_LINUX_SOLARIS_SENDFILE 295 #ifndef HAVE_SENDFILE64 301 #ifdef HAVE_FREEBSD_SENDFILE 305 #ifdef HAVE_DARWIN_SENDFILE 310 size_t send_size = 0;
311 mhd_assert (MHD_resp_sender_sendfile == connection->resp_sender);
317 send_size = (left > chunk_size) ? chunk_size : (
size_t) left;
318 if (max_off_t < offsetu64)
320 connection->resp_sender = MHD_resp_sender_std;
323 #ifdef MHD_LINUX_SOLARIS_SENDFILE 324 #ifndef HAVE_SENDFILE64 325 offset = (off_t) offsetu64;
331 offset = (off64_t) offsetu64;
350 #ifdef HAVE_LINUX_SENDFILE 359 connection->resp_sender = MHD_resp_sender_std;
362 if ( (EAFNOSUPPORT == err) ||
364 (EOPNOTSUPP == err) )
366 connection->resp_sender = MHD_resp_sender_std;
369 if ( (ENOTCONN == err) ||
378 else if (send_size > (
size_t)ret)
381 #elif defined(HAVE_FREEBSD_SENDFILE) 383 flags = used_thr_p_c ?
384 freebsd_sendfile_flags_thd_p_c_ : freebsd_sendfile_flags_;
386 if (0 != sendfile (file_fd,
401 return (ssize_t)sent_bytes;
407 connection->resp_sender = MHD_resp_sender_std;
412 ret = (ssize_t)sent_bytes;
413 #elif defined(HAVE_DARWIN_SENDFILE) 414 len = (off_t)send_size;
415 if (0 != sendfile (file_fd,
434 if (ENOTCONN == err ||
437 if (ENOTSUP == err ||
441 connection->resp_sender = MHD_resp_sender_std;
479 #if defined(TCP_CORK) || defined(TCP_PUSH) 498 #if defined(TCP_CORK) || defined(TCP_NOPUSH) 500 #if defined(TCP_NODELAY) 506 #if defined(TCP_NOPUSH) && !defined(TCP_CORK) 508 res = (0 == setsockopt (connection->
socket_fd,
511 (
const void *) &on_val,
514 #if defined(TCP_NODELAY) 517 res &= (0 == setsockopt (connection->
socket_fd,
520 (
const void *) &off_val,
525 #if defined(TCP_NODELAY) 529 (void) setsockopt (connection->
socket_fd,
532 (
const void *) &off_val,
536 res = (0 == setsockopt (connection->
socket_fd,
539 (
const void *) &on_val,
557 #if defined(TCP_NODELAY) 560 #if defined(TCP_CORK) || defined(TCP_NOPUSH) 566 #if defined(TCP_CORK) 568 res &= (0 == setsockopt (connection->
socket_fd,
571 (
const void *) &off_val,
575 #if defined(TCP_NODELAY) 577 res &= (0 == setsockopt (connection->
socket_fd,
580 (
const void *) &on_val,
584 #if defined(TCP_NOPUSH) && !defined(TCP_CORK) 586 res &= (0 == setsockopt (connection->
socket_fd,
589 (
const void *) &off_val,
611 #if defined(TCP_NOPUSH) && !defined(TCP_CORK) 615 if (
NULL == connection)
618 #if defined(TCP_NOPUSH) && !defined(TCP_CORK) 640 #if defined(TCP_NODELAY) 643 #if defined(TCP_CORK) 645 socklen_t param_size =
sizeof (cork_val);
648 #if defined(TCP_CORK) 652 if ( (0 != getsockopt (connection->
socket_fd,
658 res &= (0 == setsockopt (connection->
socket_fd,
661 (
const void *) &off_val,
664 #elif defined(TCP_NOPUSH) 668 res &= (0 == setsockopt (connection->
socket_fd,
671 (
const void *) &off_val,
676 res &= (0 == setsockopt (connection->
socket_fd,
679 (
const void *) &off_val,
709 if (
NULL == connection)
716 if ( (
NULL != iterator) &&
717 (
MHD_YES != iterator (iterator_cls,
765 pos->
header = (
char *) key;
801 if (
NULL == connection)
862 #define MHD_lookup_header_s_token_ci(c,h,tkn) \ 863 MHD_lookup_header_token_ci((c),(h),(tkn),MHD_STATICSTR_LEN_(tkn)) 959 #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) 974 struct MHD_UpgradeResponseHandle *urh = connection->urh;
985 (0 != epoll_ctl (daemon->epoll_upgrade_fd,
990 MHD_PANIC (
_(
"Failed to remove FD from epoll set\n"));
992 if (urh->in_eready_list)
995 daemon->eready_urh_tail,
997 urh->in_eready_list =
false;
1004 (0 != epoll_ctl (daemon->epoll_upgrade_fd,
1009 MHD_PANIC (
_(
"Failed to remove FD from epoll set\n"));
1014 shutdown (urh->mhd.socket, SHUT_RDWR);
1036 #ifdef HAVE_MESSAGES 1038 MHD_DLOG (connection->
daemon,
1052 #ifdef HAVE_MESSAGES 1053 #define CONNECTION_CLOSE_ERROR(c, emsg) connection_close_error (c, emsg) 1055 #define CONNECTION_CLOSE_ERROR(c, emsg) connection_close_error (c, NULL) 1088 #if defined(_MHD_HAVE_SENDFILE) 1089 if (MHD_resp_sender_sendfile == connection->resp_sender)
1113 _(
"Closing connection (application reported error generating data)\n"));
1153 2 * (0xFFFFFF +
sizeof(cbuf) + 2));
1162 _(
"Closing connection (out of memory)\n"));
1169 while (
NULL == buf);
1183 const size_t data_write_offset
1186 ret = response->
data_size - data_write_offset;
1190 &response->
data[data_write_offset],
1207 _(
"Closing connection (application error generating response)\n"));
1230 cblen = MHD_snprintf_(cbuf,
1233 (
unsigned int) ret);
1236 memcpy (&connection->
write_buffer[sizeof (cbuf) - cblen],
1239 memcpy (&connection->
write_buffer[sizeof (cbuf) + ret],
1318 static const char *
const days[] = {
1319 "Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat" 1321 static const char *
const mons[] = {
1322 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
1323 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" 1327 #if !defined(HAVE_C11_GMTIME_S) && !defined(HAVE_W32_GMTIME_S) && !defined(HAVE_GMTIME_R) 1333 #if defined(HAVE_C11_GMTIME_S) 1334 if (
NULL == gmtime_s (&t,
1337 #elif defined(HAVE_W32_GMTIME_S) 1338 if (0 != gmtime_s (&now,
1341 #elif defined(HAVE_GMTIME_R) 1342 if (
NULL == gmtime_r(&t,
1351 MHD_snprintf_ (date,
1353 "Date: %3s, %02u %3s %04u %02u:%02u:%02u GMT\r\n",
1354 days[now.tm_wday % 7],
1355 (
unsigned int) now.tm_mday,
1356 mons[now.tm_mon % 12],
1357 (
unsigned int) (1900 + now.tm_year),
1358 (
unsigned int) now.tm_hour,
1359 (
unsigned int) now.tm_min,
1360 (
unsigned int) now.tm_sec);
1416 char content_length_buf[128];
1417 size_t content_length_len;
1420 const char *reason_phrase;
1422 bool client_requested_close;
1423 bool response_has_close;
1424 bool response_has_keepalive;
1425 const char *have_encoding;
1427 int must_add_chunked_encoding;
1428 int must_add_keep_alive;
1429 int must_add_content_length;
1430 int may_add_content_length;
1433 if (0 == connection->
version[0])
1448 MHD_snprintf_ (code,
1460 off = strlen (code);
1471 datelen = strlen (date);
1486 must_add_chunked_encoding =
MHD_NO;
1487 must_add_keep_alive =
MHD_NO;
1488 must_add_content_length =
MHD_NO;
1489 response_has_close =
false;
1490 switch (connection->
state)
1505 #ifdef UPGRADE_SUPPORT 1506 else if (
NULL != response->upgrade_handler)
1515 if (
NULL == have_encoding)
1516 may_add_content_length =
MHD_YES;
1518 may_add_content_length =
MHD_NO;
1520 #ifdef UPGRADE_SUPPORT
1521 (
NULL == response->upgrade_handler) &&
1523 (! response_has_close) &&
1524 (! client_requested_close) )
1535 if (
NULL == have_encoding)
1537 must_add_chunked_encoding =
MHD_YES;
1558 if (! response_has_close)
1564 if ( ( (client_requested_close) ||
1567 (! response_has_close) &&
1568 #ifdef UPGRADE_SUPPORT
1569 (
NULL == response->upgrade_handler) &&
1576 if ( (! may_add_content_length) &&
1578 (! response_has_close) )
1591 (may_add_content_length) &&
1612 = MHD_snprintf_ (content_length_buf,
1613 sizeof (content_length_buf),
1616 must_add_content_length =
MHD_YES;
1620 if ( (! response_has_keepalive) &&
1621 (! response_has_close) &&
1622 (
MHD_NO == must_add_close) &&
1624 #ifdef UPGRADE_SUPPORT
1625 (
NULL == response->upgrade_handler) &&
1628 must_add_keep_alive =
MHD_YES;
1631 response_has_keepalive =
false;
1640 if ( (must_add_close) || (response_has_close) )
1642 else if ( (must_add_keep_alive) || (response_has_keepalive) )
1648 if (must_add_keep_alive)
1650 if (must_add_chunked_encoding)
1652 if (must_add_content_length)
1653 size += content_length_len;
1654 mhd_assert (! (must_add_close && must_add_keep_alive) );
1655 mhd_assert (! (must_add_chunked_encoding && must_add_content_length) );
1661 (! ( (
MHD_YES == must_add_close) &&
1662 (response_has_keepalive) &&
1666 "Keep-Alive")) ) ) )
1667 size += strlen (pos->
header) + strlen (pos->
value) + 4;
1675 #ifdef HAVE_MESSAGES 1676 MHD_DLOG (connection->
daemon,
1677 "Not enough memory for write!\n");
1691 "Connection: close\r\n",
1695 if (must_add_keep_alive)
1699 "Connection: Keep-Alive\r\n",
1703 if (must_add_chunked_encoding)
1707 "Transfer-Encoding: chunked\r\n",
1711 if (must_add_content_length)
1716 content_length_len);
1717 off += content_length_len;
1723 (! ( (
MHD_YES == must_add_close) &&
1724 (response_has_keepalive) &&
1728 "Keep-Alive")) ) ) )
1729 off += MHD_snprintf_ (&
data[off],
1771 unsigned int status_code,
1772 const char *message)
1785 #ifdef HAVE_MESSAGES 1786 MHD_DLOG (connection->
daemon,
1787 _(
"Error processing request (HTTP response code is %u (`%s')). Closing connection.\n"),
1799 if (
NULL == response)
1813 _(
"Closing connection (failed to queue response)\n"));
1823 _(
"Closing connection (failed to create response header)\n"));
1846 #ifdef HTTPS_SUPPORT 1849 switch (connection->tls_state)
1855 if (0 == gnutls_record_get_direction (connection->tls_session))
1868 MHD_DLOG (connection->
daemon,
1869 _(
"In function %s handling connection at state: %s\n"),
1871 MHD_state_to_string (connection->
state));
1873 switch (connection->
state)
1982 #ifdef UPGRADE_SUPPORT 1983 case MHD_CONNECTION_UPGRADE:
2019 while ( (pos < connection->read_buffer_offset - 1) &&
2020 (
'\r' != rbuf[pos]) &&
2021 (
'\n' != rbuf[pos]) )
2024 (
'\n' != rbuf[pos]) )
2045 if ( (
'\r' == rbuf[pos]) &&
2046 (
'\n' == rbuf[pos + 1]) )
2079 #ifdef HAVE_MESSAGES 2080 MHD_DLOG (connection->
daemon,
2081 _(
"Not enough memory in pool to allocate header record!\n"));
2121 #ifdef HAVE_MESSAGES 2122 MHD_DLOG (connection->
daemon,
2123 _(
"Not enough memory in pool to parse cookies!\n"));
2140 while ( ((*sce) !=
'\0') &&
2147 while ( (*ekill ==
' ') &&
2169 while ( (
'\0' != semicolon[0]) &&
2171 ( (
';' != semicolon[0]) &&
2172 (
',' != semicolon[0]) ) ) )
2174 if (
'"' == semicolon[0])
2175 quotes = (quotes + 1) & 1;
2178 if (
'\0' == semicolon[0])
2180 if (
NULL != semicolon)
2182 semicolon[0] =
'\0';
2186 if ( (
'"' == equals[0]) &&
2187 (
'"' == equals[strlen (equals) - 1]) )
2189 equals[strlen (equals) - 1] =
'\0';
2222 unsigned int unused_num_headers;
2225 if (
NULL == (uri = memchr (line,
2230 connection->
method = line;
2234 while ( (
' ' == uri[0]) &&
2235 ( (
size_t)(uri - line) < line_len) )
2237 if ((
size_t)(uri - line) == line_len)
2250 http_version = line + line_len - 1;
2252 while ( (
' ' == http_version[0]) &&
2253 (http_version > uri) )
2256 while ( (
' ' != http_version[0]) &&
2257 (http_version > uri) )
2259 if (http_version > uri)
2262 http_version[0] =
'\0';
2263 connection->
version = http_version + 1;
2264 uri_len = http_version - uri;
2269 uri_len = line_len - (uri - line);
2273 (
NULL != memchr (uri,
2285 uri_len = strlen (uri);
2308 &unused_num_headers);
2314 connection->
url = curi;
2348 _(
"Application reported internal error, closing connection.\n"));
2376 size_t to_be_processed;
2377 size_t left_unprocessed;
2378 size_t processed_size;
2391 if ( (
'\r' == buffer_head[i]) ||
2392 (
'\n' == buffer_head[i]) )
2394 if ( (
'\r' == buffer_head[i]) ||
2395 (
'\n' == buffer_head[i]) )
2401 _(
"Received malformed HTTP request (bad chunked encoding). Closing connection.\n"));
2412 uint64_t cur_chunk_left;
2418 if (cur_chunk_left > available)
2419 to_be_processed = available;
2422 to_be_processed = (size_t)cur_chunk_left;
2423 if (available > to_be_processed)
2435 while (i < available)
2437 if ( (
'\r' == buffer_head[i]) ||
2438 (
'\n' == buffer_head[i]) ||
2439 (
';' == buffer_head[i]) )
2447 if (
';' == buffer_head[i])
2449 while (i < available)
2451 if ( (
'\r' == buffer_head[i]) ||
2452 (
'\n' == buffer_head[i]) )
2460 if ( (i + 1 >= available) &&
2463 (
'0' == buffer_head[0]) ) )
2466 malformed = (end_size >= 16);
2472 malformed = (end_size != num_dig);
2478 _(
"Received malformed HTTP request (bad chunked encoding). Closing connection.\n"));
2482 if ( (i < available) &&
2483 ( (
'\r' == buffer_head[i]) ||
2484 (
'\n' == buffer_head[i]) ) )
2516 to_be_processed = available;
2519 left_unprocessed = to_be_processed;
2533 _(
"Application reported internal error, closing connection.\n"));
2536 if (left_unprocessed > to_be_processed)
2540 #ifdef HAVE_MESSAGES
2541 ,
_(
"libmicrohttpd API violation")
2546 if (0 != left_unprocessed)
2549 #ifdef HAVE_MESSAGES 2556 _(
"WARNING: incomplete upload processing and connection not suspended may result in hung connection.\n"));
2559 processed_size = to_be_processed - left_unprocessed;
2563 buffer_head += processed_size;
2564 available -= processed_size;
2568 while (
MHD_YES == instant_retry);
2594 connection->
state = next_state;
2621 colon = strchr (line,
':');
2626 _(
"Received malformed line (no colon). Closing connection.\n"));
2636 white = strchr (line,
' ');
2637 if ( (
NULL != white) &&
2640 white = strchr (line,
'\t');
2641 if ( (
NULL != white) &&
2648 while ( (
'\0' != colon[0]) &&
2649 ( (
' ' == colon[0]) ||
2650 (
'\t' == colon[0]) ) )
2657 connection->
last = line;
2658 connection->
colon = colon;
2683 last = connection->
last;
2684 if ( (
' ' == line[0]) ||
2689 last_len = strlen (last);
2692 while ( (
' ' == tmp[0]) ||
2695 tmp_len = strlen (tmp);
2708 last_len + tmp_len + 1);
2716 memcpy (&last[last_len], tmp, tmp_len + 1);
2717 connection->
last = last;
2778 #ifdef HAVE_MESSAGES 2779 MHD_DLOG (connection->
daemon,
2780 _(
"Received HTTP 1.1 request without `Host' header.\n"));
2787 if (
NULL == response)
2791 _(
"Closing connection (failed to create response)\n"));
2802 _(
"Closing connection (failed to queue response)\n"));
2827 if ( (clen == end) ||
2831 #ifdef HAVE_MESSAGES 2832 MHD_DLOG (connection->
daemon,
2833 "Failed to parse `Content-Length' header. Closing connection.\n");
2895 #ifdef HTTPS_SUPPORT 2914 bytes_read = connection->
recv_cls (connection,
2928 _(
"Socket disconnected while reading request.\n"));
2934 _(
"Connection socket is closed due to error when reading request.\n"));
2938 if (0 == bytes_read)
2948 MHD_DLOG (connection->
daemon,
2949 _(
"In function %s handling connection at state: %s\n"),
2951 MHD_state_to_string (connection->
state));
2953 switch (connection->
state)
2973 #ifdef UPGRADE_SUPPORT 2974 case MHD_CONNECTION_UPGRADE:
3004 #ifdef HTTPS_SUPPORT 3016 MHD_DLOG (connection->
daemon,
3017 _(
"In function %s handling connection at state: %s\n"),
3019 MHD_state_to_string (connection->
state));
3021 switch (connection->
state)
3032 ret = connection->
send_cls (connection,
3041 #ifdef HAVE_MESSAGES 3042 MHD_DLOG (connection->
daemon,
3043 _(
"Failed to send data in request for %s.\n"),
3052 _(
"Sent 100 continue response: `%.*s'\n"),
3066 ret = connection->
send_cls (connection,
3076 _(
"Connection was closed while sending response headers.\n"));
3093 uint64_t data_write_offset;
3102 #if defined(_MHD_HAVE_SENDFILE) 3103 if (MHD_resp_sender_sendfile == connection->resp_sender)
3105 ret = sendfile_adapter (connection);
3114 if (data_write_offset > (uint64_t)
SIZE_MAX)
3116 ret = connection->
send_cls (connection,
3118 [(
size_t)data_write_offset],
3120 (
size_t)data_write_offset);
3124 _(
"Sent %d-byte DATA response: `%.*s'\n"),
3137 #ifdef HAVE_MESSAGES 3138 MHD_DLOG (connection->
daemon,
3139 _(
"Failed to send data in request for `%s'.\n"),
3157 ret = connection->
send_cls (connection,
3167 _(
"Connection was closed while sending response body.\n"));
3185 ret = connection->
send_cls (connection,
3195 _(
"Connection was closed while sending response body.\n"));
3210 #ifdef UPGRADE_SUPPORT 3211 case MHD_CONNECTION_UPGRADE:
3218 _(
"Internal error\n"));
3282 if ( (MHD_ITC_IS_VALID_ (daemon->
itc)) &&
3283 (! MHD_itc_activate_ (daemon->
itc,
"c")) )
3285 #ifdef HAVE_MESSAGES 3287 _(
"Failed to signal end of connection via inter-thread communication channel"));
3315 #ifdef HTTPS_SUPPORT 3318 if ((MHD_TLS_CONN_INIT <= connection->tls_state) &&
3325 _(
"In function %s handling connection at state: %s\n"),
3327 MHD_state_to_string (connection->
state));
3329 switch (connection->
state)
3338 if ( (
NULL == line) ||
3560 _(
"Closing connection (failed to create response header)\n"));
3578 #ifdef UPGRADE_SUPPORT 3582 connection->
state = MHD_CONNECTION_UPGRADE;
3671 _(
"Closing connection (failed to create response header)\n"));
3763 #ifdef UPGRADE_SUPPORT 3764 case MHD_CONNECTION_UPGRADE:
3778 if ( (0 != timeout) &&
3789 #ifdef EPOLL_SUPPORT 3793 ret = MHD_connection_epoll_update_ (connection);
3801 #ifdef EPOLL_SUPPORT 3824 struct epoll_event event;
3826 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
3827 event.data.ptr = connection;
3828 if (0 != epoll_ctl (daemon->epoll_fd,
3833 #ifdef HAVE_MESSAGES 3836 _(
"Call to epoll_ctl failed: %s\n"),
3880 #ifdef HTTPS_SUPPORT 3882 if (
NULL == connection->tls_session)
3884 connection->cipher = gnutls_cipher_get (connection->tls_session);
3887 if (
NULL == connection->tls_session)
3889 connection->protocol = gnutls_protocol_get_version (connection->tls_session);
3892 if (
NULL == connection->tls_session)
3938 daemon = connection->
daemon;
3958 va_start (ap, option);
3995 unsigned int status_code,
4000 if ( (
NULL == connection) ||
4001 (
NULL == response) ||
4006 daemon = connection->
daemon;
4014 (!MHD_thread_ID_match_current_(connection->
pid.ID)) )
4016 #ifdef HAVE_MESSAGES 4018 _(
"Attempted to queue response on wrong thread!\n"));
4022 #ifdef UPGRADE_SUPPORT 4023 if ( (
NULL != response->upgrade_handler) &&
4026 #ifdef HAVE_MESSAGES 4028 _(
"Attempted 'upgrade' connection on daemon without MHD_ALLOW_UPGRADE option!\n"));
4033 (
NULL != response->upgrade_handler) )
4035 #ifdef HAVE_MESSAGES 4037 _(
"Application used invalid status code for 'upgrade' response!\n"));
4045 #if defined(_MHD_HAVE_SENDFILE) 4046 if ( (response->
fd == -1) ||
4048 connection->resp_sender = MHD_resp_sender_std;
4050 connection->resp_sender = MHD_resp_sender_sendfile;
static int process_header_line(struct MHD_Connection *connection, char *line)
static ssize_t send_param_adapter(struct MHD_Connection *connection, const void *other, size_t i)
#define MHD_send_(s, b, l)
int(* MHD_KeyValueIterator)(void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
static int parse_cookie_header(struct MHD_Connection *connection)
void * unescape_callback_cls
void MHD_connection_handle_write(struct MHD_Connection *connection)
Header for platform missing functions.
static int try_ready_normal_body(struct MHD_Connection *connection)
uint64_t current_chunk_offset
_MHD_EXTERN const char * MHD_lookup_connection_value(struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key)
#define MHD_HTTP_METHOD_CONNECT
static void MHD_connection_update_event_loop_info(struct MHD_Connection *connection)
struct sockaddr_storage addr
struct MHD_Connection * cleanup_head
enum MHD_CONNECTION_STATE state
static int try_ready_chunked_body(struct MHD_Connection *connection)
#define MHD_lookup_header_s_token_ci(c, h, tkn)
uint64_t response_write_position
enum MHD_ConnKeepAlive keepalive
size_t MHD_str_to_uint64_(const char *str, uint64_t *out_val)
#define HTTP_100_CONTINUE
enum MHD_ConnectionEventLoopInfo event_loop_info
#define MHD_mutex_unlock_chk_(pmutex)
time_t connection_timeout
static int connection_add_header(struct MHD_Connection *connection, const char *key, const char *value, enum MHD_ValueKind kind)
Methods for managing connections.
MHD_PanicCallback mhd_panic
#define MHD_socket_get_error_()
internal monotonic clock functions implementations
void MHD_connection_close_(struct MHD_Connection *connection, enum MHD_RequestTerminationCode termination_code)
struct MHD_Response * response
#define REQUEST_LACKS_HOST
#define MHD_SENFILE_CHUNK_
#define MHD_HTTP_NOT_MODIFIED
bool MHD_str_has_token_caseless_(const char *str, const char *const token, size_t token_len)
bool MHD_parse_arguments_(struct MHD_Request *request, enum MHD_ValueKind kind, char *args, MHD_ArgumentIterator_ cb, unsigned int *num_headers)
struct MHD_Connection * manual_timeout_head
void MHD_connection_mark_closed_(struct MHD_Connection *connection)
MHD_RequestTerminationCode
MHD_thread_handle_ID_ pid
int MHD_str_equal_caseless_(const char *str1, const char *str2)
time_t MHD_monotonic_sec_counter(void)
static void transmit_error_response(struct MHD_Connection *connection, unsigned int status_code, const char *message)
MHD_AccessHandlerCallback default_handler
#define MHD_SCKT_ERR_IS_EAGAIN_(err)
static void call_connection_handler(struct MHD_Connection *connection)
uint64_t remaining_upload_size
unsigned int responseCode
#define MHD_ERR_CONNRESET_
Methods for managing response objects.
static void cleanup_connection(struct MHD_Connection *connection)
void MHD_update_last_activity_(struct MHD_Connection *connection)
#define MHD_UNSIGNED_LONG_LONG
void * uri_log_callback_cls
static ssize_t recv_param_adapter(struct MHD_Connection *connection, void *other, size_t i)
struct MHD_Daemon * daemon
int MHD_response_execute_upgrade_(struct MHD_Response *response, struct MHD_Connection *connection)
#define MHD_check_response_header_s_token_ci(r, k, tkn)
#define MHD_SENFILE_CHUNK_THR_P_C_
static bool MHD_lookup_header_token_ci(const struct MHD_Connection *connection, const char *header, const char *token, size_t token_len)
Header for platform-independent inter-thread communication.
static void connection_close_error(struct MHD_Connection *connection, const char *emsg)
void * MHD_pool_reset(struct MemoryPool *pool, void *keep, size_t copy_bytes, size_t new_size)
_MHD_EXTERN const union MHD_ConnectionInfo * MHD_get_connection_info(struct MHD_Connection *connection, enum MHD_ConnectionInfoType info_type,...)
static int keepalive_possible(struct MHD_Connection *connection)
#define DLL_insert(head, tail, element)
void MHD_increment_response_rc(struct MHD_Response *response)
#define MHD_HTTP_URI_TOO_LONG
struct MHD_HTTP_Header * first_header
#define MHD_socket_last_strerr_()
size_t write_buffer_send_offset
struct MHD_Connection * connections_tail
void * MHD_pool_allocate(struct MemoryPool *pool, size_t size, int from_end)
size_t continue_message_write_offset
#define REQUEST_MALFORMED
#define MHD_INVALID_SOCKET
size_t MHD_strx_to_uint64_n_(const char *str, size_t maxlen, uint64_t *out_val)
internal shared structures
enum MHD_HTTP_StatusCode status_code
#define MHD_SCKT_SEND_MAX_SIZE_
void * MHD_pool_reallocate(struct MemoryPool *pool, void *old, size_t old_size, size_t new_size)
struct MHD_Connection * connections_head
#define MHD_HTTP_NO_CONTENT
LogCallback uri_log_callback
static int socket_start_no_buffering(struct MHD_Connection *connection)
void MHD_connection_handle_read(struct MHD_Connection *connection)
_MHD_EXTERN void MHD_destroy_response(struct MHD_Response *response)
time_t connection_timeout
_MHD_EXTERN int MHD_set_connection_option(struct MHD_Connection *connection, enum MHD_CONNECTION_OPTION option,...)
#define MHD_SCKT_ERR_IS_(err, code)
Methods for managing connections.
#define MHD_CONTENT_READER_END_OF_STREAM
#define EDLL_remove(head, tail, element)
struct MHD_Connection * manual_timeout_tail
static void get_date_string(char *date, size_t date_len)
Header for string manipulating helpers.
#define DLL_remove(head, tail, element)
static int need_100_continue(struct MHD_Connection *connection)
#define MHD_STATICSTR_LEN_(macro)
#define MHD_HTTP_VERSION_1_1
struct MHD_Connection * normal_timeout_head
void MHD_pool_destroy(struct MemoryPool *pool)
#define MHD_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE
UnescapeCallback unescape_callback
static int try_grow_read_buffer(struct MHD_Connection *connection)
_MHD_EXTERN int MHD_queue_response(struct MHD_Connection *connection, unsigned int status_code, struct MHD_Response *response)
void MHD_connection_finish_forward_(struct MHD_Connection *connection) MHD_NONNULL(1)
#define XDLL_remove(head, tail, element)
unsigned int connection_timeout_dummy
#define MHD_HTTP_BAD_REQUEST
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_buffer(size_t size, void *buffer, enum MHD_ResponseMemoryMode mode)
struct MHD_Connection * suspended_connections_tail
static int check_write_done(struct MHD_Connection *connection, enum MHD_CONNECTION_STATE next_state)
bool MHD_run_tls_handshake_(struct MHD_Connection *connection)
struct MHD_Connection * cleanup_tail
int MHD_connection_handle_idle(struct MHD_Connection *connection)
static int process_broken_line(struct MHD_Connection *connection, char *line, enum MHD_ValueKind kind)
enum MHD_ResponseFlags flags
#define MHD_recv_(s, b, l)
#define MHD_HTTP_METHOD_HEAD
static void parse_connection_headers(struct MHD_Connection *connection)
size_t write_buffer_append_offset
struct MHD_Connection * normal_timeout_tail
MHD_RequestCompletedCallback notify_completed
#define MHD_mutex_lock_chk_(pmutex)
static int socket_start_extra_buffering(struct MHD_Connection *connection)
void MHD_set_http_callbacks_(struct MHD_Connection *connection)
#define MHD_HTTP_METHOD_PUT
void * notify_completed_cls
static void process_request_body(struct MHD_Connection *connection)
#define MHD_HTTP_VERSION_1_0
TransmitCallback send_cls
_MHD_EXTERN int MHD_get_connection_values(struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls)
#define MHD_HTTP_INTERNAL_SERVER_ERROR
Header for platform-independent locks abstraction.
#define MHD_CONTENT_READER_END_WITH_ERROR
MHD_ContentReaderCallback crc
static int parse_initial_message_line(struct MHD_Connection *connection, char *line, size_t line_len)
#define XDLL_insert(head, tail, element)
static int socket_start_normal_buffering(struct MHD_Connection *connection)
#define MHD_UNSIGNED_LONG_LONG_PRINTF
#define MHD_HTTP_PROCESSING
#define MHD_SCKT_ECONNRESET_
static int socket_flush_possible(struct MHD_Connection *connection)
struct MHD_Connection * suspended_connections_head
static int socket_start_no_buffering_flush(struct MHD_Connection *connection)
size_t read_buffer_offset
static char * get_next_header_line(struct MHD_Connection *connection, size_t *line_len)
void * default_handler_cls
_MHD_EXTERN const char * MHD_get_response_header(struct MHD_Response *response, const char *key)
#define MHD_SCKT_ERR_IS_EINTR_(err)
MHD_mutex_ cleanup_connection_mutex
#define CONNECTION_CLOSE_ERROR(c, emsg)
uint64_t current_chunk_size
struct MHD_HTTP_Header * headers_received
#define MHD_HTTP_SWITCHING_PROTOCOLS
limits values definitions
_MHD_EXTERN const char * MHD_get_reason_phrase_for(unsigned int code)
bool MHD_tls_connection_shutdown(struct MHD_Connection *connection)
_MHD_EXTERN int MHD_set_connection_value(struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key, const char *value)
struct MHD_HTTP_Header * headers_received_tail
static int build_header_response(struct MHD_Connection *connection)
#define MHD_HTTP_METHOD_POST