本文整理汇总了C++中HttpHeaders::setStatusLine方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpHeaders::setStatusLine方法的具体用法?C++ HttpHeaders::setStatusLine怎么用?C++ HttpHeaders::setStatusLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders::setStatusLine方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: headers_callback
/*
* This function serves as a callback for response headers read by libcurl
*
* The libcurl documentation at
* http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTHEADERFUNCTION
* says that the callback is called once for each header and only complete
* header line are passed. So we do not need to handle multi-line headers
* ourselves.
*
* Please see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html
* The first response header returned will always be "Status-line",
* Also see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
*/
static size_t headers_callback(void *buffer, size_t size, size_t nmemb, void *userp) {
char *buf = reinterpret_cast<char*>(buffer);
HttpHeaders *pHeaders = reinterpret_cast<HttpHeaders*>(userp);
size_t result = 0u;
if (pHeaders != NULL) {
/*
* Note: std::string is capable of storing binary stream data and can
* store "\0" as normal character (witout terminating string).
*
* - Until C++11, it is not guaranteed to be contiguously stored though.
* - Use caution when using .c_str(), if string contains "\0", use .data() instead
*
* Since binary data can be stored in std::string, unicode characters
* can be present But beware of using .length() or .size(), since they
* will return number of bytes storage (i.e., char) needed to store the
* string, and not actual number of characters.
*/
std::string s = "";
s.append(buf, size * nmemb);
result = size * nmemb;
// There can be 3 different cases, each should be handled differently:
// Case 1: Check for last header line: CRLF,
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html
if (s.size() == 2u && s[0] == '\r' && s[1] == '\n')
return result;
// Case 2: If it is the first header, the it must be a status Line.
// For all other cases, statusLine must be populated with some non-zero length string
if (pHeaders->getStatusLine().length() == 0u) {
pHeaders->setStatusLine(HttpHelperUtils::stripWhitespaces(s));
return result;
}
// Case 3: This is a usual message header, of form
// message-header = field-name ":" [ field-value ]
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
pHeaders->appendHeaderString(s);
}
return result;
}