From a9366e931500a3ee1ac6ed30edbdcea708dcdcd8 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 8 Aug 2007 08:55:18 +0000 Subject: mantis 1263 --- src/daemon/Makefile.am | 7 +++++++ src/daemon/connection.c | 32 +++++++++++++++++++++++++++++++- src/daemon/daemontest_get.c | 33 ++++++++++++++++++++++++++++++--- src/daemon/internal.h | 6 ++++++ 4 files changed, 74 insertions(+), 4 deletions(-) (limited to 'src/daemon') diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am index e0174f40..e02b2c7d 100644 --- a/src/daemon/Makefile.am +++ b/src/daemon/Makefile.am @@ -33,6 +33,7 @@ check_PROGRAMS = \ daemontest_get \ daemontest_post \ daemontest_put \ + daemontest_get11 \ daemontest_post11 \ daemontest_put11 @@ -61,6 +62,12 @@ daemontest_put_LDADD = \ $(top_builddir)/src/daemon/libmicrohttpd.la \ @LIBCURL@ +daemontest_get11_SOURCES = \ + daemontest_get.c +daemontest_get11_LDADD = \ + $(top_builddir)/src/daemon/libmicrohttpd.la \ + @LIBCURL@ + daemontest_post11_SOURCES = \ daemontest_post.c daemontest_post11_LDADD = \ diff --git a/src/daemon/connection.c b/src/daemon/connection.c index bb3d8990..272fb802 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c @@ -35,6 +35,10 @@ */ #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" /** * Get all of the headers from the request. @@ -170,7 +174,11 @@ MHD_connection_get_fdset(struct MHD_Connection * connection, } } } - if (connection->response != NULL) { + if ( (connection->response != NULL) || + ( (connection->version != NULL) && + (0 == strcasecmp(connection->version, + MHD_HTTP_VERSION_1_1)) && + (connection->continuePos < strlen(HTTP_100_CONTINUE)) ) ) { FD_SET(fd, write_fd_set); if (fd > *max_fd) *max_fd = fd; @@ -921,6 +929,27 @@ 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)) ) { + ret = SEND(connection->socket_fd, + &HTTP_100_CONTINUE[connection->continuePos], + strlen(HTTP_100_CONTINUE) - connection->continuePos, + 0); + if (ret < 0) { + if (errno == EINTR) + return MHD_YES; + MHD_DLOG(connection->daemon, + "Failed to send data: %s\n", + STRERROR(errno)); + CLOSE(connection->socket_fd); + connection->socket_fd = -1; + return MHD_YES; + } + connection->continuePos += ret; + return MHD_YES; + } response = connection->response; if(response == NULL) { MHD_DLOG(connection->daemon, @@ -1027,6 +1056,7 @@ MHD_connection_handle_write(struct MHD_Connection * connection) { (connection->headersReceived == 0) ) abort(); /* internal error */ MHD_destroy_response(response); + connection->continuePos = 0; connection->responseCode = 0; connection->response = NULL; connection->headersReceived = 0; diff --git a/src/daemon/daemontest_get.c b/src/daemon/daemontest_get.c index 3cd158ff..2366c281 100644 --- a/src/daemon/daemontest_get.c +++ b/src/daemon/daemontest_get.c @@ -33,6 +33,8 @@ #include #include +static int oneone; + static int apc_all(void * cls, const struct sockaddr * addr, socklen_t addrlen) { @@ -122,7 +124,15 @@ static int testInternalGet() { curl_easy_setopt(c, CURLOPT_CONNECTTIMEOUT, 2L); - // NOTE: use of CONNECTTIMEOUT without also + if (oneone) + curl_easy_setopt(c, + CURLOPT_HTTP_VERSION, + CURL_HTTP_VERSION_1_1); + else + curl_easy_setopt(c, + CURLOPT_HTTP_VERSION, + CURL_HTTP_VERSION_1_0); + // NOTE: use of CONNECTTIMEOUT without also // setting NOSIGNAL results in really weird // crashes on my system! curl_easy_setopt(c, @@ -184,7 +194,15 @@ static int testMultithreadedGet() { curl_easy_setopt(c, CURLOPT_TIMEOUT, 2L); - curl_easy_setopt(c, + if (oneone) + curl_easy_setopt(c, + CURLOPT_HTTP_VERSION, + CURL_HTTP_VERSION_1_1); + else + curl_easy_setopt(c, + CURLOPT_HTTP_VERSION, + CURL_HTTP_VERSION_1_0); + curl_easy_setopt(c, CURLOPT_CONNECTTIMEOUT, 2L); // NOTE: use of CONNECTTIMEOUT without also @@ -256,7 +274,15 @@ static int testExternalGet() { curl_easy_setopt(c, CURLOPT_FAILONERROR, 1); - curl_easy_setopt(c, + if (oneone) + curl_easy_setopt(c, + CURLOPT_HTTP_VERSION, + CURL_HTTP_VERSION_1_1); + else + curl_easy_setopt(c, + CURLOPT_HTTP_VERSION, + CURL_HTTP_VERSION_1_0); + curl_easy_setopt(c, CURLOPT_TIMEOUT, 5L); curl_easy_setopt(c, @@ -364,6 +390,7 @@ int main(int argc, char * const * argv) { unsigned int errorCount = 0; + oneone = NULL != strstr(argv[0], "11"); if (0 != curl_global_init(CURL_GLOBAL_WIN32)) return 2; errorCount += testInternalGet(); diff --git a/src/daemon/internal.h b/src/daemon/internal.h index efadb33a..1c3525f6 100644 --- a/src/daemon/internal.h +++ b/src/daemon/internal.h @@ -271,6 +271,12 @@ struct MHD_Connection { */ size_t uploadSize; + /** + * Position in the 100 CONTINUE message that + * we need to send when receiving http 1.1 requests. + */ + size_t continuePos; + /** * Length of the foreign address. */ -- cgit v1.2.3