diff options
author | Christian Grothoff <christian@grothoff.org> | 2007-08-26 09:13:05 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2007-08-26 09:13:05 +0000 |
commit | 1d647758e4977c7aebddf893171ceb1bba5bef81 (patch) | |
tree | 59f1893e34d128d3cda09442b80894a02ccbe9b9 | |
parent | bf515f7217fde589c78a2319b91de0d2c90b834d (diff) | |
download | libmicrohttpd-1d647758e4977c7aebddf893171ceb1bba5bef81.tar.gz libmicrohttpd-1d647758e4977c7aebddf893171ceb1bba5bef81.zip |
fixing mantis 1264
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | src/daemon/connection.c | 44 | ||||
-rw-r--r-- | src/include/microhttpd.h | 11 |
4 files changed, 55 insertions, 6 deletions
@@ -1,3 +1,8 @@ | |||
1 | Sun Aug 26 03:11:46 MDT 2007 | ||
2 | Added MHD_USE_PEDANTIC_CHECKS option which enforces | ||
3 | receiving a "Host:" header in HTTP 1.1 (and sends a | ||
4 | HTTP 400 status back if this is violated). | ||
5 | |||
1 | Tue Aug 21 01:01:46 MDT 2007 | 6 | Tue Aug 21 01:01:46 MDT 2007 |
2 | Fixing assertion failure that occured when a client | 7 | Fixing assertion failure that occured when a client |
3 | closed the connection after sending some data but | 8 | closed the connection after sending some data but |
@@ -15,7 +15,6 @@ For http/1.1-compliance: | |||
15 | ======================== | 15 | ======================== |
16 | connection.c: | 16 | connection.c: |
17 | - support chunked requests from clients (#1260, ARCH, TEST) | 17 | - support chunked requests from clients (#1260, ARCH, TEST) |
18 | - send proper error code back if client forgot the "Host" header (#1264, TRIV) | ||
19 | 18 | ||
20 | For POST: | 19 | For POST: |
21 | ========= | 20 | ========= |
diff --git a/src/daemon/connection.c b/src/daemon/connection.c index e51693d9..cdc8540b 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c | |||
@@ -37,12 +37,24 @@ | |||
37 | #define HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n" | 37 | #define HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n" |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Response used when the request (http header) is too big to | 40 | * Response text used when the request (http header) is too big to |
41 | * be processed. | 41 | * be processed. |
42 | * | ||
43 | * Intentionally empty here to keep our memory footprint | ||
44 | * minimal. | ||
42 | */ | 45 | */ |
43 | #define REQUEST_TOO_BIG "" | 46 | #define REQUEST_TOO_BIG "" |
44 | 47 | ||
45 | /** | 48 | /** |
49 | * Response text used when the request (http header) does not | ||
50 | * contain a "Host:" header and still claims to be HTTP 1.1. | ||
51 | * | ||
52 | * Intentionally empty here to keep our memory footprint | ||
53 | * minimal. | ||
54 | */ | ||
55 | #define REQUEST_LACKS_HOST "" | ||
56 | |||
57 | /** | ||
46 | * Add extra debug messages with reasons for closing connections | 58 | * Add extra debug messages with reasons for closing connections |
47 | * (non-error reasons). | 59 | * (non-error reasons). |
48 | */ | 60 | */ |
@@ -305,9 +317,7 @@ MHD_excessive_data_handler (struct MHD_Connection *connection, | |||
305 | { | 317 | { |
306 | struct MHD_Response *response; | 318 | struct MHD_Response *response; |
307 | 319 | ||
308 | /* die, header far too long to be reasonable; | 320 | /* die, header far too long to be reasonable */ |
309 | FIXME: send proper response to client | ||
310 | (stop reading, queue proper response) */ | ||
311 | connection->read_close = MHD_YES; | 321 | connection->read_close = MHD_YES; |
312 | connection->headersReceived = MHD_YES; | 322 | connection->headersReceived = MHD_YES; |
313 | connection->bodyReceived = MHD_YES; | 323 | connection->bodyReceived = MHD_YES; |
@@ -589,6 +599,7 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) | |||
589 | const char *clen; | 599 | const char *clen; |
590 | const char *end; | 600 | const char *end; |
591 | unsigned long long cval; | 601 | unsigned long long cval; |
602 | struct MHD_Response * response; | ||
592 | 603 | ||
593 | if (connection->bodyReceived == 1) | 604 | if (connection->bodyReceived == 1) |
594 | abort (); | 605 | abort (); |
@@ -638,7 +649,7 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) | |||
638 | if (strlen (line) == 0) | 649 | if (strlen (line) == 0) |
639 | { | 650 | { |
640 | /* end of header */ | 651 | /* end of header */ |
641 | connection->headersReceived = 1; | 652 | connection->headersReceived = MHD_YES; |
642 | clen = MHD_lookup_connection_value (connection, | 653 | clen = MHD_lookup_connection_value (connection, |
643 | MHD_HEADER_KIND, | 654 | MHD_HEADER_KIND, |
644 | MHD_HTTP_HEADER_CONTENT_LENGTH); | 655 | MHD_HTTP_HEADER_CONTENT_LENGTH); |
@@ -680,6 +691,29 @@ MHD_parse_connection_headers (struct MHD_Connection *connection) | |||
680 | this request */ | 691 | this request */ |
681 | connection->read_close = MHD_YES; | 692 | connection->read_close = MHD_YES; |
682 | } | 693 | } |
694 | |||
695 | if ( (0 != (MHD_USE_PEDANTIC_CHECKS & connection->daemon->options)) && | ||
696 | (NULL != connection->version) && | ||
697 | (0 == strcasecmp(MHD_HTTP_VERSION_1_1, | ||
698 | connection->version)) && | ||
699 | (NULL == MHD_lookup_connection_value(connection, | ||
700 | MHD_HEADER_KIND, | ||
701 | MHD_HTTP_HEADER_HOST)) ) { | ||
702 | /* die, http 1.1 request without host and we are pedantic */ | ||
703 | connection->bodyReceived = MHD_YES; | ||
704 | connection->read_close = MHD_YES; | ||
705 | MHD_DLOG (connection->daemon, | ||
706 | "Received `%s' request without `%s' header.\n", | ||
707 | MHD_HTTP_VERSION_1_1, | ||
708 | MHD_HTTP_HEADER_HOST); | ||
709 | response = MHD_create_response_from_data (strlen (REQUEST_LACKS_HOST), | ||
710 | REQUEST_LACKS_HOST, MHD_NO, MHD_NO); | ||
711 | MHD_queue_response (connection, | ||
712 | MHD_HTTP_BAD_REQUEST, | ||
713 | response); | ||
714 | MHD_destroy_response (response); | ||
715 | } | ||
716 | |||
683 | break; | 717 | break; |
684 | } | 718 | } |
685 | /* line should be normal header line, find colon */ | 719 | /* line should be normal header line, find colon */ |
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h index 975611bf..d09c66a9 100644 --- a/src/include/microhttpd.h +++ b/src/include/microhttpd.h | |||
@@ -274,6 +274,17 @@ enum MHD_FLAG | |||
274 | */ | 274 | */ |
275 | MHD_USE_IPv6 = 16, | 275 | MHD_USE_IPv6 = 16, |
276 | 276 | ||
277 | /** | ||
278 | * Be pedantic about the protocol (as opposed to as tolerant as | ||
279 | * possible). Specifically, at the moment, this flag causes MHD to | ||
280 | * reject http 1.1 connections without a "Host" header. This is | ||
281 | * required by the standard, but of course in violation of the "be | ||
282 | * as liberal as possible in what you accept" norm. It is | ||
283 | * recommended to turn this ON if you are testing clients against | ||
284 | * MHD, and OFF in production. | ||
285 | */ | ||
286 | MHD_USE_PEDANTIC_CHECKS = 32, | ||
287 | |||
277 | }; | 288 | }; |
278 | 289 | ||
279 | /** | 290 | /** |