mirror of
https://github.com/sogou/workflow.git
synced 2026-02-08 01:33:17 +08:00
Enable HttpMessage getting output body.
This commit is contained in:
@@ -67,6 +67,48 @@ bool HttpMessage::append_output_body_nocopy(const void *buf, size_t size)
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t HttpMessage::get_output_body_blocks(const void *buf[], size_t size[],
|
||||
size_t max) const
|
||||
{
|
||||
struct HttpMessageBlock *block;
|
||||
struct list_head *pos;
|
||||
size_t n = 0;
|
||||
|
||||
list_for_each(pos, &this->output_body)
|
||||
{
|
||||
if (n == max)
|
||||
break;
|
||||
|
||||
block = list_entry(pos, struct HttpMessageBlock, list);
|
||||
buf[n] = block->ptr;
|
||||
size[n] = block->size;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
bool HttpMessage::get_output_body_merged(void *buf, size_t *size) const
|
||||
{
|
||||
struct HttpMessageBlock *block;
|
||||
struct list_head *pos;
|
||||
|
||||
if (*size < this->output_body_size)
|
||||
{
|
||||
errno = ENOSPC;
|
||||
return false;
|
||||
}
|
||||
|
||||
list_for_each(pos, &this->output_body)
|
||||
{
|
||||
block = list_entry(pos, struct HttpMessageBlock, list);
|
||||
memcpy(buf, block->ptr, block->size);
|
||||
buf = (char *)buf + block->size;
|
||||
}
|
||||
|
||||
*size = this->output_body_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
void HttpMessage::clear_output_body()
|
||||
{
|
||||
struct HttpMessageBlock *block;
|
||||
|
||||
@@ -115,13 +115,18 @@ public:
|
||||
return this->append_output_body_nocopy(buf, strlen(buf));
|
||||
}
|
||||
|
||||
void clear_output_body();
|
||||
|
||||
size_t get_output_body_size() const
|
||||
{
|
||||
return this->output_body_size;
|
||||
}
|
||||
|
||||
size_t get_output_body_blocks(const void *buf[], size_t size[],
|
||||
size_t max) const;
|
||||
|
||||
bool get_output_body_merged(void *buf, size_t *size) const;
|
||||
|
||||
void clear_output_body();
|
||||
|
||||
/* std::string interfaces */
|
||||
public:
|
||||
bool get_http_version(std::string& version) const
|
||||
@@ -166,6 +171,13 @@ public:
|
||||
return this->append_output_body_nocopy(buf.c_str(), buf.size());
|
||||
}
|
||||
|
||||
bool get_output_body_merged(std::string& body) const
|
||||
{
|
||||
size_t size = this->output_body_size;
|
||||
body.resize(size);
|
||||
return this->get_output_body_merged((void *)body.data(), &size);
|
||||
}
|
||||
|
||||
/* for http task implementations. */
|
||||
public:
|
||||
bool is_header_complete() const
|
||||
|
||||
Reference in New Issue
Block a user