diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-08 13:11:50 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-08 13:11:50 +0000 |
commit | ea8bac474500dec49acdf7ce6fdc8910ecdc374d (patch) | |
tree | 8e337256a2ced20d71f7bd66ee3f38f9cf4773d9 /src | |
parent | 1f4a53507e325cfdc48e3024e00c59f7e721faba (diff) | |
download | libmicrohttpd-ea8bac474500dec49acdf7ce6fdc8910ecdc374d.tar.gz libmicrohttpd-ea8bac474500dec49acdf7ce6fdc8910ecdc374d.zip |
adding MHD_set_response_options function
Diffstat (limited to 'src')
-rw-r--r-- | src/include/microhttpd.h | 49 | ||||
-rw-r--r-- | src/include/platform_interface.h | 4 | ||||
-rw-r--r-- | src/include/w32functions.h | 4 | ||||
-rw-r--r-- | src/microhttpd/connection.c | 8 | ||||
-rw-r--r-- | src/microhttpd/internal.c | 7 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 25 | ||||
-rw-r--r-- | src/microhttpd/response.c | 34 |
7 files changed, 116 insertions, 15 deletions
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h index 30df9611..b7cdb1f7 100644 --- a/src/include/microhttpd.h +++ b/src/include/microhttpd.h | |||
@@ -130,7 +130,7 @@ typedef intptr_t ssize_t; | |||
130 | * Current version of the library. | 130 | * Current version of the library. |
131 | * 0x01093001 = 1.9.30-1. | 131 | * 0x01093001 = 1.9.30-1. |
132 | */ | 132 | */ |
133 | #define MHD_VERSION 0x00093700 | 133 | #define MHD_VERSION 0x00093701 |
134 | 134 | ||
135 | /** | 135 | /** |
136 | * MHD-internal return code for "YES". | 136 | * MHD-internal return code for "YES". |
@@ -1745,6 +1745,53 @@ MHD_resume_connection (struct MHD_Connection *connection); | |||
1745 | 1745 | ||
1746 | /* **************** Response manipulation functions ***************** */ | 1746 | /* **************** Response manipulation functions ***************** */ |
1747 | 1747 | ||
1748 | |||
1749 | /** | ||
1750 | * Flags for special handling of responses. | ||
1751 | */ | ||
1752 | enum MHD_ResponseFlags | ||
1753 | { | ||
1754 | /** | ||
1755 | * Default: no special flags. | ||
1756 | */ | ||
1757 | MHD_RF_NONE = 0, | ||
1758 | |||
1759 | /** | ||
1760 | * Only respond in conservative HTTP 1.0-mode. In particular, | ||
1761 | * do not (automatically) sent "Connection" headers and always | ||
1762 | * close the connection after generating the response. | ||
1763 | */ | ||
1764 | MHD_RF_HTTP_VERSION_1_0_ONLY = 1 | ||
1765 | |||
1766 | }; | ||
1767 | |||
1768 | |||
1769 | /** | ||
1770 | * MHD options (for future extensions). | ||
1771 | */ | ||
1772 | enum MHD_ResponseOptions | ||
1773 | { | ||
1774 | /** | ||
1775 | * End of the list of options. | ||
1776 | */ | ||
1777 | MHD_RO_END = 0 | ||
1778 | }; | ||
1779 | |||
1780 | |||
1781 | /** | ||
1782 | * Set special flags and options for a response. | ||
1783 | * | ||
1784 | * @param response the response to modify | ||
1785 | * @param flags to set for the response | ||
1786 | * @param ... #MHD_RO_END terminated list of options | ||
1787 | * @return #MHD_YES on success, #MHD_NO on error | ||
1788 | */ | ||
1789 | int | ||
1790 | MHD_set_response_options (struct MHD_Response *response, | ||
1791 | enum MHD_ResponseFlags flags, | ||
1792 | ...); | ||
1793 | |||
1794 | |||
1748 | /** | 1795 | /** |
1749 | * Create a response object. The response object can be extended with | 1796 | * Create a response object. The response object can be extended with |
1750 | * header information and then be used any number of times. | 1797 | * header information and then be used any number of times. |
diff --git a/src/include/platform_interface.h b/src/include/platform_interface.h index 368e5f34..f7373e7d 100644 --- a/src/include/platform_interface.h +++ b/src/include/platform_interface.h | |||
@@ -13,12 +13,12 @@ | |||
13 | Lesser General Public License for more details. | 13 | Lesser General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Lesser General Public | 15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with this library. | 16 | License along with this library. |
17 | If not, see <http://www.gnu.org/licenses/>. | 17 | If not, see <http://www.gnu.org/licenses/>. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * @file include/platfrom_interface.h | 21 | * @file include/platform_interface.h |
22 | * @brief internal platform abstraction functions | 22 | * @brief internal platform abstraction functions |
23 | * @author Karlson2k (Evgeny Grin) | 23 | * @author Karlson2k (Evgeny Grin) |
24 | */ | 24 | */ |
diff --git a/src/include/w32functions.h b/src/include/w32functions.h index 07614e6b..c7a885a6 100644 --- a/src/include/w32functions.h +++ b/src/include/w32functions.h | |||
@@ -13,12 +13,12 @@ | |||
13 | Lesser General Public License for more details. | 13 | Lesser General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Lesser General Public | 15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with this library. | 16 | License along with this library. |
17 | If not, see <http://www.gnu.org/licenses/>. | 17 | If not, see <http://www.gnu.org/licenses/>. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * @file platform/w32functions.h | 21 | * @file include/w32functions.h |
22 | * @brief internal functions for W32 systems | 22 | * @brief internal functions for W32 systems |
23 | * @author Karlson2k (Evgeny Grin) | 23 | * @author Karlson2k (Evgeny Grin) |
24 | */ | 24 | */ |
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 945c3f69..5feca5e4 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -528,6 +528,9 @@ keepalive_possible (struct MHD_Connection *connection) | |||
528 | 528 | ||
529 | if (NULL == connection->version) | 529 | if (NULL == connection->version) |
530 | return MHD_NO; | 530 | return MHD_NO; |
531 | if ( (NULL != connection->response) && | ||
532 | (0 != (connection->response->flags & MHD_RF_HTTP_VERSION_1_0_ONLY) ) ) | ||
533 | return MHD_NO; | ||
531 | end = MHD_lookup_connection_value (connection, | 534 | end = MHD_lookup_connection_value (connection, |
532 | MHD_HEADER_KIND, | 535 | MHD_HEADER_KIND, |
533 | MHD_HTTP_HEADER_CONNECTION); | 536 | MHD_HTTP_HEADER_CONNECTION); |
@@ -596,6 +599,7 @@ add_extra_headers (struct MHD_Connection *connection) | |||
596 | /* 'close' header doesn't exist yet, see if we need to add one; | 599 | /* 'close' header doesn't exist yet, see if we need to add one; |
597 | if the client asked for a close, no need to start chunk'ing */ | 600 | if the client asked for a close, no need to start chunk'ing */ |
598 | if ( (NULL == client_close) && | 601 | if ( (NULL == client_close) && |
602 | (0 == (connection->response->flags & MHD_RF_HTTP_VERSION_1_0_ONLY) ) && | ||
599 | (MHD_YES == keepalive_possible (connection)) && | 603 | (MHD_YES == keepalive_possible (connection)) && |
600 | (0 == strcasecmp (connection->version, | 604 | (0 == strcasecmp (connection->version, |
601 | MHD_HTTP_VERSION_1_1)) ) | 605 | MHD_HTTP_VERSION_1_1)) ) |
@@ -662,13 +666,15 @@ add_extra_headers (struct MHD_Connection *connection) | |||
662 | MHD_HTTP_HEADER_CONTENT_LENGTH, buf); | 666 | MHD_HTTP_HEADER_CONTENT_LENGTH, buf); |
663 | } | 667 | } |
664 | } | 668 | } |
665 | if (MHD_YES == add_close) | 669 | if ( (MHD_YES == add_close) && |
670 | (0 == (connection->response->flags & MHD_RF_HTTP_VERSION_1_0_ONLY) ) ) | ||
666 | MHD_add_response_header (connection->response, | 671 | MHD_add_response_header (connection->response, |
667 | MHD_HTTP_HEADER_CONNECTION, | 672 | MHD_HTTP_HEADER_CONNECTION, |
668 | "close"); | 673 | "close"); |
669 | if ( (NULL == have_keepalive) && | 674 | if ( (NULL == have_keepalive) && |
670 | (NULL == have_close) && | 675 | (NULL == have_close) && |
671 | (MHD_NO == add_close) && | 676 | (MHD_NO == add_close) && |
677 | (0 == (connection->response->flags & MHD_RF_HTTP_VERSION_1_0_ONLY) ) && | ||
672 | (MHD_YES == keepalive_possible (connection)) ) | 678 | (MHD_YES == keepalive_possible (connection)) ) |
673 | MHD_add_response_header (connection->response, | 679 | MHD_add_response_header (connection->response, |
674 | MHD_HTTP_HEADER_CONNECTION, | 680 | MHD_HTTP_HEADER_CONNECTION, |
diff --git a/src/microhttpd/internal.c b/src/microhttpd/internal.c index 6170fe0a..c8db5af0 100644 --- a/src/microhttpd/internal.c +++ b/src/microhttpd/internal.c | |||
@@ -160,6 +160,13 @@ MHD_http_unescape (void *cls, | |||
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | /** | ||
164 | * Equivalent to time(NULL) but tries to use some sort of monotonic | ||
165 | * clock that isn't affected by someone setting the system real time | ||
166 | * clock. | ||
167 | * | ||
168 | * @return 'current' time | ||
169 | */ | ||
163 | time_t | 170 | time_t |
164 | MHD_monotonic_time (void) | 171 | MHD_monotonic_time (void) |
165 | { | 172 | { |
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index d57db379..928ebe11 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -266,8 +266,8 @@ struct MHD_Response | |||
266 | char *data; | 266 | char *data; |
267 | 267 | ||
268 | /** | 268 | /** |
269 | * Closure to give to the content reader | 269 | * Closure to give to the content reader @e crc |
270 | * free callback. | 270 | * and content reader free callback @crfc. |
271 | */ | 271 | */ |
272 | void *crc_cls; | 272 | void *crc_cls; |
273 | 273 | ||
@@ -284,8 +284,8 @@ struct MHD_Response | |||
284 | MHD_ContentReaderFreeCallback crfc; | 284 | MHD_ContentReaderFreeCallback crfc; |
285 | 285 | ||
286 | /** | 286 | /** |
287 | * Mutex to synchronize access to data/size and | 287 | * Mutex to synchronize access to @e data, @e size and |
288 | * reference counts. | 288 | * @e reference_count. |
289 | */ | 289 | */ |
290 | MHD_mutex_ mutex; | 290 | MHD_mutex_ mutex; |
291 | 291 | ||
@@ -296,22 +296,23 @@ struct MHD_Response | |||
296 | 296 | ||
297 | /** | 297 | /** |
298 | * At what offset in the stream is the | 298 | * At what offset in the stream is the |
299 | * beginning of data located? | 299 | * beginning of @e data located? |
300 | */ | 300 | */ |
301 | uint64_t data_start; | 301 | uint64_t data_start; |
302 | 302 | ||
303 | /** | 303 | /** |
304 | * Offset to start reading from when using 'fd'. | 304 | * Offset to start reading from when using @e fd. |
305 | */ | 305 | */ |
306 | off_t fd_off; | 306 | off_t fd_off; |
307 | 307 | ||
308 | /** | 308 | /** |
309 | * Size of data. | 309 | * Number of bytes ready in @e data (buffer may be larger |
310 | * than what is filled with payload). | ||
310 | */ | 311 | */ |
311 | size_t data_size; | 312 | size_t data_size; |
312 | 313 | ||
313 | /** | 314 | /** |
314 | * Size of the data buffer. | 315 | * Size of the data buffer @e data. |
315 | */ | 316 | */ |
316 | size_t data_buffer_size; | 317 | size_t data_buffer_size; |
317 | 318 | ||
@@ -326,6 +327,11 @@ struct MHD_Response | |||
326 | */ | 327 | */ |
327 | int fd; | 328 | int fd; |
328 | 329 | ||
330 | /** | ||
331 | * Flags set for the MHD response. | ||
332 | */ | ||
333 | enum MHD_ResponseFlags flags; | ||
334 | |||
329 | }; | 335 | }; |
330 | 336 | ||
331 | 337 | ||
@@ -1386,6 +1392,7 @@ struct MHD_Daemon | |||
1386 | * | 1392 | * |
1387 | * @return 'current' time | 1393 | * @return 'current' time |
1388 | */ | 1394 | */ |
1389 | time_t MHD_monotonic_time(void); | 1395 | time_t |
1396 | MHD_monotonic_time(void); | ||
1390 | 1397 | ||
1391 | #endif | 1398 | #endif |
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c index b287a222..d4d77fea 100644 --- a/src/microhttpd/response.c +++ b/src/microhttpd/response.c | |||
@@ -266,6 +266,40 @@ MHD_create_response_from_callback (uint64_t size, | |||
266 | 266 | ||
267 | 267 | ||
268 | /** | 268 | /** |
269 | * Set special flags and options for a response. | ||
270 | * | ||
271 | * @param response the response to modify | ||
272 | * @param flags to set for the response | ||
273 | * @param ... #MHD_RO_END terminated list of options | ||
274 | * @return #MHD_YES on success, #MHD_NO on error | ||
275 | */ | ||
276 | int | ||
277 | MHD_set_response_options (struct MHD_Response *response, | ||
278 | enum MHD_ResponseFlags flags, | ||
279 | ...) | ||
280 | { | ||
281 | va_list ap; | ||
282 | int ret; | ||
283 | enum MHD_ResponseOptions ro; | ||
284 | |||
285 | ret = MHD_YES; | ||
286 | response->flags = flags; | ||
287 | va_start (ap, flags); | ||
288 | while (MHD_RO_END != (ro = va_arg (ap, enum MHD_ResponseOptions))) | ||
289 | { | ||
290 | switch (ro) | ||
291 | { | ||
292 | default: | ||
293 | ret = MHD_NO; | ||
294 | break; | ||
295 | } | ||
296 | } | ||
297 | va_end (ap); | ||
298 | return ret; | ||
299 | } | ||
300 | |||
301 | |||
302 | /** | ||
269 | * Given a file descriptor, read data from the file | 303 | * Given a file descriptor, read data from the file |
270 | * to generate the response. | 304 | * to generate the response. |
271 | * | 305 | * |