aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-08 13:11:50 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-08 13:11:50 +0000
commitea8bac474500dec49acdf7ce6fdc8910ecdc374d (patch)
tree8e337256a2ced20d71f7bd66ee3f38f9cf4773d9 /src/microhttpd
parent1f4a53507e325cfdc48e3024e00c59f7e721faba (diff)
downloadlibmicrohttpd-ea8bac474500dec49acdf7ce6fdc8910ecdc374d.tar.gz
libmicrohttpd-ea8bac474500dec49acdf7ce6fdc8910ecdc374d.zip
adding MHD_set_response_options function
Diffstat (limited to 'src/microhttpd')
-rw-r--r--src/microhttpd/connection.c8
-rw-r--r--src/microhttpd/internal.c7
-rw-r--r--src/microhttpd/internal.h25
-rw-r--r--src/microhttpd/response.c34
4 files changed, 64 insertions, 10 deletions
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 */
163time_t 170time_t
164MHD_monotonic_time (void) 171MHD_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 */
1389time_t MHD_monotonic_time(void); 1395time_t
1396MHD_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 */
276int
277MHD_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 *