diff options
author | Christian Grothoff <christian@grothoff.org> | 2007-08-11 00:14:18 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2007-08-11 00:14:18 +0000 |
commit | c75bf1093162231d4e2f09f399f2d6039d2c321f (patch) | |
tree | 7ce3b424f8eeff05bcd54b05c87576a7a81d7a57 | |
parent | 71edae497964094f63bedb630d8bceb670ac660e (diff) |
100 continue
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | src/daemon/connection.c | 52 | ||||
-rw-r--r-- | src/daemon/daemontest_get.c | 4 | ||||
-rw-r--r-- | src/daemon/daemontest_post.c | 4 | ||||
-rw-r--r-- | src/daemon/daemontest_put.c | 5 | ||||
-rw-r--r-- | src/daemon/internal.h | 9 | ||||
-rw-r--r-- | src/daemon/response.c | 9 |
7 files changed, 53 insertions, 33 deletions
@@ -1,7 +1,8 @@ Fri Aug 10 17:31:23 MDT 2007 Fixed problems with handling of responses created from callbacks. Allowing accept policy callback to be NULL - (to accept from all). Added minimal fileserver example. -CG + (to accept from all). Added minimal fileserver example. + Only send 100 continue header when specifically requested. - CG Wed Aug 8 01:46:06 MDT 2007 Added pool allocation and connection limitations (total diff --git a/src/daemon/connection.c b/src/daemon/connection.c index 6da77002..b5d0b3dd 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c @@ -31,11 +31,6 @@ #include "response.h" /** - * Size by which MHD usually tries to increment read/write buffers. - */ -#define MHD_BUF_INC_SIZE 2048 - -/** * Message to transmit when http 1.1 request is received */ #define HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n" @@ -141,6 +136,25 @@ MHD_queue_response(struct MHD_Connection * connection, return MHD_YES; } +/** + * Do we (still) need to send a 100 continue + * message for this connection? + */ +static int +MHD_need_100_continue(struct MHD_Connection * connection) { + const char * expect; + + return ( (connection->version != NULL) && + (0 == strcasecmp(connection->version, + MHD_HTTP_VERSION_1_1)) && + (connection->headersReceived == 1) && + (NULL != (expect = MHD_lookup_connection_value(connection, + MHD_HEADER_KIND, + MHD_HTTP_HEADER_EXPECT))) && + (0 == strcasecmp(expect, + "100-continue")) && + (connection->continuePos < strlen(HTTP_100_CONTINUE)) ); +} /** * Obtain the select sets for this connection @@ -186,10 +200,7 @@ MHD_connection_get_fdset(struct MHD_Connection * connection, } } if ( (connection->response != NULL) || - ( (connection->version != NULL) && - (0 == strcasecmp(connection->version, - MHD_HTTP_VERSION_1_1)) && - (connection->continuePos < strlen(HTTP_100_CONTINUE)) ) ) { + MHD_need_100_continue(connection) ) { FD_SET(fd, write_fd_set); if (fd > *max_fd) *max_fd = fd; @@ -998,10 +1009,7 @@ MHD_connection_handle_write(struct MHD_Connection * connection) { struct MHD_Response * response; int ret; - if ( (connection->version != NULL) && - (0 == strcasecmp(connection->version, - MHD_HTTP_VERSION_1_1)) && - (connection->continuePos < strlen(HTTP_100_CONTINUE)) ) { + if (MHD_need_100_continue(connection)) { ret = SEND(connection->socket_fd, &HTTP_100_CONTINUE[connection->continuePos], strlen(HTTP_100_CONTINUE) - connection->continuePos, @@ -1067,24 +1075,18 @@ MHD_connection_handle_write(struct MHD_Connection * connection) { if (response->crc != NULL) pthread_mutex_lock(&response->mutex); - /* prepare send buffer */ - if ( (response->data == NULL) || - (response->data_start > connection->messagePos) || - (response->data_start + response->data_size <= connection->messagePos) ) { - if (response->data_size == 0) { - if (response->data != NULL) - free(response->data); - response->data = malloc(MHD_BUF_INC_SIZE); - response->data_size = MHD_BUF_INC_SIZE; - } + /* prepare send buffer */ + if ( (response->crc != NULL) && + ( (response->data_start > connection->messagePos) || + (response->data_start + response->data_size <= connection->messagePos) ) ) { ret = response->crc(response->crc_cls, connection->messagePos, response->data, - MIN(response->data_size, + MIN(response->data_buffer_size, response->total_size - connection->messagePos)); if (ret == -1) { /* end of message, signal other side by closing! */ - response->data_size = connection->messagePos; + response->total_size = connection->messagePos; CLOSE(connection->socket_fd); connection->socket_fd = -1; if (response->crc != NULL) diff --git a/src/daemon/daemontest_get.c b/src/daemon/daemontest_get.c index 89f50461..08de296d 100644 --- a/src/daemon/daemontest_get.c +++ b/src/daemon/daemontest_get.c @@ -165,7 +165,7 @@ static int testMultithreadedGet() { cbc.pos = 0; d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, 1081, - &apc_all, + NULL, NULL, &ahc_echo, "GET", @@ -248,7 +248,7 @@ static int testExternalGet() { cbc.pos = 0; d = MHD_start_daemon(MHD_USE_DEBUG, 1082, - &apc_all, + NULL, NULL, &ahc_echo, "GET", diff --git a/src/daemon/daemontest_post.c b/src/daemon/daemontest_post.c index 5db2d6f8..2c020563 100644 --- a/src/daemon/daemontest_post.c +++ b/src/daemon/daemontest_post.c @@ -197,7 +197,7 @@ static int testMultithreadedPost() { cbc.pos = 0; d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION |MHD_USE_DEBUG, 1081, - &apc_all, + NULL, NULL, &ahc_echo, NULL, @@ -290,7 +290,7 @@ static int testExternalPost() { cbc.pos = 0; d = MHD_start_daemon(MHD_USE_DEBUG, 1082, - &apc_all, + NULL, NULL, &ahc_echo, NULL, diff --git a/src/daemon/daemontest_put.c b/src/daemon/daemontest_put.c index 7a6fe98a..e2f03bdf 100644 --- a/src/daemon/daemontest_put.c +++ b/src/daemon/daemontest_put.c @@ -212,8 +212,7 @@ static int testMultithreadedPut() { cbc.pos = 0; d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, 1081, - &apc_all, - NULL, + NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); @@ -310,7 +309,7 @@ static int testExternalPut() { cbc.pos = 0; d = MHD_start_daemon(MHD_USE_DEBUG, 1082, - &apc_all, + NULL, NULL, &ahc_echo, &done_flag, diff --git a/src/daemon/internal.h b/src/daemon/internal.h index 25d231ee..8aa08243 100644 --- a/src/daemon/internal.h +++ b/src/daemon/internal.h @@ -53,6 +53,10 @@ #define MAX(a,b) ((a)<(b)) ? (b) : (a) #define MIN(a,b) ((a)<(b)) ? (a) : (b) +/** + * Size by which MHD usually tries to increment read/write buffers. + */ +#define MHD_BUF_INC_SIZE 2048 /** * fprintf-like helper function for logging debug @@ -147,6 +151,11 @@ struct MHD_Response { size_t data_size; /** + * Size of the data buffer. + */ + size_t data_buffer_size; + + /** * At what offset in the stream is the * beginning of data located? */ diff --git a/src/daemon/response.c b/src/daemon/response.c index b816a8a5..0326a15b 100644 --- a/src/daemon/response.c +++ b/src/daemon/response.c @@ -168,7 +168,14 @@ MHD_create_response_from_callback(size_t size, memset(retVal, 0, sizeof(struct MHD_Response)); + retVal->data = malloc(MHD_BUF_INC_SIZE); + if (retVal->data == NULL) { + free(retVal); + return NULL; + } + retVal->data_buffer_size = MHD_BUF_INC_SIZE; if (pthread_mutex_init(&retVal->mutex, NULL) != 0) { + free(retVal->data); free(retVal); return NULL; } @@ -258,6 +265,8 @@ MHD_destroy_response(struct MHD_Response * response) { free(pos->value); free(pos); } + if (response->crc != NULL) + free(response->data); free(response); } |