aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-04-27 22:36:09 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2017-04-27 22:36:09 +0300
commit33f121a4f6a2d5d47c51d7cbf1d5a750ed369750 (patch)
tree8070f17bd311faf7cb512fabeaa3f853bede565a
parent4c0cf12617719fa33b7e9315cf29ee1c74ef06dc (diff)
downloadlibmicrohttpd-33f121a4f6a2d5d47c51d7cbf1d5a750ed369750.tar.gz
libmicrohttpd-33f121a4f6a2d5d47c51d7cbf1d5a750ed369750.zip
Replaced flags MHD_USE_PEDANTIC_CHECKS and MHD_USE_PERMISSIVE_CHECKS by
single option MHD_OPTION_STRICT_FOR_CLIENT.
-rw-r--r--ChangeLog5
-rw-r--r--src/examples/minimal_example.c3
-rw-r--r--src/include/microhttpd.h37
-rw-r--r--src/microhttpd/connection.c4
-rw-r--r--src/microhttpd/daemon.c22
-rw-r--r--src/microhttpd/internal.h5
6 files changed, 62 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 28452654..a8a87f84 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
1Thu Apr 27 22:31:00 CEST 2017
2 Replaced flags MHD_USE_PEDANTIC_CHECKS and MHD_USE_PERMISSIVE_CHECKS by
3 single option MHD_OPTION_STRICT_FOR_CLIENT. Flag MHD_USE_PEDANTIC_CHECKS
4 is still supported. -EG
5
1Tue Apr 26 15:11:00 CEST 2017 6Tue Apr 26 15:11:00 CEST 2017
2 Fixed shift in HTTP reasons strings. 7 Fixed shift in HTTP reasons strings.
3 Added test for HTTP reasons strings. -EG 8 Added test for HTTP reasons strings. -EG
diff --git a/src/examples/minimal_example.c b/src/examples/minimal_example.c
index c5796fc8..98e7e192 100644
--- a/src/examples/minimal_example.c
+++ b/src/examples/minimal_example.c
@@ -68,13 +68,14 @@ main (int argc, char *const *argv)
68 return 1; 68 return 1;
69 } 69 }
70 d = MHD_start_daemon (// MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 70 d = MHD_start_daemon (// MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
71 MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_PEDANTIC_CHECKS | MHD_USE_ERROR_LOG, 71 MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
72 // MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, 72 // MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL,
73 // MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, 73 // MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL,
74 // MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 74 // MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
75 atoi (argv[1]), 75 atoi (argv[1]),
76 NULL, NULL, &ahc_echo, PAGE, 76 NULL, NULL, &ahc_echo, PAGE,
77 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, 77 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
78 MHD_OPTION_STRICT_FOR_CLIENT, (int) 1,
78 MHD_OPTION_END); 79 MHD_OPTION_END);
79 if (d == NULL) 80 if (d == NULL)
80 return 1; 81 return 1;
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index fcb617d8..02bf38ab 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -957,6 +957,11 @@ enum MHD_FLAG
957 * MHD, and OFF in production. 957 * MHD, and OFF in production.
958 */ 958 */
959 MHD_USE_PEDANTIC_CHECKS = 32, 959 MHD_USE_PEDANTIC_CHECKS = 32,
960#if 0 /* Will be marked for real deprecation later. */
961#define MHD_USE_PEDANTIC_CHECKS \
962 _MHD_DEPR_IN_MACRO("Flag MHD_USE_PEDANTIC_CHECKS is deprecated, use option MHD_OPTION_STRICT_FOR_CLIENT instead") \
963 32
964#endif /* 0 */
960 965
961 /** 966 /**
962 * Use `poll()` instead of `select()`. This allows sockets with `fd >= 967 * Use `poll()` instead of `select()`. This allows sockets with `fd >=
@@ -1136,16 +1141,7 @@ enum MHD_FLAG
1136 * This is combination of #MHD_USE_AUTO and #MHD_USE_INTERNAL_POLLING_THREAD 1141 * This is combination of #MHD_USE_AUTO and #MHD_USE_INTERNAL_POLLING_THREAD
1137 * flags. 1142 * flags.
1138 */ 1143 */
1139 MHD_USE_AUTO_INTERNAL_THREAD = MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD, 1144 MHD_USE_AUTO_INTERNAL_THREAD = MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD
1140
1141 /**
1142 * Be permissive about the protocol, allowing slight deviations that
1143 * are technically not allowed by the RFC.
1144 * Specifically, at the moment, this flag causes MHD to
1145 * allow spaces in header field names. This is
1146 * disallowed by the standard.
1147 */
1148 MHD_USE_PERMISSIVE_CHECKS = 131072
1149 1145
1150}; 1146};
1151 1147
@@ -1471,7 +1467,26 @@ enum MHD_OPTION
1471 * value is used. This option should be followed by an `unsigned int` 1467 * value is used. This option should be followed by an `unsigned int`
1472 * argument. 1468 * argument.
1473 */ 1469 */
1474 MHD_OPTION_LISTEN_BACKLOG_SIZE = 28 1470 MHD_OPTION_LISTEN_BACKLOG_SIZE = 28,
1471
1472 /**
1473 * If set to 1 - be strict about the protocol (as opposed to as
1474 * tolerant as possible). Specifically, at the moment, this flag
1475 * causes MHD to reject HTTP 1.1 connections without a "Host" header.
1476 * This is required by the standard, but of course in violation of
1477 * the "be as liberal as possible in what you accept" norm. It is
1478 * recommended to set this to 1 if you are testing clients against
1479 * MHD, and 0 in production.
1480 * if set to -1 - be opposite to strict and be permissive about the
1481 * protocol, allowing slight deviations that are technically not
1482 * allowed by the RFC. Specifically, at the moment, this flag
1483 * causes MHD to allow spaces in header field names. This is
1484 * disallowed by the standard.
1485 * It is not recommended to set it to -1 on publicly available
1486 * servers as it may potentially lower level of protection.
1487 * This option should be followed by an `int` argument.
1488 */
1489 MHD_OPTION_STRICT_FOR_CLIENT = 29
1475}; 1490};
1476 1491
1477 1492
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 7baee402..228af49b 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -2213,7 +2213,7 @@ process_header_line (struct MHD_Connection *connection,
2213 _("Received malformed line (no colon). Closing connection.\n")); 2213 _("Received malformed line (no colon). Closing connection.\n"));
2214 return MHD_NO; 2214 return MHD_NO;
2215 } 2215 }
2216 if (0 == (MHD_USE_PERMISSIVE_CHECKS & connection->daemon->options)) 2216 if (-1 >= connection->daemon->strict_for_client)
2217 { 2217 {
2218 /* check for whitespace before colon, which is not allowed 2218 /* check for whitespace before colon, which is not allowed
2219 by RFC 7230 section 3.2.4; we count space ' ' and 2219 by RFC 7230 section 3.2.4; we count space ' ' and
@@ -2348,7 +2348,7 @@ parse_connection_headers (struct MHD_Connection *connection)
2348 const char *end; 2348 const char *end;
2349 2349
2350 parse_cookie_header (connection); 2350 parse_cookie_header (connection);
2351 if ( (0 != (MHD_USE_PEDANTIC_CHECKS & connection->daemon->options)) && 2351 if ( (1 <= connection->daemon->strict_for_client) &&
2352 (NULL != connection->version) && 2352 (NULL != connection->version) &&
2353 (MHD_str_equal_caseless_(MHD_HTTP_VERSION_1_1, 2353 (MHD_str_equal_caseless_(MHD_HTTP_VERSION_1_1,
2354 connection->version)) && 2354 connection->version)) &&
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index b528622d..a91d2687 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -5063,6 +5063,18 @@ parse_options_va (struct MHD_Daemon *daemon,
5063 daemon->listen_backlog_size = va_arg (ap, 5063 daemon->listen_backlog_size = va_arg (ap,
5064 unsigned int); 5064 unsigned int);
5065 break; 5065 break;
5066 case MHD_OPTION_STRICT_FOR_CLIENT:
5067 daemon->strict_for_client = va_arg (ap, int);;
5068#ifdef HAVE_MESSAGES
5069 if ( (0 != (daemon->options & MHD_USE_PEDANTIC_CHECKS)) &&
5070 (1 != daemon->strict_for_client) )
5071 {
5072 MHD_DLOG (daemon,
5073 _("Flag MHD_USE_PEDANTIC_CHECKS is ignored because "
5074 "another behavior is specified by MHD_OPTION_STRICT_CLIENT.\n"));
5075 }
5076#endif /* HAVE_MESSAGES */
5077 break;
5066 case MHD_OPTION_ARRAY: 5078 case MHD_OPTION_ARRAY:
5067 oa = va_arg (ap, struct MHD_OptionItem*); 5079 oa = va_arg (ap, struct MHD_OptionItem*);
5068 i = 0; 5080 i = 0;
@@ -5117,6 +5129,15 @@ parse_options_va (struct MHD_Daemon *daemon,
5117 MHD_OPTION_END)) 5129 MHD_OPTION_END))
5118 return MHD_NO; 5130 return MHD_NO;
5119 break; 5131 break;
5132 /* all options taking 'int' */
5133 case MHD_OPTION_STRICT_FOR_CLIENT:
5134 if (MHD_YES != parse_options (daemon,
5135 servaddr,
5136 opt,
5137 (int) oa[i].value,
5138 MHD_OPTION_END))
5139 return MHD_NO;
5140 break;
5120 /* all options taking one pointer */ 5141 /* all options taking one pointer */
5121 case MHD_OPTION_SOCK_ADDR: 5142 case MHD_OPTION_SOCK_ADDR:
5122 case MHD_OPTION_HTTPS_MEM_KEY: 5143 case MHD_OPTION_HTTPS_MEM_KEY:
@@ -5428,6 +5449,7 @@ MHD_start_daemon_va (unsigned int flags,
5428 daemon->listening_address_reuse = 0; 5449 daemon->listening_address_reuse = 0;
5429 daemon->options = *pflags; 5450 daemon->options = *pflags;
5430 pflags = &daemon->options; 5451 pflags = &daemon->options;
5452 daemon->strict_for_client = (0 != (*pflags & MHD_USE_PEDANTIC_CHECKS)) ? 1 : 0;
5431 daemon->port = port; 5453 daemon->port = port;
5432 daemon->apc = apc; 5454 daemon->apc = apc;
5433 daemon->apc_cls = apc_cls; 5455 daemon->apc_cls = apc_cls;
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 9ced47c1..aac13d6c 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -1540,6 +1540,11 @@ struct MHD_Daemon
1540 */ 1540 */
1541 uint16_t port; 1541 uint16_t port;
1542 1542
1543 /**
1544 * Be neutral (zero), strict (1) or permissive (-1) to client.
1545 */
1546 int strict_for_client;
1547
1543#ifdef HTTPS_SUPPORT 1548#ifdef HTTPS_SUPPORT
1544#ifdef UPGRADE_SUPPORT 1549#ifdef UPGRADE_SUPPORT
1545 /** 1550 /**