本文整理汇总了C++中HttpHeader::httpCode方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpHeader::httpCode方法的具体用法?C++ HttpHeader::httpCode怎么用?C++ HttpHeader::httpCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpHeader
的用法示例。
在下文中一共展示了HttpHeader::httpCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
//.........这里部分代码省略.........
示例2: convertHttpCodeToUpdaterCode
//.........这里部分代码省略.........
if((receiveResponseAndDataResult == CORE_REMOTE_HOST_CLOSED_CONNECTION)
&& previousResponseReceived && authorizationTypeSwitched && !requestHasAlreadyBeenRepeated)
{
TRACE_MESSAGE("Repeating the same request (without authorization switch), because server was reachable, but unexpectedly closed connection");
requestHasAlreadyBeenRepeated = true;
continue;
}
return receiveResponseAndDataResult;
}
previousResponseReceived = true;
requestHasAlreadyBeenRepeated = false;
m_authorizationDriver.authorized(
// authorization information is reset in case connection is to be closed
!needCloseConnection
// authorization success in case file received or successful redirect
&& (httpHeader.isFile()
|| httpHeader.redirectRequired()
|| httpHeader.fileNotFound()));
if(httpHeader.isFile())
{
// in case proxy server by some ocassion desided to close
// connection after successful file receive event
if(needCloseConnection)
m_authorizationDriver.resetNtlmState();
return CORE_NO_ERROR;
}
authorizationTarget = httpHeader.authorizationTarget();
authorizationWasNeededOnProxy = !proxyAuthorizationHeader.empty();
lastHttpCode = httpHeader.httpCode();
// authorization error
if(httpHeader.authorizationNeeded())
{
authorizationWasNeededOnProxy = (authorizationTarget == DownloadProgress::proxyServer);
if(!switchAuthorization(fileName, relativeUrlPath, httpHeader.authorizationTarget(), proxyAddress,
authorizationTypeSwitched, ntlmAuthorizationTriedAlready))
{
return httpHeader.convertHttpCodeToUpdaterCode();
}
}
// redirect needed
else if(httpHeader.redirectRequired())
{
// protection against infinite loop (according to RFC 2616)
if(++infiniteRedirectLoop > 2)
{
TRACE_MESSAGE2("Infinite redirection loop detected for location '%S'",
httpHeader.m_location.toWideChar());
return CORE_NO_SOURCE_FILE;
}
if(httpHeader.m_location.isAbsoluteUri())
serverAddress.parse(httpHeader.m_location);
else
{
serverAddress.parse(toProtocolPrefix(serverAddress.m_protocol) + serverAddress.m_hostname
+ serverAddress.m_path + httpHeader.m_location);
serverAddress.m_path.correctPathDelimiters();
}
fileName = serverAddress.m_fileName;