rework client using async api
This commit is contained in:
+31
-10
@@ -94,17 +94,35 @@ private:
|
||||
class Parser {
|
||||
public:
|
||||
Parser();
|
||||
virtual ~Parser() = default;
|
||||
|
||||
Parser(const Parser&) = delete;
|
||||
Parser& operator=(const Parser&) = delete;
|
||||
|
||||
virtual ~Parser() = default;
|
||||
|
||||
void Init(Message* message);
|
||||
|
||||
bool finished() const {
|
||||
return finished_;
|
||||
}
|
||||
|
||||
// If the headers part has been parsed or not.
|
||||
bool header_ended() const {
|
||||
return header_ended_;
|
||||
}
|
||||
|
||||
// Get the length of the headers part.
|
||||
// Available after the headers have been parsed (see header_ended()).
|
||||
std::size_t header_length() const {
|
||||
return header_length_;
|
||||
}
|
||||
|
||||
// The content length parsed from `Content-Length` header.
|
||||
// kInvalidLength if the content is chunked.
|
||||
std::size_t content_length() const {
|
||||
return content_length_;
|
||||
}
|
||||
|
||||
bool Parse(const char* data, std::size_t length);
|
||||
|
||||
protected:
|
||||
@@ -144,25 +162,28 @@ protected:
|
||||
bool Finish();
|
||||
|
||||
protected:
|
||||
Message* message_;
|
||||
Message* message_ = nullptr;
|
||||
|
||||
std::unique_ptr<BodyHandler> body_handler_;
|
||||
|
||||
// Data streaming or not.
|
||||
bool stream_;
|
||||
bool stream_ = false;
|
||||
|
||||
// Data waiting to be parsed.
|
||||
std::string pending_data_;
|
||||
|
||||
// The length of the headers part.
|
||||
std::size_t header_length_ = 0;
|
||||
|
||||
// Temporary data and helper flags for parsing.
|
||||
std::size_t content_length_;
|
||||
std::size_t content_length_ = kInvalidLength;
|
||||
ContentType content_type_;
|
||||
bool start_line_parsed_;
|
||||
bool content_length_parsed_;
|
||||
bool header_ended_;
|
||||
bool chunked_;
|
||||
std::size_t chunk_size_;
|
||||
bool finished_;
|
||||
bool start_line_parsed_ = false;
|
||||
bool content_length_parsed_ = false;
|
||||
bool header_ended_ = false;
|
||||
bool chunked_ = false;
|
||||
std::size_t chunk_size_ = kInvalidLength;
|
||||
bool finished_ = false;
|
||||
};
|
||||
|
||||
} // namespace webcc
|
||||
|
||||
Reference in New Issue
Block a user