| 770 | } |
| 771 | |
| 772 | void AsyncHttpClient::onData(const uint8_t* data, size_t len) |
| 773 | { |
| 774 | size_t index = 0U; |
| 775 | const void* vData = data; |
| 776 | const char* asciiData = static_cast<const char*>(vData); |
| 777 | bool isError = false; |
| 778 | |
| 779 | /* RFC2616 - Response = Status-Line |
| 780 | * *(( general-header |
| 781 | * | response-header |
| 782 | * | entity-header ) CRLF) |
| 783 | * CRLF |
| 784 | * [ message-body ] |
| 785 | */ |
| 786 | |
| 787 | while ((len > index) && (false == isError)) |
| 788 | { |
| 789 | switch (m_rspPart) |
| 790 | { |
| 791 | case RESPONSE_PART_STATUS_LINE: |
| 792 | if (true == parseRspStatusLine(asciiData, len, index)) |
| 793 | { |
| 794 | LOG_DEBUG("Rsp. HTTP-Version: %s", m_rsp.getHttpVersion().c_str()); |
| 795 | LOG_DEBUG("Rsp. Status-Code: %u", m_rsp.getStatusCode()); |
| 796 | LOG_DEBUG("Rsp. Reason-Phrase: %s", m_rsp.getReasonPhrase().c_str()); |
| 797 | |
| 798 | m_rspPart = RESPONSE_PART_HEADER; |
| 799 | } |
| 800 | break; |
| 801 | |
| 802 | case RESPONSE_PART_HEADER: |
| 803 | if (true == parseRspHeader(asciiData, len, index)) |
| 804 | { |
| 805 | /* Examine response header. |
| 806 | * This is important to determine the number of following |
| 807 | * payload data and to know when the last data is |
| 808 | * received. |
| 809 | */ |
| 810 | if (false == handleRspHeader()) |
| 811 | { |
| 812 | /* Not nice, but anyway. */ |
| 813 | LOG_ERROR("Header error."); |
| 814 | m_tcpClient.close(); |
| 815 | isError = true; |
| 816 | } |
| 817 | else if (TRANSFER_CODING_IDENTITY == m_transferCoding) |
| 818 | { |
| 819 | /* "Content-Length" may be missing. */ |
| 820 | if (0U == m_contentLength) |
| 821 | { |
| 822 | m_contentLength = len - index; |
| 823 | } |
| 824 | } |
| 825 | m_rspPart = RESPONSE_PART_BODY; |
| 826 | } |
| 827 | break; |
| 828 | |
| 829 | case RESPONSE_PART_BODY: |
no test coverage detected