mirror of
https://git.gnunet.org/libmicrohttpd.git
synced 2026-09-25 04:09:31 +03:00
100 continue
This commit is contained in:
@@ -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
|
||||
|
||||
+27
-25
@@ -30,11 +30,6 @@
|
||||
#include "memorypool.h"
|
||||
#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
|
||||
*/
|
||||
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
@@ -146,6 +150,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?
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user