当前位置: 首页>>代码示例>>C++>>正文


C++ HttpHeader::load方法代码示例

本文整理汇总了C++中HttpHeader::load方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpHeader::load方法的具体用法?C++ HttpHeader::load怎么用?C++ HttpHeader::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpHeader的用法示例。


在下文中一共展示了HttpHeader::load方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

KLUPD::CoreError KLUPD::HttpProtocol::receiveResponseAndData(HttpHeader &httpHeader)
{
    bool httpHeaderFullyReceived = false;

    const char *entity = 0;
    size_t total_entity_bytes = 0;

    const size_t httpBufferSize = 65536;
    char httpBuffer[httpBufferSize + 1];
    memset(httpBuffer, 0, httpBufferSize + 1);
    size_t currentOffsetInHttpBuffer = 0;

    while(true)
    {
        CoreError receiveResult = CORE_NO_ERROR;
        const int bytesReceived = m_socket.recv(httpBuffer + currentOffsetInHttpBuffer,
            httpBufferSize - currentOffsetInHttpBuffer, receiveResult);
        currentOffsetInHttpBuffer += bytesReceived;

        // according to RFC 2616, 4.4 point 5: connection close may indicate
         // file transfer completion if Range or Content-Length is not specified
        if(httpHeaderFullyReceived
            && (receiveResult == CORE_REMOTE_HOST_CLOSED_CONNECTION)
            && (httpHeader.m_contentLength == -1))
        {
            TRACE_MESSAGE2("HTTP connection closed by server, no Content-Length field, consider file is obtained, size %d bytes", currentOffsetInHttpBuffer);
            return CORE_NO_ERROR;
        }
        if(receiveResult != CORE_NO_ERROR)
            return receiveResult;

        // size of entity part that is currently in buffer
        size_t entityBytes = 0;
        if(httpHeaderFullyReceived)
        {
            // http header was obtained on previous iteration
            entityBytes = currentOffsetInHttpBuffer;
            entity = httpBuffer;
        }
        else
        {
            // HTTP header has not been obtained yet, check if it is in httpBuffer
            const char *const headerEndMarker = "\r\n\r\n";
            char *const headerLastPosition = strstr(httpBuffer, headerEndMarker);

            if(!headerLastPosition)
            {
                // no end-of-header marker found
                if(httpBufferSize < currentOffsetInHttpBuffer)
                {
                    TRACE_MESSAGE3("Error: response HTTP header can not fit into %d-bytes buffer (already received %d bytes)",
                        httpBufferSize, currentOffsetInHttpBuffer);
                    return CORE_DOWNLOAD_ERROR;
                }

                // continue reading from socket
                continue;
            }

            httpHeaderFullyReceived = true;

            // pass to applicaiton data included into HTTP header
            fullHttpHeaderReceived(std::string(httpBuffer, headerLastPosition + strlen(headerEndMarker)));

            *headerLastPosition = 0;
            TRACE_MESSAGE2("HTTP response received:\n%s", HTTPRequestBuilder::toString(httpBuffer).c_str());

            // Parse HTTP header, data loaded into httpHeader structure
            if(!httpHeader.load(httpBuffer, m_authorizationDriver))
            {
                TRACE_MESSAGE("Failed to parse HTTP response header");
                return CORE_DOWNLOAD_ERROR;
            }

            // it is expected 206 code in case regetting is used
            if(m_regettingPosition && (httpHeader.httpCode() == 200))
            {
                TRACE_MESSAGE("It is expected 206 code in case regetting is used, but 200 code is received");
                return CORE_DOWNLOAD_ERROR;
            }

            // data from socket after the HTTP header
            entityBytes = (httpBuffer + currentOffsetInHttpBuffer)  // pointer to the end of received bytes
                - (headerLastPosition + strlen(headerEndMarker));   // pointer to the data (begin of the file)
            entity = entityBytes ? headerLastPosition + strlen(headerEndMarker) : 0;
        }

        total_entity_bytes += entityBytes;

        if(httpHeader.isFile()
            // only header has been received, but data is not received yet
            && entityBytes)
        {
            const CoreError saveDataToFileResult = dataReceived(reinterpret_cast<const unsigned char *>(entity), entityBytes);
            if(!isSuccess(saveDataToFileResult))
            {
                TRACE_MESSAGE2("Failed to write data obtained from HTTP Server, result %S",
                    toString(saveDataToFileResult).toWideChar());
                return saveDataToFileResult;
            }
//.........这里部分代码省略.........
开发者ID:hackshields,项目名称:antivirus,代码行数:101,代码来源:NetFacHTTP.cpp


注:本文中的HttpHeader::load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。