| 552 | } |
| 553 | |
| 554 | std::string HTTPRequest::ReadBody() |
| 555 | { |
| 556 | struct evbuffer* buf = evhttp_request_get_input_buffer(req); |
| 557 | if (!buf) |
| 558 | return ""; |
| 559 | size_t size = evbuffer_get_length(buf); |
| 560 | /** Trivial implementation: if this is ever a performance bottleneck, |
| 561 | * internal copying can be avoided in multi-segment buffers by using |
| 562 | * evbuffer_peek and an awkward loop. Though in that case, it'd be even |
| 563 | * better to not copy into an intermediate string but use a stream |
| 564 | * abstraction to consume the evbuffer on the fly in the parsing algorithm. |
| 565 | */ |
| 566 | const char* data = (const char*)evbuffer_pullup(buf, size); |
| 567 | if (!data) // returns nullptr in case of empty buffer |
| 568 | return ""; |
| 569 | std::string rv(data, size); |
| 570 | evbuffer_drain(buf, size); |
| 571 | return rv; |
| 572 | } |
| 573 | |
| 574 | void HTTPRequest::WriteHeader(const std::string& hdr, const std::string& value) |
| 575 | { |
no outgoing calls
no test coverage detected