| 665 | } |
| 666 | |
| 667 | void HTTPRequest::Chunk(const std::string& chunk) { |
| 668 | assert(!replySent); |
| 669 | |
| 670 | int status = 200; |
| 671 | |
| 672 | if (!startedChunkTransfer) { |
| 673 | HTTPEvent* ev = new HTTPEvent(eventBase, true, NULL, |
| 674 | std::bind(evhttp_send_reply_start, req, status, |
| 675 | (const char*) NULL)); |
| 676 | ev->trigger(0); |
| 677 | |
| 678 | startDetectClientClose(); |
| 679 | startedChunkTransfer = true; |
| 680 | } |
| 681 | |
| 682 | |
| 683 | if (chunk.size() > 0) { |
| 684 | auto databuf = evbuffer_new(); // HTTPEvent will free this buffer |
| 685 | evbuffer_add(databuf, chunk.data(), chunk.size()); |
| 686 | HTTPEvent* ev = new HTTPEvent(eventBase, true, databuf, |
| 687 | std::bind(evhttp_send_reply_chunk, req, databuf)); |
| 688 | ev->trigger(0); |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | /** Closure sent to main thread to request a reply to be sent to |
| 693 | * a HTTP request. |