From db2e47c3ef0c2fb33ad8ae111c51eae9f3268939 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Mon, 16 Apr 2012 16:43:04 +0200 Subject: [PATCH] added 100-continue --- HttpServer/HttpCommTask.cpp | 22 +++++++++++++++++++++- Rest/HttpRequest.cpp | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/HttpServer/HttpCommTask.cpp b/HttpServer/HttpCommTask.cpp index 9ae7f94435..1f21de5c12 100644 --- a/HttpServer/HttpCommTask.cpp +++ b/HttpServer/HttpCommTask.cpp @@ -95,6 +95,7 @@ namespace triagens { LOGGER_TRACE << "HTTP READ FOR " << static_cast(this) << ":\n" << string(readBuffer->c_str(), readPosition); + // check that we know, how to serve this request request = server->createRequest(readBuffer->c_str(), readPosition); if (request == 0) { @@ -102,12 +103,15 @@ namespace triagens { return false; } + // update the connection information, i. e. client and server addresses and ports request->setConnectionInfo(connectionInfo); LOGGER_TRACE << "server port = " << connectionInfo.serverPort << ", client port = " << connectionInfo.clientPort; + // set body start to current position bodyPosition = readPosition; + // and different methods switch (request->requestType()) { case HttpRequest::HTTP_REQUEST_GET: case HttpRequest::HTTP_REQUEST_DELETE: @@ -115,7 +119,7 @@ namespace triagens { bodyLength = request->contentLength(); if (bodyLength > 0) { - LOGGER_DEBUG << "received http GET/DELETE/HEAD request with body length, this should not happen"; + LOGGER_WARNING << "received http GET/DELETE/HEAD request with body length, this should not happen"; readRequestBody = true; } else { @@ -139,6 +143,22 @@ namespace triagens { LOGGER_WARNING << "got corrupted HTTP request '" << string(readBuffer->c_str(), (readPosition < 6 ? readPosition : 6)) << "'"; return false; } + + // check for a 100-continue + if (readRequestBody) { + bool found; + string const& expect = request->header("expect", found); + + if (found && StringUtils::trim(expect) == "100-continue") { + LOGGER_TRACE << "received a 100-continue request"; + + StringBuffer* buffer = new StringBuffer(); + buffer->appendText("HTTP/1.1 100 (Continue)\r\n\r\n"); + + writeBuffers.push_back(buffer); + fillWriteBuffer(); + } + } } else { if (readBuffer->c_str() < end) { diff --git a/Rest/HttpRequest.cpp b/Rest/HttpRequest.cpp index e94e85247e..b1f493254b 100644 --- a/Rest/HttpRequest.cpp +++ b/Rest/HttpRequest.cpp @@ -103,7 +103,7 @@ namespace triagens { // ----------------------------------------------------------------------------- size_t HttpRequest::contentLength () const { - string const& contentLengthString = StringUtils::trim(header("content-length")); + string const contentLengthString = StringUtils::trim(header("content-length")); if (contentLengthString != "") { return StringUtils::uint32(contentLengthString);