diff options
Diffstat (limited to 'src/daemon/connection.c')
-rw-r--r-- | src/daemon/connection.c | 52 |
1 files changed, 27 insertions, 25 deletions
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 | */ | ||
143 | static int | ||
144 | MHD_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) |