From a0a8223fb7703b249d01bf663410175189f0f9b4 Mon Sep 17 00:00:00 2001 From: lganzzzo Date: Sun, 14 Jul 2019 02:58:52 +0300 Subject: [PATCH] Code cleanup. Remove unnecessary shared_ptrs. --- src/oatpp/core/data/buffer/FIFOBuffer.cpp | 24 ++++----- src/oatpp/core/data/buffer/FIFOBuffer.hpp | 6 +-- src/oatpp/core/data/stream/ChunkedBuffer.cpp | 6 +-- src/oatpp/core/data/stream/ChunkedBuffer.hpp | 2 +- src/oatpp/core/data/stream/Stream.cpp | 2 +- src/oatpp/core/data/stream/Stream.hpp | 2 +- .../core/data/stream/StreamBufferedProxy.cpp | 6 +-- src/oatpp/web/client/HttpRequestExecutor.cpp | 8 +-- .../protocol/http/incoming/BodyDecoder.cpp | 44 ++++++++++------- .../protocol/http/incoming/BodyDecoder.hpp | 49 +++++++++---------- .../web/protocol/http/incoming/Request.cpp | 10 ++-- .../web/protocol/http/incoming/Request.hpp | 14 +++--- .../web/protocol/http/incoming/Response.cpp | 10 ++-- .../web/protocol/http/incoming/Response.hpp | 10 ++-- .../http/incoming/SimpleBodyDecoder.cpp | 11 +++-- .../http/incoming/SimpleBodyDecoder.hpp | 18 +++---- src/oatpp/web/protocol/http/outgoing/Body.hpp | 4 +- .../web/protocol/http/outgoing/BufferBody.cpp | 4 +- .../web/protocol/http/outgoing/BufferBody.hpp | 4 +- .../http/outgoing/ChunkedBufferBody.cpp | 2 +- .../http/outgoing/ChunkedBufferBody.hpp | 2 +- .../web/protocol/http/outgoing/Request.cpp | 2 +- .../web/protocol/http/outgoing/Request.hpp | 2 +- .../web/protocol/http/outgoing/Response.cpp | 2 +- .../web/protocol/http/outgoing/Response.hpp | 4 +- .../web/server/HttpConnectionHandler.cpp | 2 +- test/oatpp/network/virtual_/InterfaceTest.cpp | 4 +- test/oatpp/web/FullAsyncTest.cpp | 6 +-- test/oatpp/web/FullTest.cpp | 10 ++-- .../web/mime/multipart/StatefulParserTest.cpp | 2 +- .../web/server/api/ApiControllerTest.cpp | 18 +++---- 31 files changed, 144 insertions(+), 146 deletions(-) diff --git a/src/oatpp/core/data/buffer/FIFOBuffer.cpp b/src/oatpp/core/data/buffer/FIFOBuffer.cpp index 7c127315..d4e284ab 100644 --- a/src/oatpp/core/data/buffer/FIFOBuffer.cpp +++ b/src/oatpp/core/data/buffer/FIFOBuffer.cpp @@ -161,7 +161,7 @@ data::v_io_size FIFOBuffer::write(const void *data, data::v_io_size count) { } -data::v_io_size FIFOBuffer::readAndWriteToStream(data::stream::OutputStream& stream, data::v_io_size count) { +data::v_io_size FIFOBuffer::readAndWriteToStream(data::stream::OutputStream* stream, data::v_io_size count) { if(!m_canRead) { return data::IOError::WAIT_RETRY; @@ -178,7 +178,7 @@ data::v_io_size FIFOBuffer::readAndWriteToStream(data::stream::OutputStream& str if(size > count) { size = count; } - auto bytesWritten = stream.write(&m_buffer[m_readPosition], size); + auto bytesWritten = stream->write(&m_buffer[m_readPosition], size); if(bytesWritten > 0) { m_readPosition += bytesWritten; if (m_readPosition == m_writePosition) { @@ -195,7 +195,7 @@ data::v_io_size FIFOBuffer::readAndWriteToStream(data::stream::OutputStream& str size = count; } else if(size == 0) { - auto bytesWritten = stream.write(m_buffer, m_writePosition); + auto bytesWritten = stream->write(m_buffer, m_writePosition); if(bytesWritten > 0) { m_readPosition = bytesWritten; if (m_readPosition == m_writePosition) { @@ -206,7 +206,7 @@ data::v_io_size FIFOBuffer::readAndWriteToStream(data::stream::OutputStream& str } - auto bytesWritten = stream.write(&m_buffer[m_readPosition], size); + auto bytesWritten = stream->write(&m_buffer[m_readPosition], size); if(bytesWritten > 0) { m_readPosition += bytesWritten; } @@ -214,7 +214,7 @@ data::v_io_size FIFOBuffer::readAndWriteToStream(data::stream::OutputStream& str } -data::v_io_size FIFOBuffer::readFromStreamAndWrite(data::stream::InputStream& stream, data::v_io_size count) { +data::v_io_size FIFOBuffer::readFromStreamAndWrite(data::stream::InputStream* stream, data::v_io_size count) { if(m_canRead && m_writePosition == m_readPosition) { return data::IOError::WAIT_RETRY; @@ -231,7 +231,7 @@ data::v_io_size FIFOBuffer::readFromStreamAndWrite(data::stream::InputStream& st if(size > count) { size = count; } - auto bytesRead = stream.read(&m_buffer[m_writePosition], size); + auto bytesRead = stream->read(&m_buffer[m_writePosition], size); if(bytesRead > 0) { m_writePosition += bytesRead; m_canRead = true; @@ -246,7 +246,7 @@ data::v_io_size FIFOBuffer::readFromStreamAndWrite(data::stream::InputStream& st size = count; } else if(size == 0) { - auto bytesRead = stream.read(m_buffer, m_readPosition); + auto bytesRead = stream->read(m_buffer, m_readPosition); if(bytesRead > 0) { m_writePosition = bytesRead; m_canRead = true; @@ -256,7 +256,7 @@ data::v_io_size FIFOBuffer::readFromStreamAndWrite(data::stream::InputStream& st } - auto bytesRead = stream.read(&m_buffer[m_writePosition], size); + auto bytesRead = stream->read(&m_buffer[m_writePosition], size); if(bytesRead > 0) { m_writePosition += bytesRead; m_canRead = true; @@ -266,7 +266,7 @@ data::v_io_size FIFOBuffer::readFromStreamAndWrite(data::stream::InputStream& st } -data::v_io_size FIFOBuffer::flushToStream(data::stream::OutputStream& stream) { +data::v_io_size FIFOBuffer::flushToStream(data::stream::OutputStream* stream) { if(!m_canRead) { return 0; @@ -275,10 +275,10 @@ data::v_io_size FIFOBuffer::flushToStream(data::stream::OutputStream& stream) { data::v_io_size result = 0; if(m_readPosition < m_writePosition) { - result = data::stream::writeExactSizeData(&stream, &m_buffer[m_readPosition], m_writePosition - m_readPosition); + result = data::stream::writeExactSizeData(stream, &m_buffer[m_readPosition], m_writePosition - m_readPosition); } else { - auto result = data::stream::writeExactSizeData(&stream, &m_buffer[m_readPosition], m_bufferSize - m_readPosition); - result += data::stream::writeExactSizeData(&stream, m_buffer, m_writePosition); + auto result = data::stream::writeExactSizeData(stream, &m_buffer[m_readPosition], m_bufferSize - m_readPosition); + result += data::stream::writeExactSizeData(stream, m_buffer, m_writePosition); } setBufferPosition(0, 0, false); diff --git a/src/oatpp/core/data/buffer/FIFOBuffer.hpp b/src/oatpp/core/data/buffer/FIFOBuffer.hpp index bf65311b..23c1c690 100644 --- a/src/oatpp/core/data/buffer/FIFOBuffer.hpp +++ b/src/oatpp/core/data/buffer/FIFOBuffer.hpp @@ -107,7 +107,7 @@ public: * @param count * @return [1..count], IOErrors. */ - data::v_io_size readAndWriteToStream(data::stream::OutputStream& stream, data::v_io_size count); + data::v_io_size readAndWriteToStream(data::stream::OutputStream* stream, data::v_io_size count); /** * call stream.read() and then write bytes read to buffer @@ -115,14 +115,14 @@ public: * @param count * @return */ - data::v_io_size readFromStreamAndWrite(data::stream::InputStream& stream, data::v_io_size count); + data::v_io_size readFromStreamAndWrite(data::stream::InputStream* stream, data::v_io_size count); /** * flush all availableToRead bytes to stream * @param stream * @return */ - data::v_io_size flushToStream(data::stream::OutputStream& stream); + data::v_io_size flushToStream(data::stream::OutputStream* stream); /** * flush all availableToRead bytes to stream in asynchronous manner diff --git a/src/oatpp/core/data/stream/ChunkedBuffer.cpp b/src/oatpp/core/data/stream/ChunkedBuffer.cpp index 32fde643..ef8d4bcb 100644 --- a/src/oatpp/core/data/stream/ChunkedBuffer.cpp +++ b/src/oatpp/core/data/stream/ChunkedBuffer.cpp @@ -209,18 +209,18 @@ oatpp::String ChunkedBuffer::getSubstring(data::v_io_size pos, return str; } -bool ChunkedBuffer::flushToStream(const std::shared_ptr& stream){ +bool ChunkedBuffer::flushToStream(OutputStream* stream){ data::v_io_size pos = m_size; auto curr = m_firstEntry; while (pos > 0) { if(pos > CHUNK_ENTRY_SIZE) { - auto res = data::stream::writeExactSizeData(stream.get(), curr->chunk, CHUNK_ENTRY_SIZE); + auto res = data::stream::writeExactSizeData(stream, curr->chunk, CHUNK_ENTRY_SIZE); if(res != CHUNK_ENTRY_SIZE) { return false; } pos -= res; } else { - auto res = data::stream::writeExactSizeData(stream.get(), curr->chunk, pos); + auto res = data::stream::writeExactSizeData(stream, curr->chunk, pos); if(res != pos) { return false; } diff --git a/src/oatpp/core/data/stream/ChunkedBuffer.hpp b/src/oatpp/core/data/stream/ChunkedBuffer.hpp index 259074ed..0089f5fe 100644 --- a/src/oatpp/core/data/stream/ChunkedBuffer.hpp +++ b/src/oatpp/core/data/stream/ChunkedBuffer.hpp @@ -214,7 +214,7 @@ public: * @param stream - &id:oatpp::data::stream::OutputStream; stream to write all data to. * @return - `true` if no errors occured. **will be refactored to return actual amount of bytes flushed**. */ - bool flushToStream(const std::shared_ptr& stream); + bool flushToStream(OutputStream* stream); /** * Write all data from ChunkedBuffer to &id:oatpp::data::stream::OutputStream; in asynchronous manner. diff --git a/src/oatpp/core/data/stream/Stream.cpp b/src/oatpp/core/data/stream/Stream.cpp index 80dec83b..5b6aa613 100644 --- a/src/oatpp/core/data/stream/Stream.cpp +++ b/src/oatpp/core/data/stream/Stream.cpp @@ -224,7 +224,7 @@ ConsistentOutputStream& operator << (ConsistentOutputStream& s, bool value) { return s; } -oatpp::data::v_io_size transfer(const std::shared_ptr& fromStream, +oatpp::data::v_io_size transfer(InputStream* fromStream, WriteCallback* writeCallback, oatpp::data::v_io_size transferSize, void* buffer, diff --git a/src/oatpp/core/data/stream/Stream.hpp b/src/oatpp/core/data/stream/Stream.hpp index c1fbb918..dead9041 100644 --- a/src/oatpp/core/data/stream/Stream.hpp +++ b/src/oatpp/core/data/stream/Stream.hpp @@ -409,7 +409,7 @@ public: * @param bufferSize * @return - amount of bytes actually transferred. */ -oatpp::data::v_io_size transfer(const std::shared_ptr& fromStream, +oatpp::data::v_io_size transfer(InputStream* fromStream, WriteCallback* writeCallback, oatpp::data::v_io_size transferSize, void* buffer, diff --git a/src/oatpp/core/data/stream/StreamBufferedProxy.cpp b/src/oatpp/core/data/stream/StreamBufferedProxy.cpp index 6947ae6a..99dcc60b 100644 --- a/src/oatpp/core/data/stream/StreamBufferedProxy.cpp +++ b/src/oatpp/core/data/stream/StreamBufferedProxy.cpp @@ -30,7 +30,7 @@ data::v_io_size OutputStreamBufferedProxy::write(const void *data, data::v_io_si if(m_buffer->availableToWrite() > 0) { return m_buffer->write(data, count); } else { - auto bytesFlushed = m_buffer->readAndWriteToStream(*m_outputStream, m_buffer->getBufferSize()); + auto bytesFlushed = m_buffer->readAndWriteToStream(m_outputStream.get(), m_buffer->getBufferSize()); if(bytesFlushed > 0) { return m_buffer->write(data, count); } @@ -51,7 +51,7 @@ oatpp::data::stream::IOMode OutputStreamBufferedProxy::getOutputStreamIOMode() { } data::v_io_size OutputStreamBufferedProxy::flush() { - return m_buffer->flushToStream(*m_outputStream); + return m_buffer->flushToStream(m_outputStream.get()); } oatpp::async::CoroutineStarter OutputStreamBufferedProxy::flushAsync() { @@ -63,7 +63,7 @@ data::v_io_size InputStreamBufferedProxy::read(void *data, data::v_io_size count if(m_buffer.availableToRead() > 0) { return m_buffer.read(data, count); } else { - auto bytesBuffered = m_buffer.readFromStreamAndWrite(*m_inputStream, m_buffer.getBufferSize()); + auto bytesBuffered = m_buffer.readFromStreamAndWrite(m_inputStream.get(), m_buffer.getBufferSize()); if(bytesBuffered > 0) { return m_buffer.read(data, count); } diff --git a/src/oatpp/web/client/HttpRequestExecutor.cpp b/src/oatpp/web/client/HttpRequestExecutor.cpp index 75cb3fd4..0c3b359d 100644 --- a/src/oatpp/web/client/HttpRequestExecutor.cpp +++ b/src/oatpp/web/client/HttpRequestExecutor.cpp @@ -113,10 +113,10 @@ HttpRequestExecutor::execute(const String& method, request->putHeaderIfNotExists(oatpp::web::protocol::http::Header::CONNECTION, oatpp::web::protocol::http::Header::Value::CONNECTION_KEEP_ALIVE); auto ioBuffer = oatpp::data::buffer::IOBuffer::createShared(); - - auto upStream = oatpp::data::stream::OutputStreamBufferedProxy::createShared(connection, ioBuffer); - request->send(upStream); - upStream->flush(); + + oatpp::data::stream::OutputStreamBufferedProxy upStream(connection, ioBuffer, (p_char8)ioBuffer->getData(), ioBuffer->getSize()); + request->send(&upStream); + upStream.flush(); oatpp::web::protocol::http::incoming::ResponseHeadersReader headerReader(ioBuffer->getData(), ioBuffer->getSize(), 4096); oatpp::web::protocol::http::HttpError::Info error; diff --git a/src/oatpp/web/protocol/http/incoming/BodyDecoder.cpp b/src/oatpp/web/protocol/http/incoming/BodyDecoder.cpp index 0668820f..4d1e0275 100644 --- a/src/oatpp/web/protocol/http/incoming/BodyDecoder.cpp +++ b/src/oatpp/web/protocol/http/incoming/BodyDecoder.cpp @@ -26,37 +26,43 @@ namespace oatpp { namespace web { namespace protocol { namespace http { namespace incoming { +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// BodyDecoder::ToStringDecoder + BodyDecoder::ToStringDecoder::ToStringDecoder(const BodyDecoder* decoder, const Headers& headers, - const std::shared_ptr& bodyStream) + const std::shared_ptr& bodyStream) : m_decoder(decoder) , m_headers(headers) , m_bodyStream(bodyStream) - , m_chunkedBuffer(oatpp::data::stream::ChunkedBuffer::createShared()) + , m_chunkedBuffer(data::stream::ChunkedBuffer::createShared()) {} -void BodyDecoder::decode(const Headers& headers, - const std::shared_ptr& bodyStream, - const std::shared_ptr& toStream) const -{ - oatpp::data::stream::DefaultWriteCallback callback(toStream.get()); - decode(headers, bodyStream, &callback); -} - -oatpp::async::CoroutineStarter BodyDecoder::decodeAsync(const Headers& headers, - const std::shared_ptr& bodyStream, - const std::shared_ptr& toStream) const -{ - auto callback = std::make_shared(toStream); - return decodeAsync(headers, bodyStream, callback); -} - async::Action BodyDecoder::ToStringDecoder::act() { - return m_decoder->decodeAsync(m_headers, m_bodyStream, m_chunkedBuffer).next(yieldTo(&ToStringDecoder::onDecoded)); + return m_decoder->decodeToStreamAsync(m_headers, m_bodyStream, m_chunkedBuffer).next(yieldTo(&ToStringDecoder::onDecoded)); } async::Action BodyDecoder::ToStringDecoder::onDecoded() { return _return(m_chunkedBuffer->toString()); } +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// BodyDecoder + +void BodyDecoder::decodeToStream(const Headers& headers, + data::stream::InputStream* bodyStream, + data::stream::OutputStream* toStream) const +{ + data::stream::DefaultWriteCallback callback(toStream); + decode(headers, bodyStream, &callback); +} + +async::CoroutineStarter BodyDecoder::decodeToStreamAsync(const Headers& headers, + const std::shared_ptr& bodyStream, + const std::shared_ptr& toStream) const +{ + auto callback = std::make_shared(toStream); + return decodeAsync(headers, bodyStream, callback); +} + }}}}} diff --git a/src/oatpp/web/protocol/http/incoming/BodyDecoder.hpp b/src/oatpp/web/protocol/http/incoming/BodyDecoder.hpp index cfa3caeb..a8703385 100644 --- a/src/oatpp/web/protocol/http/incoming/BodyDecoder.hpp +++ b/src/oatpp/web/protocol/http/incoming/BodyDecoder.hpp @@ -103,22 +103,18 @@ public: /** * Implement this method! Decode bodyStream and write decoded data to toStream. * @param headers - Headers map. &id:oatpp::web::protocol::http::Headers;. - * @param bodyStream - `std::shared_ptr` to &id:oatpp::data::stream::InputStream;. + * @param bodyStream - pointer to &id:oatpp::data::stream::InputStream;. * @param writeCallback - &id:oatpp::data::stream::WriteCallback;. */ - virtual void decode(const Headers& headers, - const std::shared_ptr& bodyStream, - oatpp::data::stream::WriteCallback* writeCallback) const = 0; + virtual void decode(const Headers& headers, data::stream::InputStream* bodyStream, data::stream::WriteCallback* writeCallback) const = 0; /** * Decode using &id:oatpp::data::stream::DefaultWriteCallback;. * @param headers - Headers map. &id:oatpp::web::protocol::http::Headers;. - * @param bodyStream - `std::shared_ptr` to &id:oatpp::data::stream::InputStream;. - * @param toStream - `std::shared_ptr` to &id:oatpp::data::stream::OutputStream;. + * @param bodyStream - pointer to &id:oatpp::data::stream::InputStream;. + * @param toStream - pointer to &id:oatpp::data::stream::OutputStream;. */ - void decode(const Headers& headers, - const std::shared_ptr& bodyStream, - const std::shared_ptr& toStream) const; + void decodeToStream(const Headers& headers, data::stream::InputStream* bodyStream, data::stream::OutputStream* toStream) const; /** * Implement this method! Same as &l:BodyDecoder::decode (); but Async. @@ -128,8 +124,8 @@ public: * @return - &id:oatpp::async::CoroutineStarter;. */ virtual oatpp::async::CoroutineStarter decodeAsync(const Headers& headers, - const std::shared_ptr& bodyStream, - const std::shared_ptr& writeCallback) const = 0; + const std::shared_ptr& bodyStream, + const std::shared_ptr& writeCallback) const = 0; /** * Decode in asynchronous manner using &id:oatpp::data::stream::DefaultAsyncWriteCallback;. @@ -138,35 +134,34 @@ public: * @param toStream - `std::shared_ptr` to &id:oatpp::data::stream::OutputStream;. * @return - &id:oatpp::async::CoroutineStarter;. */ - oatpp::async::CoroutineStarter decodeAsync(const Headers& headers, - const std::shared_ptr& bodyStream, - const std::shared_ptr& toStream) const; + oatpp::async::CoroutineStarter decodeToStreamAsync(const Headers& headers, + const std::shared_ptr& bodyStream, + const std::shared_ptr& toStream) const; /** * Read body stream and decode it to string. * @param headers - Headers map. &id:oatpp::web::protocol::http::Headers;. - * @param bodyStream - `std::shared_ptr` to &id:oatpp::data::stream::InputStream;. + * @param bodyStream - pointer to &id:oatpp::data::stream::InputStream;. * @return - &oatpp::String;. */ - oatpp::String decodeToString(const Headers& headers, - const std::shared_ptr& bodyStream) const { - auto chunkedBuffer = oatpp::data::stream::ChunkedBuffer::createShared(); - decode(headers, bodyStream, chunkedBuffer); - return chunkedBuffer->toString(); + oatpp::String decodeToString(const Headers& headers, data::stream::InputStream* bodyStream) const { + oatpp::data::stream::ChunkedBuffer stream; + decodeToStream(headers, bodyStream, &stream); + return stream.toString(); } /** * Read body stream, decode, and deserialize it as DTO Object (see [Data Transfer Object (DTO)](https://oatpp.io/docs/components/dto/)). * @tparam Type - DTO object type. * @param headers - Headers map. &id:oatpp::web::protocol::http::Headers;. - * @param bodyStream - `std::shared_ptr` to &id:oatpp::data::stream::InputStream;. - * @param objectMapper - `std::shared_ptr` to &id:oatpp::data::mapping::ObjectMapper;. + * @param bodyStream - pointer to &id:oatpp::data::stream::InputStream;. + * @param objectMapper - pointer to &id:oatpp::data::mapping::ObjectMapper;. * @return - deserialized DTO object. */ template typename Type::ObjectWrapper decodeToDto(const Headers& headers, - const std::shared_ptr& bodyStream, - const std::shared_ptr& objectMapper) const { + data::stream::InputStream* bodyStream, + data::mapping::ObjectMapper* objectMapper) const { return objectMapper->readFromString(decodeToString(headers, bodyStream)); } @@ -177,7 +172,7 @@ public: * @return - &id:oatpp::async::CoroutineStarterForResult;. */ oatpp::async::CoroutineStarterForResult - decodeToStringAsync(const Headers& headers, const std::shared_ptr& bodyStream) const { + decodeToStringAsync(const Headers& headers, const std::shared_ptr& bodyStream) const { return ToStringDecoder::startForResult(this, headers, bodyStream); } @@ -192,8 +187,8 @@ public: template oatpp::async::CoroutineStarterForResult decodeToDtoAsync(const Headers& headers, - const std::shared_ptr& bodyStream, - const std::shared_ptr& objectMapper) const { + const std::shared_ptr& bodyStream, + const std::shared_ptr& objectMapper) const { return ToDtoDecoder::startForResult(this, headers, bodyStream, objectMapper); } diff --git a/src/oatpp/web/protocol/http/incoming/Request.cpp b/src/oatpp/web/protocol/http/incoming/Request.cpp index ad70b7f4..63b9d3b2 100644 --- a/src/oatpp/web/protocol/http/incoming/Request.cpp +++ b/src/oatpp/web/protocol/http/incoming/Request.cpp @@ -105,16 +105,16 @@ oatpp::String Request::getPathTail() const { return m_pathVariables.getTail(); } -void Request::streamBody(const std::shared_ptr& toStream) const { - m_bodyDecoder->decode(m_headers, m_bodyStream, toStream); +void Request::transferBodyToStream(oatpp::data::stream::OutputStream* toStream) const { + m_bodyDecoder->decodeToStream(m_headers, m_bodyStream.get(), toStream); } oatpp::String Request::readBodyToString() const { - return m_bodyDecoder->decodeToString(m_headers, m_bodyStream); + return m_bodyDecoder->decodeToString(m_headers, m_bodyStream.get()); } -oatpp::async::CoroutineStarter Request::streamBodyAsync(const std::shared_ptr& toStream) const { - return m_bodyDecoder->decodeAsync(m_headers, m_bodyStream, toStream); +oatpp::async::CoroutineStarter Request::transferBodyToStreamAsync(const std::shared_ptr& toStream) const { + return m_bodyDecoder->decodeToStreamAsync(m_headers, m_bodyStream, toStream); } }}}}} \ No newline at end of file diff --git a/src/oatpp/web/protocol/http/incoming/Request.hpp b/src/oatpp/web/protocol/http/incoming/Request.hpp index 7b246b57..a62507a4 100644 --- a/src/oatpp/web/protocol/http/incoming/Request.hpp +++ b/src/oatpp/web/protocol/http/incoming/Request.hpp @@ -153,7 +153,7 @@ public: * Stream content of the body-stream to toStream * @param toStream */ - void streamBody(const std::shared_ptr& toStream) const; + void transferBodyToStream(oatpp::data::stream::OutputStream* toStream) const; /** * Transfer body stream to string @@ -168,8 +168,8 @@ public: * @return DTO */ template - typename Type::ObjectWrapper readBodyToDto(const std::shared_ptr& objectMapper) const { - return objectMapper->readFromString(m_bodyDecoder->decodeToString(m_headers, m_bodyStream)); + typename Type::ObjectWrapper readBodyToDto(data::mapping::ObjectMapper* objectMapper) const { + return objectMapper->readFromString(m_bodyDecoder->decodeToString(m_headers, m_bodyStream.get())); } /** @@ -180,9 +180,9 @@ public: * @return DTO */ template - void readBodyToDto(oatpp::data::mapping::type::PolymorphicWrapper& objectWrapper, - const std::shared_ptr& objectMapper) const { - objectWrapper = objectMapper->readFromString(m_bodyDecoder->decodeToString(m_headers, m_bodyStream)); + void readBodyToDto(data::mapping::type::PolymorphicWrapper& objectWrapper, + data::mapping::ObjectMapper* objectMapper) const { + objectWrapper = objectMapper->readFromString(m_bodyDecoder->decodeToString(m_headers, m_bodyStream.get())); } // Async @@ -192,7 +192,7 @@ public: * @param toStream * @return - &id:oatpp::async::CoroutineStarter;. */ - oatpp::async::CoroutineStarter streamBodyAsync(const std::shared_ptr& toStream) const; + oatpp::async::CoroutineStarter transferBodyToStreamAsync(const std::shared_ptr& toStream) const; /** * Transfer body stream to string Async. diff --git a/src/oatpp/web/protocol/http/incoming/Response.cpp b/src/oatpp/web/protocol/http/incoming/Response.cpp index 4a251793..e8182a2a 100644 --- a/src/oatpp/web/protocol/http/incoming/Response.cpp +++ b/src/oatpp/web/protocol/http/incoming/Response.cpp @@ -66,16 +66,16 @@ std::shared_ptr Response::getBodyDecoder() co return m_bodyDecoder; } -void Response::streamBody(const std::shared_ptr& toStream) const { - m_bodyDecoder->decode(m_headers, m_bodyStream, toStream); +void Response::transferBodyToStream(oatpp::data::stream::OutputStream* toStream) const { + m_bodyDecoder->decodeToStream(m_headers, m_bodyStream.get(), toStream); } oatpp::String Response::readBodyToString() const { - return m_bodyDecoder->decodeToString(m_headers, m_bodyStream); + return m_bodyDecoder->decodeToString(m_headers, m_bodyStream.get()); } -oatpp::async::CoroutineStarter Response::streamBodyAsync(const std::shared_ptr& toStream) const { - return m_bodyDecoder->decodeAsync(m_headers, m_bodyStream, toStream); +oatpp::async::CoroutineStarter Response::transferBodyToStreamAsync(const std::shared_ptr& toStream) const { + return m_bodyDecoder->decodeToStreamAsync(m_headers, m_bodyStream, toStream); } }}}}} diff --git a/src/oatpp/web/protocol/http/incoming/Response.hpp b/src/oatpp/web/protocol/http/incoming/Response.hpp index 6df594b2..88af3750 100644 --- a/src/oatpp/web/protocol/http/incoming/Response.hpp +++ b/src/oatpp/web/protocol/http/incoming/Response.hpp @@ -116,9 +116,9 @@ public: /** * Decode and transfer body to toStream. * Use case example - stream huge body directly to file using relatively small buffer. - * @param toStream - &id:oatpp::data::stream::OutputStream;. + * @param toStream - pointer to &id:oatpp::data::stream::OutputStream;. */ - void streamBody(const std::shared_ptr& toStream) const; + void transferBodyToStream(oatpp::data::stream::OutputStream* toStream) const; /** * Decode and read body to &id:oatpp::String;. @@ -133,8 +133,8 @@ public: * @return - deserialized DTO object. */ template - typename Type::ObjectWrapper readBodyToDto(const std::shared_ptr& objectMapper) const { - return m_bodyDecoder->decodeToDto(m_headers, m_bodyStream, objectMapper); + typename Type::ObjectWrapper readBodyToDto(oatpp::data::mapping::ObjectMapper* objectMapper) const { + return m_bodyDecoder->decodeToDto(m_headers, m_bodyStream.get(), objectMapper); } // Async @@ -144,7 +144,7 @@ public: * @param toStream - `std::shared_ptr` to &id:oatpp::data::stream::OutputStream;. * @return - &id:oatpp::async::CoroutineStarter;. */ - oatpp::async::CoroutineStarter streamBodyAsync(const std::shared_ptr& toStream) const; + oatpp::async::CoroutineStarter transferBodyToStreamAsync(const std::shared_ptr& toStream) const; /** * Same as &l:Response::readBodyToString (); but Async. diff --git a/src/oatpp/web/protocol/http/incoming/SimpleBodyDecoder.cpp b/src/oatpp/web/protocol/http/incoming/SimpleBodyDecoder.cpp index fd77b6e7..6b9bbea5 100644 --- a/src/oatpp/web/protocol/http/incoming/SimpleBodyDecoder.cpp +++ b/src/oatpp/web/protocol/http/incoming/SimpleBodyDecoder.cpp @@ -29,9 +29,10 @@ namespace oatpp { namespace web { namespace protocol { namespace http { namespace incoming { -data::v_io_size SimpleBodyDecoder::readLine(const std::shared_ptr& fromStream, - p_char8 buffer, - data::v_io_size maxLineSize) { +data::v_io_size SimpleBodyDecoder::readLine(oatpp::data::stream::InputStream* fromStream, + p_char8 buffer, + data::v_io_size maxLineSize) +{ v_char8 a; data::v_io_size count = 0; @@ -55,7 +56,7 @@ data::v_io_size SimpleBodyDecoder::readLine(const std::shared_ptr& fromStream, +void SimpleBodyDecoder::doChunkedDecoding(oatpp::data::stream::InputStream* fromStream, oatpp::data::stream::WriteCallback* writeCallback) { auto buffer = oatpp::data::buffer::IOBuffer::createShared(); @@ -84,7 +85,7 @@ void SimpleBodyDecoder::doChunkedDecoding(const std::shared_ptr& bodyStream, + oatpp::data::stream::InputStream* bodyStream, oatpp::data::stream::WriteCallback* writeCallback) const { auto transferEncodingIt = headers.find(Header::TRANSFER_ENCODING); diff --git a/src/oatpp/web/protocol/http/incoming/SimpleBodyDecoder.hpp b/src/oatpp/web/protocol/http/incoming/SimpleBodyDecoder.hpp index 51f316d4..1b7f1177 100644 --- a/src/oatpp/web/protocol/http/incoming/SimpleBodyDecoder.hpp +++ b/src/oatpp/web/protocol/http/incoming/SimpleBodyDecoder.hpp @@ -34,25 +34,21 @@ namespace oatpp { namespace web { namespace protocol { namespace http { namespac */ class SimpleBodyDecoder : public BodyDecoder { private: - static data::v_io_size readLine(const std::shared_ptr& fromStream, - p_char8 buffer, - data::v_io_size maxLineSize); - static void doChunkedDecoding(const std::shared_ptr& from, - oatpp::data::stream::WriteCallback* writeCallback); + static data::v_io_size readLine(data::stream::InputStream* fromStream, p_char8 buffer, data::v_io_size maxLineSize); + + static void doChunkedDecoding(data::stream::InputStream* from, data::stream::WriteCallback* writeCallback); - static oatpp::async::CoroutineStarter doChunkedDecodingAsync(const std::shared_ptr& fromStream, - const std::shared_ptr& writeCallback); + static oatpp::async::CoroutineStarter doChunkedDecodingAsync(const std::shared_ptr& fromStream, + const std::shared_ptr& writeCallback); public: /** * Decode bodyStream and write decoded data to toStream. * @param headers - Headers map. &id:oatpp::web::protocol::http::Headers;. - * @param bodyStream - `std::shared_ptr` to &id:oatpp::data::stream::InputStream;. + * @param bodyStream - pointer to &id:oatpp::data::stream::InputStream;. * @param writeCallback - &id:oatpp::data::stream::WriteCallback;. */ - void decode(const Headers& headers, - const std::shared_ptr& bodyStream, - oatpp::data::stream::WriteCallback* writeCallback) const override; + void decode(const Headers& headers, data::stream::InputStream* bodyStream, data::stream::WriteCallback* writeCallback) const override; /** * Same as &l:SimpleBodyDecoder::decode (); but Async. diff --git a/src/oatpp/web/protocol/http/outgoing/Body.hpp b/src/oatpp/web/protocol/http/outgoing/Body.hpp index 827ac2b9..40a8d435 100644 --- a/src/oatpp/web/protocol/http/outgoing/Body.hpp +++ b/src/oatpp/web/protocol/http/outgoing/Body.hpp @@ -60,9 +60,9 @@ public: /** * Write body content to stream. - * @param stream - `std::shared_ptr` to &id:oatpp::data::stream::OutputStream;. + * @param stream - pointer to &id:oatpp::data::stream::OutputStream;. */ - virtual void writeToStream(const std::shared_ptr& stream) noexcept = 0; + virtual void writeToStream(OutputStream* stream) noexcept = 0; /** * Same as &l:Body::writeToStream (); but async. diff --git a/src/oatpp/web/protocol/http/outgoing/BufferBody.cpp b/src/oatpp/web/protocol/http/outgoing/BufferBody.cpp index f1cb2ab0..3d91b7f1 100644 --- a/src/oatpp/web/protocol/http/outgoing/BufferBody.cpp +++ b/src/oatpp/web/protocol/http/outgoing/BufferBody.cpp @@ -50,8 +50,8 @@ void BufferBody::declareHeaders(Headers& headers) noexcept { headers[oatpp::web::protocol::http::Header::CONTENT_LENGTH] = oatpp::utils::conversion::int32ToStr(m_buffer->getSize()); } -void BufferBody::writeToStream(const std::shared_ptr& stream) noexcept { - oatpp::data::stream::writeExactSizeData(stream.get(), m_buffer->getData(), m_buffer->getSize()); +void BufferBody::writeToStream(OutputStream* stream) noexcept { + oatpp::data::stream::writeExactSizeData(stream, m_buffer->getData(), m_buffer->getSize()); } diff --git a/src/oatpp/web/protocol/http/outgoing/BufferBody.hpp b/src/oatpp/web/protocol/http/outgoing/BufferBody.hpp index 062bcc59..69b554a5 100644 --- a/src/oatpp/web/protocol/http/outgoing/BufferBody.hpp +++ b/src/oatpp/web/protocol/http/outgoing/BufferBody.hpp @@ -60,9 +60,9 @@ public: /** * Write body data to stream. - * @param stream - `std::shared_ptr` to &id:oatpp::data::stream::OutputStream;. + * @param stream - pointer to &id:oatpp::data::stream::OutputStream;. */ - void writeToStream(const std::shared_ptr& stream) noexcept override; + void writeToStream(OutputStream* stream) noexcept override; public: diff --git a/src/oatpp/web/protocol/http/outgoing/ChunkedBufferBody.cpp b/src/oatpp/web/protocol/http/outgoing/ChunkedBufferBody.cpp index 9f981ec3..454599cf 100644 --- a/src/oatpp/web/protocol/http/outgoing/ChunkedBufferBody.cpp +++ b/src/oatpp/web/protocol/http/outgoing/ChunkedBufferBody.cpp @@ -45,7 +45,7 @@ void ChunkedBufferBody::declareHeaders(Headers& headers) noexcept { } } -void ChunkedBufferBody::writeToStream(const std::shared_ptr& stream) noexcept { +void ChunkedBufferBody::writeToStream(OutputStream* stream) noexcept { if(m_chunked) { auto chunks = m_buffer->getChunks(); auto curr = chunks->getFirstNode(); diff --git a/src/oatpp/web/protocol/http/outgoing/ChunkedBufferBody.hpp b/src/oatpp/web/protocol/http/outgoing/ChunkedBufferBody.hpp index 6e4fb84f..21d63163 100644 --- a/src/oatpp/web/protocol/http/outgoing/ChunkedBufferBody.hpp +++ b/src/oatpp/web/protocol/http/outgoing/ChunkedBufferBody.hpp @@ -73,7 +73,7 @@ public: * Write body data to stream. * @param stream - `std::shared_ptr` to &id:oatpp::data::stream::OutputStream;. */ - void writeToStream(const std::shared_ptr& stream) noexcept override; + void writeToStream(OutputStream* stream) noexcept override; public: diff --git a/src/oatpp/web/protocol/http/outgoing/Request.cpp b/src/oatpp/web/protocol/http/outgoing/Request.cpp index 2b8fb458..c1f0bc81 100644 --- a/src/oatpp/web/protocol/http/outgoing/Request.cpp +++ b/src/oatpp/web/protocol/http/outgoing/Request.cpp @@ -73,7 +73,7 @@ std::shared_ptr Request::getBody() { return m_body; } -void Request::send(const std::shared_ptr& stream){ +void Request::send(data::stream::OutputStream* stream){ if(m_body){ m_body->declareHeaders(m_headers); diff --git a/src/oatpp/web/protocol/http/outgoing/Request.hpp b/src/oatpp/web/protocol/http/outgoing/Request.hpp index 6465e4f1..0209c87d 100644 --- a/src/oatpp/web/protocol/http/outgoing/Request.hpp +++ b/src/oatpp/web/protocol/http/outgoing/Request.hpp @@ -120,7 +120,7 @@ public: * Write request to stream. * @param stream - &id:oatpp::data::stream::OutputStream;. */ - void send(const std::shared_ptr& stream); + void send(data::stream::OutputStream* stream); /** * Write request to stream in asynchronous manner. diff --git a/src/oatpp/web/protocol/http/outgoing/Response.cpp b/src/oatpp/web/protocol/http/outgoing/Response.cpp index e87794c6..756a5832 100644 --- a/src/oatpp/web/protocol/http/outgoing/Response.cpp +++ b/src/oatpp/web/protocol/http/outgoing/Response.cpp @@ -76,7 +76,7 @@ std::shared_ptr Response::getCo return m_connectionUpgradeParameters; } -void Response::send(const std::shared_ptr& stream) { +void Response::send(data::stream::OutputStream* stream) { if(m_body){ m_body->declareHeaders(m_headers); diff --git a/src/oatpp/web/protocol/http/outgoing/Response.hpp b/src/oatpp/web/protocol/http/outgoing/Response.hpp index 645b2e39..981694e9 100644 --- a/src/oatpp/web/protocol/http/outgoing/Response.hpp +++ b/src/oatpp/web/protocol/http/outgoing/Response.hpp @@ -129,9 +129,9 @@ public: /** * Write this Response to stream. - * @param stream - `std::shared_ptr` to &id:oatpp::data::stream::OutputStream;. + * @param stream - pointer to &id:oatpp::data::stream::OutputStream;. */ - void send(const std::shared_ptr& stream); + void send(data::stream::OutputStream* stream); /** * Same as &l:Response::send (); but async. diff --git a/src/oatpp/web/server/HttpConnectionHandler.cpp b/src/oatpp/web/server/HttpConnectionHandler.cpp index 7a649b13..66c95343 100644 --- a/src/oatpp/web/server/HttpConnectionHandler.cpp +++ b/src/oatpp/web/server/HttpConnectionHandler.cpp @@ -70,7 +70,7 @@ void HttpConnectionHandler::Task::run(){ if(response) { outStream->setBufferPosition(0, 0, false); - response->send(outStream); + response->send(outStream.get()); outStream->flush(); } else { return; diff --git a/test/oatpp/network/virtual_/InterfaceTest.cpp b/test/oatpp/network/virtual_/InterfaceTest.cpp index 7be8ec0b..aaf70fbf 100644 --- a/test/oatpp/network/virtual_/InterfaceTest.cpp +++ b/test/oatpp/network/virtual_/InterfaceTest.cpp @@ -61,7 +61,7 @@ namespace { v_char8 buffer[100]; oatpp::data::stream::ChunkedBuffer stream; oatpp::data::stream::DefaultWriteCallback writeCallback(&stream); - res = oatpp::data::stream::transfer(socket, &writeCallback, 2, buffer, 100); + res = oatpp::data::stream::transfer(socket.get(), &writeCallback, 2, buffer, 100); OATPP_ASSERT(res == 2); OATPP_ASSERT(stream.getSize() == res); @@ -89,7 +89,7 @@ namespace { v_char8 buffer[100]; oatpp::data::stream::ChunkedBuffer stream; oatpp::data::stream::DefaultWriteCallback writeCallback(&stream); - auto res = oatpp::data::stream::transfer(m_socket, &writeCallback, m_dataSample->getSize(), buffer, 100); + auto res = oatpp::data::stream::transfer(m_socket.get(), &writeCallback, m_dataSample->getSize(), buffer, 100); OATPP_ASSERT(res == m_dataSample->getSize()); OATPP_ASSERT(stream.getSize() == res); diff --git a/test/oatpp/web/FullAsyncTest.cpp b/test/oatpp/web/FullAsyncTest.cpp index 8d19bedc..0cf75aa9 100644 --- a/test/oatpp/web/FullAsyncTest.cpp +++ b/test/oatpp/web/FullAsyncTest.cpp @@ -152,7 +152,7 @@ void FullAsyncTest::onRun() { { // test GET with path parameter auto response = client->getWithParams("my_test_param-Async", connection); OATPP_ASSERT(response->getStatusCode() == 200); - auto dto = response->readBodyToDto(objectMapper); + auto dto = response->readBodyToDto(objectMapper.get()); OATPP_ASSERT(dto); OATPP_ASSERT(dto->testValue == "my_test_param-Async"); } @@ -160,7 +160,7 @@ void FullAsyncTest::onRun() { { // test GET with header parameter auto response = client->getWithHeaders("my_test_header-Async", connection); OATPP_ASSERT(response->getStatusCode() == 200); - auto dto = response->readBodyToDto(objectMapper); + auto dto = response->readBodyToDto(objectMapper.get()); OATPP_ASSERT(dto); OATPP_ASSERT(dto->testValue == "my_test_header-Async"); } @@ -168,7 +168,7 @@ void FullAsyncTest::onRun() { { // test POST with body auto response = client->postBody("my_test_body-Async", connection); OATPP_ASSERT(response->getStatusCode() == 200); - auto dto = response->readBodyToDto(objectMapper); + auto dto = response->readBodyToDto(objectMapper.get()); OATPP_ASSERT(dto); OATPP_ASSERT(dto->testValue == "my_test_body-Async"); } diff --git a/test/oatpp/web/FullTest.cpp b/test/oatpp/web/FullTest.cpp index 7fdc4e38..b93e1e87 100644 --- a/test/oatpp/web/FullTest.cpp +++ b/test/oatpp/web/FullTest.cpp @@ -145,7 +145,7 @@ void FullTest::onRun() { { // test GET with path parameter auto response = client->getWithParams("my_test_param", connection); OATPP_ASSERT(response->getStatusCode() == 200); - auto dto = response->readBodyToDto(objectMapper); + auto dto = response->readBodyToDto(objectMapper.get()); OATPP_ASSERT(dto); OATPP_ASSERT(dto->testValue == "my_test_param"); } @@ -153,7 +153,7 @@ void FullTest::onRun() { { // test GET with query parameters auto response = client->getWithQueries("oatpp", 1, connection); OATPP_ASSERT(response->getStatusCode() == 200); - auto dto = response->readBodyToDto(objectMapper); + auto dto = response->readBodyToDto(objectMapper.get()); OATPP_ASSERT(dto); OATPP_ASSERT(dto->testValue == "name=oatpp&age=1"); } @@ -161,7 +161,7 @@ void FullTest::onRun() { { // test GET with query parameters auto response = client->getWithQueriesMap("value1", 32, 0.32, connection); OATPP_ASSERT(response->getStatusCode() == 200); - auto dto = response->readBodyToDto(objectMapper); + auto dto = response->readBodyToDto(objectMapper.get()); OATPP_ASSERT(dto); OATPP_ASSERT(dto->testMap); OATPP_ASSERT(dto->testMap->count() == 3); @@ -173,7 +173,7 @@ void FullTest::onRun() { { // test GET with header parameter auto response = client->getWithHeaders("my_test_header", connection); OATPP_ASSERT(response->getStatusCode() == 200); - auto dto = response->readBodyToDto(objectMapper); + auto dto = response->readBodyToDto(objectMapper.get()); OATPP_ASSERT(dto); OATPP_ASSERT(dto->testValue == "my_test_header"); } @@ -181,7 +181,7 @@ void FullTest::onRun() { { // test POST with body auto response = client->postBody("my_test_body", connection); OATPP_ASSERT(response->getStatusCode() == 200); - auto dto = response->readBodyToDto(objectMapper); + auto dto = response->readBodyToDto(objectMapper.get()); OATPP_ASSERT(dto); OATPP_ASSERT(dto->testValue == "my_test_body"); } diff --git a/test/oatpp/web/mime/multipart/StatefulParserTest.cpp b/test/oatpp/web/mime/multipart/StatefulParserTest.cpp index 69b3ee91..d0e0cedd 100644 --- a/test/oatpp/web/mime/multipart/StatefulParserTest.cpp +++ b/test/oatpp/web/mime/multipart/StatefulParserTest.cpp @@ -112,7 +112,7 @@ namespace { oatpp::data::stream::ChunkedBuffer stream; oatpp::data::stream::DefaultWriteCallback writeCallback(&stream); - oatpp::data::stream::transfer(part->getInputStream(), &writeCallback, 0, buffer, bufferSize); + oatpp::data::stream::transfer(part->getInputStream().get(), &writeCallback, 0, buffer, bufferSize); oatpp::String readData = stream.toString(); diff --git a/test/oatpp/web/server/api/ApiControllerTest.cpp b/test/oatpp/web/server/api/ApiControllerTest.cpp index 180fa3e8..9fe7b0d3 100644 --- a/test/oatpp/web/server/api/ApiControllerTest.cpp +++ b/test/oatpp/web/server/api/ApiControllerTest.cpp @@ -105,10 +105,10 @@ void ApiControllerTest::onRun() { auto response = controller.root(); OATPP_ASSERT(response->getStatus().code == 200); - auto stream = oatpp::data::stream::ChunkedBuffer::createShared(); - response->send(stream); + oatpp::data::stream::ChunkedBuffer stream; + response->send(&stream); - OATPP_LOGD(TAG, "response:\n---\n%s\n---\n", stream->toString()->c_str()); + OATPP_LOGD(TAG, "response:\n---\n%s\n---\n", stream.toString()->c_str()); } @@ -132,10 +132,10 @@ void ApiControllerTest::onRun() { auto response = controller.pathParams("p1", "p2"); OATPP_ASSERT(response->getStatus().code == 200); - auto stream = oatpp::data::stream::ChunkedBuffer::createShared(); - response->send(stream); + oatpp::data::stream::ChunkedBuffer stream; + response->send(&stream); - OATPP_LOGD(TAG, "response:\n---\n%s\n---\n", stream->toString()->c_str()); + OATPP_LOGD(TAG, "response:\n---\n%s\n---\n", stream.toString()->c_str()); } @@ -153,10 +153,10 @@ void ApiControllerTest::onRun() { auto response = controller.queryParams("p1", "p2"); OATPP_ASSERT(response->getStatus().code == 200); - auto stream = oatpp::data::stream::ChunkedBuffer::createShared(); - response->send(stream); + oatpp::data::stream::ChunkedBuffer stream; + response->send(&stream); - OATPP_LOGD(TAG, "response:\n---\n%s\n---\n", stream->toString()->c_str()); + OATPP_LOGD(TAG, "response:\n---\n%s\n---\n", stream.toString()->c_str()); }