File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed
Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,13 @@ namespace Aws
6060 */
6161 bool SetBody (const std::shared_ptr<Aws::Crt::Io::InputStream> &body) noexcept ;
6262
63+ /* *
64+ * Sets an async input stream as the message body
65+ * @param body the async input stream representing the message body
66+ * @return future<bool> indicating success/failure
67+ */
68+ std::future<bool > SetBody (const std::shared_ptr<Aws::Crt::Io::AsyncInputStream> &body) noexcept ;
69+
6370 /* *
6471 * Gets the number of headers contained in this request
6572 * @return the number of headers contained in this request
@@ -101,6 +108,7 @@ namespace Aws
101108 Allocator *m_allocator;
102109 struct aws_http_message *m_message;
103110 std::shared_ptr<Aws::Crt::Io::InputStream> m_bodyStream;
111+ std::shared_ptr<Aws::Crt::Io::AsyncInputStream> m_asyncBodyStream;
104112 };
105113
106114 /* *
Original file line number Diff line number Diff line change 99#include < aws/crt/Types.h>
1010#include < aws/io/stream.h>
1111
12+ #include < future>
13+
1214namespace Aws
1315{
1416 namespace Crt
@@ -192,6 +194,33 @@ namespace Aws
192194 private:
193195 std::shared_ptr<Aws::Crt::Io::IStream> m_stream;
194196 };
197+
198+ /* *
199+ * Interface for asynchronous input streams.
200+ * Used for async HTTP request bodies.
201+ */
202+ class AWS_CRT_CPP_API AsyncInputStream
203+ {
204+ public:
205+ virtual ~AsyncInputStream () = default ;
206+
207+ AsyncInputStream (const AsyncInputStream &) = delete ;
208+ AsyncInputStream &operator =(const AsyncInputStream &) = delete ;
209+ AsyncInputStream (AsyncInputStream &&) = delete ;
210+ AsyncInputStream &operator =(AsyncInputStream &&) = delete ;
211+
212+ virtual bool IsValid () const noexcept = 0;
213+
214+ protected:
215+ AsyncInputStream () = default ;
216+
217+ /* *
218+ * Asynchronously read into buffer.
219+ * @return future<bool> - true on success (including EOF/no data available), false on error
220+ */
221+ virtual std::future<bool > ReadImpl (ByteBuf &buffer) noexcept = 0;
222+ };
223+
195224 } // namespace Io
196225 } // namespace Crt
197226} // namespace Aws
Original file line number Diff line number Diff line change @@ -57,12 +57,24 @@ namespace Aws
5757 bool HttpMessage::SetBody (const std::shared_ptr<Aws::Crt::Io::InputStream> &body) noexcept
5858 {
5959 m_bodyStream = body;
60+ m_asyncBodyStream = nullptr ;
6061 aws_http_message_set_body_stream (
6162 m_message, m_bodyStream && *m_bodyStream ? m_bodyStream->GetUnderlyingStream () : nullptr );
6263
6364 return true ;
6465 }
6566
67+ std::future<bool > HttpMessage::SetBody (const std::shared_ptr<Aws::Crt::Io::AsyncInputStream> &body) noexcept
68+ {
69+ m_asyncBodyStream = body;
70+ m_bodyStream = nullptr ;
71+ aws_http_message_set_body_stream (m_message, nullptr );
72+
73+ std::promise<bool > promise;
74+ promise.set_value (body == nullptr || body->IsValid ());
75+ return promise.get_future ();
76+ }
77+
6678 size_t HttpMessage::GetHeaderCount () const noexcept
6779 {
6880 return aws_http_message_get_header_count (m_message);
You can’t perform that action at this time.
0 commit comments