NetServices: add support for receiving incoming chunked messages
Change-Id: I1bfe22a7959c7a5fc7dc644e4e3941965edafb65
This commit is contained in:
@@ -68,7 +68,8 @@ public:
|
||||
|
||||
ssize_t ReadFrom(BDataIO* source);
|
||||
void WriteExactlyTo(BDataIO* target);
|
||||
void WriteTo(HttpTransferFunction func);
|
||||
void WriteTo(HttpTransferFunction func,
|
||||
std::optional<size_t> maxSize = std::nullopt);
|
||||
std::optional<BString> GetNextLine();
|
||||
|
||||
size_t RemainingBytes() noexcept;
|
||||
@@ -82,6 +83,15 @@ private:
|
||||
};
|
||||
|
||||
|
||||
enum class HttpBodyInputStreamState {
|
||||
ChunkSize,
|
||||
ChunkEnd,
|
||||
Chunk,
|
||||
Trailers,
|
||||
Done
|
||||
};
|
||||
|
||||
|
||||
class HttpParser {
|
||||
public:
|
||||
HttpParser() {};
|
||||
@@ -100,6 +110,8 @@ public:
|
||||
bool Complete() const noexcept;
|
||||
|
||||
private:
|
||||
size_t _ParseBodyRaw(HttpBuffer& buffer, HttpTransferFunction writeToBody);
|
||||
size_t _ParseBodyChunked(HttpBuffer& buffer, HttpTransferFunction writeToBody);
|
||||
size_t _ReadChunk(HttpBuffer& buffer, HttpTransferFunction writeToBody,
|
||||
size_t maxSize, bool flush);
|
||||
bool _IsChunked() const noexcept;
|
||||
@@ -108,8 +120,9 @@ private:
|
||||
off_t fHeaderBytes = 0;
|
||||
|
||||
// Support for chunked transfers
|
||||
std::optional<off_t> fRemainingChunkSize;
|
||||
bool fChunkedTransferComplete = false;
|
||||
HttpBodyInputStreamState fBodyState = HttpBodyInputStreamState::ChunkSize;
|
||||
off_t fRemainingChunkSize = 0;
|
||||
bool fLastChunk = false;
|
||||
|
||||
// Receive stats
|
||||
std::optional<off_t> fBodyBytesTotal = 0;
|
||||
|
||||
Reference in New Issue
Block a user