| 534 | } |
| 535 | |
| 536 | std::string HTTPRequest::ReadBody() |
| 537 | { |
| 538 | struct evbuffer* buf = evhttp_request_get_input_buffer(req); |
| 539 | if (!buf) |
| 540 | return ""; |
| 541 | size_t size = evbuffer_get_length(buf); |
| 542 | /** Trivial implementation: if this is ever a performance bottleneck, |
| 543 | * internal copying can be avoided in multi-segment buffers by using |
| 544 | * evbuffer_peek and an awkward loop. Though in that case, it'd be even |
| 545 | * better to not copy into an intermediate string but use a stream |
| 546 | * abstraction to consume the evbuffer on the fly in the parsing algorithm. |
| 547 | */ |
| 548 | const char* data = (const char*)evbuffer_pullup(buf, size); |
| 549 | if (!data) // returns nullptr in case of empty buffer |
| 550 | return ""; |
| 551 | std::string rv(data, size); |
| 552 | evbuffer_drain(buf, size); |
| 553 | return rv; |
| 554 | } |
| 555 | |
| 556 | void HTTPRequest::WriteHeader(const std::string& hdr, const std::string& value) |
| 557 | { |
no outgoing calls