| 673 | } |
| 674 | |
| 675 | static int on_headers_complete(http_parser* p) |
| 676 | { |
| 677 | StreamingResponseDecoder* decoder = (StreamingResponseDecoder*) p->data; |
| 678 | |
| 679 | // This asserts not only that `on_message_begin` has been previously called, |
| 680 | // but also that `on_headers_complete` is not called more than once. |
| 681 | CHECK_NOTNULL(decoder->response); |
| 682 | |
| 683 | // Add final header. |
| 684 | decoder->response->headers[decoder->field] = decoder->value; |
| 685 | decoder->field.clear(); |
| 686 | decoder->value.clear(); |
| 687 | |
| 688 | if (http::isValidStatus(decoder->parser.status_code)) { |
| 689 | decoder->response->code = decoder->parser.status_code; |
| 690 | |
| 691 | decoder->response->status = |
| 692 | http::Status::string(decoder->parser.status_code); |
| 693 | } else { |
| 694 | decoder->failure = true; |
| 695 | return http_parsing::FAILURE; |
| 696 | } |
| 697 | |
| 698 | // We cannot provide streaming gzip decompression! |
| 699 | Option<std::string> encoding = |
| 700 | decoder->response->headers.get("Content-Encoding"); |
| 701 | if (encoding.isSome() && encoding.get() == "gzip") { |
| 702 | decoder->failure = true; |
| 703 | return http_parsing::FAILURE; |
| 704 | } |
| 705 | |
| 706 | CHECK_NONE(decoder->writer); |
| 707 | |
| 708 | http::Pipe pipe; |
| 709 | decoder->writer = pipe.writer(); |
| 710 | decoder->response->reader = pipe.reader(); |
| 711 | |
| 712 | // Send the response to the caller, but keep a Pipe::Writer for |
| 713 | // streaming the body content into the response. |
| 714 | decoder->responses.push_back(decoder->response); |
| 715 | |
| 716 | // TODO(alexr): We currently do not support trailers, i.e., extra headers |
| 717 | // after `on_headers_complete` has been called. When we add trailer support, |
| 718 | // we need a thread-safe way to surface them up in the response or some |
| 719 | // auxiliary data structure. |
| 720 | decoder->response = nullptr; |
| 721 | |
| 722 | return http_parsing::SUCCESS; |
| 723 | } |
| 724 | |
| 725 | static int on_body(http_parser* p, const char* data, size_t length) |
| 726 | { |
nothing calls this directly
no test coverage detected