| 491 | } |
| 492 | |
| 493 | std::string HTTPRequest::ReadBody() |
| 494 | { |
| 495 | struct evbuffer* buf = evhttp_request_get_input_buffer(req); |
| 496 | if (!buf) |
| 497 | return ""; |
| 498 | size_t size = evbuffer_get_length(buf); |
| 499 | /** Trivial implementation: if this is ever a performance bottleneck, |
| 500 | * internal copying can be avoided in multi-segment buffers by using |
| 501 | * evbuffer_peek and an awkward loop. Though in that case, it'd be even |
| 502 | * better to not copy into an intermediate string but use a stream |
| 503 | * abstraction to consume the evbuffer on the fly in the parsing algorithm. |
| 504 | */ |
| 505 | const char* data = (const char*)evbuffer_pullup(buf, size); |
| 506 | if (!data) // returns NULL in case of empty buffer |
| 507 | return ""; |
| 508 | std::string rv(data, size); |
| 509 | evbuffer_drain(buf, size); |
| 510 | return rv; |
| 511 | } |
| 512 | |
| 513 | void HTTPRequest::WriteHeader(const std::string& hdr, const std::string& value) |
| 514 | { |
no outgoing calls
no test coverage detected