aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2007-08-11 00:14:18 +0000
committerChristian Grothoff <christian@grothoff.org>2007-08-11 00:14:18 +0000
commitc75bf1093162231d4e2f09f399f2d6039d2c321f (patch)
tree7ce3b424f8eeff05bcd54b05c87576a7a81d7a57
parent71edae497964094f63bedb630d8bceb670ac660e (diff)
downloadlibmicrohttpd-c75bf1093162231d4e2f09f399f2d6039d2c321f.tar.gz
libmicrohttpd-c75bf1093162231d4e2f09f399f2d6039d2c321f.zip
100 continue
-rw-r--r--ChangeLog3
-rw-r--r--src/daemon/connection.c52
-rw-r--r--src/daemon/daemontest_get.c4
-rw-r--r--src/daemon/daemontest_post.c4
-rw-r--r--src/daemon/daemontest_put.c5
-rw-r--r--src/daemon/internal.h9
-rw-r--r--src/daemon/response.c9
7 files changed, 53 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index 5be3654e..af5c76fb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,8 @@
1Fri Aug 10 17:31:23 MDT 2007 1Fri Aug 10 17:31:23 MDT 2007
2 Fixed problems with handling of responses created from 2 Fixed problems with handling of responses created from
3 callbacks. Allowing accept policy callback to be NULL 3 callbacks. Allowing accept policy callback to be NULL
4 (to accept from all). Added minimal fileserver example. -CG 4 (to accept from all). Added minimal fileserver example.
5 Only send 100 continue header when specifically requested. - CG
5 6
6Wed Aug 8 01:46:06 MDT 2007 7Wed Aug 8 01:46:06 MDT 2007
7 Added pool allocation and connection limitations (total 8 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 @@
31#include "response.h" 31#include "response.h"
32 32
33/** 33/**
34 * Size by which MHD usually tries to increment read/write buffers.
35 */
36#define MHD_BUF_INC_SIZE 2048
37
38/**
39 * Message to transmit when http 1.1 request is received 34 * Message to transmit when http 1.1 request is received
40 */ 35 */
41#define HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n" 36#define HTTP_100_CONTINUE "HTTP/1.1 100 Continue\r\n\r\n"
@@ -141,6 +136,25 @@ MHD_queue_response(struct MHD_Connection * connection,
141 return MHD_YES; 136 return MHD_YES;
142} 137}
143 138
139/**
140 * Do we (still) need to send a 100 continue
141 * message for this connection?
142 */
143static int
144MHD_need_100_continue(struct MHD_Connection * connection) {
145 const char * expect;
146
147 return ( (connection->version != NULL) &&
148 (0 == strcasecmp(connection->version,
149 MHD_HTTP_VERSION_1_1)) &&
150 (connection->headersReceived == 1) &&
151 (NULL != (expect = MHD_lookup_connection_value(connection,
152 MHD_HEADER_KIND,
153 MHD_HTTP_HEADER_EXPECT))) &&
154 (0 == strcasecmp(expect,
155 "100-continue")) &&
156 (connection->continuePos < strlen(HTTP_100_CONTINUE)) );
157}
144 158
145/** 159/**
146 * Obtain the select sets for this connection 160 * Obtain the select sets for this connection
@@ -186,10 +200,7 @@ MHD_connection_get_fdset(struct MHD_Connection * connection,
186 } 200 }
187 } 201 }
188 if ( (connection->response != NULL) || 202 if ( (connection->response != NULL) ||
189 ( (connection->version != NULL) && 203 MHD_need_100_continue(connection) ) {
190 (0 == strcasecmp(connection->version,
191 MHD_HTTP_VERSION_1_1)) &&
192 (connection->continuePos < strlen(HTTP_100_CONTINUE)) ) ) {
193 FD_SET(fd, write_fd_set); 204 FD_SET(fd, write_fd_set);
194 if (fd > *max_fd) 205 if (fd > *max_fd)
195 *max_fd = fd; 206 *max_fd = fd;
@@ -998,10 +1009,7 @@ MHD_connection_handle_write(struct MHD_Connection * connection) {
998 struct MHD_Response * response; 1009 struct MHD_Response * response;
999 int ret; 1010 int ret;
1000 1011
1001 if ( (connection->version != NULL) && 1012 if (MHD_need_100_continue(connection)) {
1002 (0 == strcasecmp(connection->version,
1003 MHD_HTTP_VERSION_1_1)) &&
1004 (connection->continuePos < strlen(HTTP_100_CONTINUE)) ) {
1005 ret = SEND(connection->socket_fd, 1013 ret = SEND(connection->socket_fd,
1006 &HTTP_100_CONTINUE[connection->continuePos], 1014 &HTTP_100_CONTINUE[connection->continuePos],
1007 strlen(HTTP_100_CONTINUE) - connection->continuePos, 1015 strlen(HTTP_100_CONTINUE) - connection->continuePos,
@@ -1067,24 +1075,18 @@ MHD_connection_handle_write(struct MHD_Connection * connection) {
1067 if (response->crc != NULL) 1075 if (response->crc != NULL)
1068 pthread_mutex_lock(&response->mutex); 1076 pthread_mutex_lock(&response->mutex);
1069 1077
1070 /* prepare send buffer */ 1078 /* prepare send buffer */
1071 if ( (response->data == NULL) || 1079 if ( (response->crc != NULL) &&
1072 (response->data_start > connection->messagePos) || 1080 ( (response->data_start > connection->messagePos) ||
1073 (response->data_start + response->data_size <= connection->messagePos) ) { 1081 (response->data_start + response->data_size <= connection->messagePos) ) ) {
1074 if (response->data_size == 0) {
1075 if (response->data != NULL)
1076 free(response->data);
1077 response->data = malloc(MHD_BUF_INC_SIZE);
1078 response->data_size = MHD_BUF_INC_SIZE;
1079 }
1080 ret = response->crc(response->crc_cls, 1082 ret = response->crc(response->crc_cls,
1081 connection->messagePos, 1083 connection->messagePos,
1082 response->data, 1084 response->data,
1083 MIN(response->data_size, 1085 MIN(response->data_buffer_size,
1084 response->total_size - connection->messagePos)); 1086 response->total_size - connection->messagePos));
1085 if (ret == -1) { 1087 if (ret == -1) {
1086 /* end of message, signal other side by closing! */ 1088 /* end of message, signal other side by closing! */
1087 response->data_size = connection->messagePos; 1089 response->total_size = connection->messagePos;
1088 CLOSE(connection->socket_fd); 1090 CLOSE(connection->socket_fd);
1089 connection->socket_fd = -1; 1091 connection->socket_fd = -1;
1090 if (response->crc != NULL) 1092 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() {
165 cbc.pos = 0; 165 cbc.pos = 0;
166 d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, 166 d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG,
167 1081, 167 1081,
168 &apc_all, 168 NULL,
169 NULL, 169 NULL,
170 &ahc_echo, 170 &ahc_echo,
171 "GET", 171 "GET",
@@ -248,7 +248,7 @@ static int testExternalGet() {
248 cbc.pos = 0; 248 cbc.pos = 0;
249 d = MHD_start_daemon(MHD_USE_DEBUG, 249 d = MHD_start_daemon(MHD_USE_DEBUG,
250 1082, 250 1082,
251 &apc_all, 251 NULL,
252 NULL, 252 NULL,
253 &ahc_echo, 253 &ahc_echo,
254 "GET", 254 "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() {
197 cbc.pos = 0; 197 cbc.pos = 0;
198 d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION |MHD_USE_DEBUG, 198 d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION |MHD_USE_DEBUG,
199 1081, 199 1081,
200 &apc_all, 200 NULL,
201 NULL, 201 NULL,
202 &ahc_echo, 202 &ahc_echo,
203 NULL, 203 NULL,
@@ -290,7 +290,7 @@ static int testExternalPost() {
290 cbc.pos = 0; 290 cbc.pos = 0;
291 d = MHD_start_daemon(MHD_USE_DEBUG, 291 d = MHD_start_daemon(MHD_USE_DEBUG,
292 1082, 292 1082,
293 &apc_all, 293 NULL,
294 NULL, 294 NULL,
295 &ahc_echo, 295 &ahc_echo,
296 NULL, 296 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() {
212 cbc.pos = 0; 212 cbc.pos = 0;
213 d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, 213 d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG,
214 1081, 214 1081,
215 &apc_all, 215 NULL, NULL,
216 NULL,
217 &ahc_echo, 216 &ahc_echo,
218 &done_flag, 217 &done_flag,
219 MHD_OPTION_END); 218 MHD_OPTION_END);
@@ -310,7 +309,7 @@ static int testExternalPut() {
310 cbc.pos = 0; 309 cbc.pos = 0;
311 d = MHD_start_daemon(MHD_USE_DEBUG, 310 d = MHD_start_daemon(MHD_USE_DEBUG,
312 1082, 311 1082,
313 &apc_all, 312 NULL,
314 NULL, 313 NULL,
315 &ahc_echo, 314 &ahc_echo,
316 &done_flag, 315 &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 @@
53#define MAX(a,b) ((a)<(b)) ? (b) : (a) 53#define MAX(a,b) ((a)<(b)) ? (b) : (a)
54#define MIN(a,b) ((a)<(b)) ? (a) : (b) 54#define MIN(a,b) ((a)<(b)) ? (a) : (b)
55 55
56/**
57 * Size by which MHD usually tries to increment read/write buffers.
58 */
59#define MHD_BUF_INC_SIZE 2048
56 60
57/** 61/**
58 * fprintf-like helper function for logging debug 62 * fprintf-like helper function for logging debug
@@ -147,6 +151,11 @@ struct MHD_Response {
147 size_t data_size; 151 size_t data_size;
148 152
149 /** 153 /**
154 * Size of the data buffer.
155 */
156 size_t data_buffer_size;
157
158 /**
150 * At what offset in the stream is the 159 * At what offset in the stream is the
151 * beginning of data located? 160 * beginning of data located?
152 */ 161 */
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,
168 memset(retVal, 168 memset(retVal,
169 0, 169 0,
170 sizeof(struct MHD_Response)); 170 sizeof(struct MHD_Response));
171 retVal->data = malloc(MHD_BUF_INC_SIZE);
172 if (retVal->data == NULL) {
173 free(retVal);
174 return NULL;
175 }
176 retVal->data_buffer_size = MHD_BUF_INC_SIZE;
171 if (pthread_mutex_init(&retVal->mutex, NULL) != 0) { 177 if (pthread_mutex_init(&retVal->mutex, NULL) != 0) {
178 free(retVal->data);
172 free(retVal); 179 free(retVal);
173 return NULL; 180 return NULL;
174 } 181 }
@@ -258,6 +265,8 @@ MHD_destroy_response(struct MHD_Response * response) {
258 free(pos->value); 265 free(pos->value);
259 free(pos); 266 free(pos);
260 } 267 }
268 if (response->crc != NULL)
269 free(response->data);
261 free(response); 270 free(response);
262} 271}
263 272