本文整理汇总了C++中HttpHeaders::setHeader方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpHeaders::setHeader方法的具体用法?C++ HttpHeaders::setHeader怎么用?C++ HttpHeaders::setHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders::setHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkNewVersion
void checkNewVersion(const Uuid& uuid, const std::string& extraParams, CheckUpdateDelegate* delegate)
{
using namespace base;
using namespace net;
std::string url = UPDATE_URL;
if (!uuid.empty()) {
url += "&uuid=";
url += uuid;
}
if (!extraParams.empty()) {
url += "&";
url += extraParams;
}
HttpRequest request(url);
HttpHeaders headers;
headers.setHeader("User-Agent", getUserAgent());
request.setHeaders(headers);
std::stringstream body;
HttpResponse response(&body);
request.send(response);
CheckUpdateResponse data(body.str());
delegate->onResponse(data);
}
示例2: checkNewVersion
void checkNewVersion(const Uuid& uuid, const std::string& extraParams, CheckUpdateDelegate* delegate)
{
using namespace base;
using namespace net;
#ifndef UPDATE_URL
#define UPDATE_URL ""
#endif
#pragma message("warning: Define UPDATE_URL macro")
std::string url = UPDATE_URL;
if (!uuid.empty()) {
url += "&uuid=";
url += uuid;
}
if (!extraParams.empty()) {
url += "&";
url += extraParams;
}
HttpRequest request(url);
HttpHeaders headers;
headers.setHeader("User-Agent", getUserAgent());
request.setHeaders(headers);
std::stringstream body;
HttpResponse response(&body);
request.send(response);
TRACE("Checking updates: %s (User-Agent: %s)\n", url.c_str(), getUserAgent().c_str());
TRACE("Response:\n--\n%s--\n", body.str().c_str());
CheckUpdateResponse data(body.str());
delegate->onResponse(data);
}
示例3: getDocument
Response* FakeConnection::getDocument(const std::string& uri) {
TIMED_FUNC(FakeConnection_getDocument);
LOG(DEBUG) << " Entering FakeConnection::getDocument";
LOG(DEBUG) << " Fetching document with URI: " << uri;
std::map<std::string,IDocumentContent*>::iterator it;
it = mImpl->documents.find(uri);
std::string ct("");
std::string mime("");
if (mImpl->documents.end() != it) {
LOG(DEBUG) << " Found document with URI: " << uri;
IDocumentContent* docPtr = it->second;
ct = docPtr->getContent();
mime = docPtr->getMimeType();
}
//IDocumentContent& value = mImpl->documents[uri.c_str()];
//LOG(DEBUG) << " pointer value: " << value;
Response* response = new Response;
LOG(DEBUG) << " Setting response code";
LOG(DEBUG) << " Setting response content ptr";
//std::unique_ptr<std::string> content(new std::string(ct));
//response->setContent(std::move(content));
response->setContent(new std::string(ct));
LOG(DEBUG) << " Setting response headers";
if (0 == ct.compare("")) {
// not found
response->setResponseCode(ResponseCode::NOT_FOUND);
response->setResponseType(ResponseType::UNKNOWN_TYPE);
} else {
// found
HttpHeaders headers;
headers.setHeader("Content-type",mime);
response->setResponseHeaders(headers);
response->setResponseCode(ResponseCode::OK);
if (0 == mime.compare("application/json")) {
response->setResponseType(ResponseType::JSON);
} else if (0 == mime.compare("application/xml") ) {
response->setResponseType(ResponseType::XML);
} else if (0 == mime.compare("text/plain")) {
response->setResponseType(ResponseType::TEXT);
} else {
response->setResponseType(ResponseType::BINARY);
}
}
LOG(DEBUG) << " returning response ";
return response;
}
示例4: search
Response* FakeConnection::search(const SearchDescription& desc) {
TIMED_FUNC(FakeConnection_search);
LOG(DEBUG) << " Entering FakeConnection::search";
Response* response = new Response;
response->setResponseCode(ResponseCode::OK);
HttpHeaders headers;
headers.setHeader("Content-type","application/json");
response->setResponseHeaders(headers);
std::ostringstream cos;
cos <<
"{\"response\": {" <<
"\"start\": 1, \"page-length\": ";
// return 10 or documents.length, whichever is smaller
if (mImpl->documents.size() < 10) {
cos << mImpl->documents.size();
} else {
cos << 10;
}
cos << ", \"results\": [";
// loop over documents in map
std::map<std::string,IDocumentContent*>::iterator it;
int count = 0;
for (it = mImpl->documents.begin();it != mImpl->documents.end() && count < 10;++it) {
++count; // iterate first as MarkLogic responses are 1 indexed, not 0 indexed
if (count > 1) {
cos << ",";
}
cos << "{\"index\": " << count << " , \"uri\": \"" << (it->first)
<< "\", \"score\": \"43648\" \"confidence\":\"0.418356\" \"fitness\":\"0.50947\"}";
}
cos << "] } }";
//std::unique_ptr<std::string> cPtr(new std::string(cos.str()));
//response->setContent(std::move(cPtr));
response->setContent(new std::string(cos.str()));
response->setResponseType(ResponseType::JSON);
return response;
}