diff --git a/src/oatpp/core/data/stream/StreamBufferedProxy.cpp b/src/oatpp/core/data/stream/StreamBufferedProxy.cpp index fa328b8e..b2788dd1 100644 --- a/src/oatpp/core/data/stream/StreamBufferedProxy.cpp +++ b/src/oatpp/core/data/stream/StreamBufferedProxy.cpp @@ -90,6 +90,10 @@ v_io_size InputStreamBufferedProxy::commitReadOffset(v_buff_size count) { return m_buffer.commitReadOffset(count); } +bool InputStreamBufferedProxy::hasUnreadData() { + return m_buffer.availableToRead() > 0; +} + void InputStreamBufferedProxy::setInputStreamIOMode(oatpp::data::stream::IOMode ioMode) { m_inputStream->setInputStreamIOMode(ioMode); } diff --git a/src/oatpp/core/data/stream/StreamBufferedProxy.hpp b/src/oatpp/core/data/stream/StreamBufferedProxy.hpp index 4a911505..a397354a 100644 --- a/src/oatpp/core/data/stream/StreamBufferedProxy.hpp +++ b/src/oatpp/core/data/stream/StreamBufferedProxy.hpp @@ -123,6 +123,8 @@ public: v_io_size commitReadOffset(v_buff_size count); + bool hasUnreadData(); + /** * Set InputStream I/O mode. * @param ioMode diff --git a/src/oatpp/web/server/HttpProcessor.cpp b/src/oatpp/web/server/HttpProcessor.cpp index 3cf2cac2..3016e6b6 100644 --- a/src/oatpp/web/server/HttpProcessor.cpp +++ b/src/oatpp/web/server/HttpProcessor.cpp @@ -74,6 +74,7 @@ HttpProcessor::ProcessingResources::ProcessingResources(const std::shared_ptrconfig->headersOutBufferInitial) , headersReader(&headersInBuffer, components->config->headersReaderChunkSize, components->config->headersReaderMaxSize) , inStream(data::stream::InputStreamBufferedProxy::createShared(connection, base::StrBuffer::createShared(data::buffer::IOBuffer::BUFFER_SIZE))) + , outStream(data::stream::OutputStreamBufferedProxy::createShared(connection, base::StrBuffer::createShared(data::buffer::IOBuffer::BUFFER_SIZE))) {} bool HttpProcessor::processNextRequest(ProcessingResources& resources) { @@ -83,7 +84,8 @@ bool HttpProcessor::processNextRequest(ProcessingResources& resources) { if(error.status.code != 0) { auto response = resources.components->errorHandler->handleError(error.status, "Invalid request headers"); - response->send(resources.connection.get(), &resources.headersOutBuffer, nullptr); + response->send(resources.outStream.get(), &resources.headersOutBuffer, nullptr); + resources.outStream->flush(); return false; } @@ -95,7 +97,8 @@ bool HttpProcessor::processNextRequest(ProcessingResources& resources) { if(!route) { auto response = resources.components->errorHandler->handleError(protocol::http::Status::CODE_404, "Current url has no mapping"); - response->send(resources.connection.get(), &resources.headersOutBuffer, nullptr); + response->send(resources.outStream.get(), &resources.headersOutBuffer, nullptr); + resources.outStream->flush(); return false; } @@ -126,18 +129,21 @@ bool HttpProcessor::processNextRequest(ProcessingResources& resources) { } catch (oatpp::web::protocol::http::HttpError& error) { response = resources.components->errorHandler->handleError(error.getInfo().status, error.getMessage(), error.getHeaders()); - response->send(resources.connection.get(), &resources.headersOutBuffer, nullptr); + response->send(resources.outStream.get(), &resources.headersOutBuffer, nullptr); + resources.outStream->flush(); return false; } catch (std::exception& error) { response = resources.components->errorHandler->handleError(protocol::http::Status::CODE_500, error.what()); - response->send(resources.connection.get(), &resources.headersOutBuffer, nullptr); + response->send(resources.outStream.get(), &resources.headersOutBuffer, nullptr); + resources.outStream->flush(); return false; } catch (...) { response = resources.components->errorHandler->handleError(protocol::http::Status::CODE_500, "Unknown error"); - response->send(resources.connection.get(), &resources.headersOutBuffer, nullptr); + response->send(resources.outStream.get(), &resources.headersOutBuffer, nullptr); + resources.outStream->flush(); return false; } @@ -147,7 +153,10 @@ bool HttpProcessor::processNextRequest(ProcessingResources& resources) { auto contentEncoderProvider = protocol::http::utils::CommunicationUtils::selectEncoder(request, resources.components->contentEncodingProviders); - response->send(resources.connection.get(), &resources.headersOutBuffer, contentEncoderProvider.get()); + response->send(resources.outStream.get(), &resources.headersOutBuffer, contentEncoderProvider.get()); + //if(!resources.inStream->hasUnreadData()) { + resources.outStream->flush(); + //} switch(connectionState) { diff --git a/src/oatpp/web/server/HttpProcessor.hpp b/src/oatpp/web/server/HttpProcessor.hpp index e0fd41f0..7a61673d 100644 --- a/src/oatpp/web/server/HttpProcessor.hpp +++ b/src/oatpp/web/server/HttpProcessor.hpp @@ -160,6 +160,7 @@ private: oatpp::data::stream::BufferOutputStream headersOutBuffer; RequestHeadersReader headersReader; std::shared_ptr inStream; + std::shared_ptr outStream; }; diff --git a/test/oatpp/AllTestsMain.cpp b/test/oatpp/AllTestsMain.cpp index 4c827785..0219d2d2 100644 --- a/test/oatpp/AllTestsMain.cpp +++ b/test/oatpp/AllTestsMain.cpp @@ -70,18 +70,6 @@ namespace { -v_int64 calcNextP2(v_int64 v) { - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - v |= v >> 32; - v++; - return v; -} - void runTests() { oatpp::base::Environment::printCompilationConfig(); @@ -89,6 +77,7 @@ void runTests() { OATPP_LOGD("aaa", "coroutine size=%d", sizeof(oatpp::async::AbstractCoroutine)); OATPP_LOGD("aaa", "action size=%d", sizeof(oatpp::async::Action)); +/* OATPP_RUN_TEST(oatpp::test::base::CommandLineArgumentsTest); OATPP_RUN_TEST(oatpp::test::base::LoggerTest); @@ -169,11 +158,11 @@ void runTests() { test_port.run(); } - +*/ { - oatpp::test::web::FullTest test_virtual(0, 1000); - test_virtual.run(); +// oatpp::test::web::FullTest test_virtual(0, 1000); +// test_virtual.run(); oatpp::test::web::FullTest test_port(8000, 10); test_port.run(); diff --git a/test/oatpp/web/FullTest.cpp b/test/oatpp/web/FullTest.cpp index 71d97aba..72b29d46 100644 --- a/test/oatpp/web/FullTest.cpp +++ b/test/oatpp/web/FullTest.cpp @@ -147,7 +147,7 @@ void FullTest::onRun() { runner.addController(app::BearerAuthorizationController::createShared()); runner.run([this, &runner] { - +/* OATPP_COMPONENT(std::shared_ptr, clientConnectionProvider); OATPP_COMPONENT(std::shared_ptr, objectMapper); @@ -472,6 +472,9 @@ void FullTest::onRun() { } } +*/ + + std::this_thread::sleep_for(std::chrono::minutes(10)); }, std::chrono::minutes(10));