本文整理汇总了C++中http::Response类的典型用法代码示例。如果您正苦于以下问题:C++ Response类的具体用法?C++ Response怎么用?C++ Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Response类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: handleRequest
void EtagStoreResource::handleRequest(const Http::Request& request,
Http::Response& response) {
handle_etag(request, response);
response.setMimeType("image/gif");
response.addHeader("Content-Length", TO_S(EMPTY_GIF_SIZE));
response.out().write(EMPTY_GIF, EMPTY_GIF_SIZE);
}
开发者ID:starius,项目名称:wt-classes,代码行数:7,代码来源:EtagStore.cpp
示例2: responseTree
/*
* Throws XMLTree::PraseException and other
* std::exception's from string methods
*/
std::vector<std::string>
BaseService::parseGenericResponse(const Http::Response& response,
const char *expectedId) const
{
XMLTree responseTree(false, response.getBodyPtr(), response.getBodyLen());
XMLElement element = responseTree.getRootElement();
std::vector<std::string> responses;
if (element.isNamed(RESPONSE_SET)) {
std::string version;
std::string requestId;
if (element.getAttributeValue(VERSION, version) &&
std::strcmp(version.c_str(), RESPONSE_SET_VERSION) == 0 &&
element.getAttributeValue(REQUEST_ID, requestId) &&
std::strcmp(requestId.c_str(), expectedId) == 0) {
std::string responseData;
for (element = element.getFirstSubElement();
element.isNamed(RESPONSE);
element.nextSibling()) {
if (element.getValue(responseData)) {
responses.push_back(responseData);
} else {
element.log(logModule, Log::LOG_ERROR);
throw XMLTree::ParseException("unable to get Response "
"data");
}
}
if (element.isValid()) {
element.log(logModule, Log::LOG_ERROR);
throw XMLTree::ParseException("unexpected element in "
"ResponseSet");
}
} else if (std::strcmp(version.c_str(), RESPONSE_SET_VERSION) == 0) {
element.log(logModule, Log::LOG_ERROR);
throw XMLTree::ParseException(std::string("missing or mismatched "
"request id in "
"ResponseSet: ") +
requestId);
} else {
element.log(logModule, Log::LOG_ERROR);
throw XMLTree::ParseException(std::string("missing or unsupported "
"version in "
"ResponseSet: ") +
version);
}
} else {
element.log(logModule, Log::LOG_ERROR);
throw XMLTree::ParseException("unexpected element in response");
}
return responses;
}
开发者ID:,项目名称:,代码行数:58,代码来源:
示例3: getAgentAttributes
/**
* Fetches agent profile attributes using REST attribute service
* Agent has to be authenticated before doing this.
* If successful, properties object gets loaded with profile attributes
*/
am_status_t AgentProfileService::getAgentAttributes(
const std::string appSSOToken,
const std::string sharedAgentProfileName,
const std::string realmName,
am_properties_t properties)
{
am_status_t status = AM_FAILURE;
Http::Response response;
std::string certName;
std::string::size_type pos;
std::string encodedAgentToken = Http::encode(appSSOToken);
std::string encodedSharedAgentProfileName = Http::encode(sharedAgentProfileName);
std::string encodedRealmName = Http::encode(realmName);
std::string urlParams = "?name=";
urlParams.append(encodedSharedAgentProfileName);
urlParams.append("&attributes_names=realm");
urlParams.append("&attributes_values_realm=");
urlParams.append(encodedRealmName);
urlParams.append("&attributes_names=objecttype");
urlParams.append("&attributes_values_objecttype=Agent" );
urlParams.append("&admin=" );
urlParams.append(encodedAgentToken);
try {
setRestSvcInfo(mRestURL);
} catch (InternalException &iex) {
status = AM_FAILURE;
}
status = doHttpGet(mRestSvcInfo, urlParams, Http::CookieList(),
response, READ_INIT_BUF_LEN,
certName);
if(status == AM_SUCCESS) {
std::string xmlResponse(response.getBodyPtr());
pos = xmlResponse.find(EXCEPTION,0);
if(pos != std::string::npos){
status = AM_REST_ATTRS_SERVICE_FAILURE;
} else {
try {
status = parseAgentResponse(xmlResponse, properties);
} catch(...) {
Log::log(logModule, Log::LOG_ERROR,
"parseAgentResponse(): Attribute xml parsing error");
status = AM_REST_ATTRS_SERVICE_FAILURE;
}
}
} else {
status = AM_REST_ATTRS_SERVICE_FAILURE;
}
return status;
}
开发者ID:dromero91,项目名称:openam,代码行数:59,代码来源:agent_profile_service.cpp
示例4: completeHandshake
void WebSocketFramer::completeHandshake(http::Response& response)
{
std::string connection = response.get("Connection", "");
if (util::icompare(connection, "Upgrade") != 0)
throw std::runtime_error("WebSocket error: No Connection: Upgrade header in handshake response"); //, ws::ErrorNoHandshake
std::string upgrade = response.get("Upgrade", "");
if (util::icompare(upgrade, "websocket") != 0)
throw std::runtime_error("WebSocket error: No Upgrade: websocket header in handshake response"); //, ws::ErrorNoHandshake
std::string accept = response.get("Sec-WebSocket-Accept", "");
if (accept != computeAccept(_key))
throw std::runtime_error("WebSocket error: Invalid or missing Sec-WebSocket-Accept header in handshake response"); //, ws::ErrorNoHandshake
}
开发者ID:AsamQi,项目名称:libsourcey,代码行数:12,代码来源:websocket.cpp
示例5: handleRequest
void WRestResource::handleRequest(const Http::Request &request,
Http::Response &response)
{
try {
auto it = std::find(METHOD_STRINGS.cbegin(), METHOD_STRINGS.cend(), request.method());
auto idx = static_cast<std::size_t>(std::distance(METHOD_STRINGS.cbegin(), it));
if (it == METHOD_STRINGS.cend() || !handlers_[idx])
response.setStatus(405);
} catch (Exception e) {
response.setStatus(e.status());
}
}
开发者ID:AlexanderKotliar,项目名称:wt,代码行数:12,代码来源:WRestResource.C
示例6: handleRequest
void WRasterImage::handleRequest(const Http::Request& request,
Http::Response& response)
{
response.setMimeType("image/" + impl_->type_);
RasterStream s(response.out());
if (impl_->type_ == "png")
SkImageEncoder::EncodeStream(&s, *impl_->bitmap_, SkImageEncoder::kPNG_Type, 100);
else if (impl_->type_ == "jpg")
SkImageEncoder::EncodeStream(&s, *impl_->bitmap_, SkImageEncoder::kJPEG_Type, 100);
}
开发者ID:feuGeneA,项目名称:wt,代码行数:13,代码来源:WRasterImage-skia.C
示例7: authenticate
void Authenticator::authenticate(http::Request& request,
const http::Response& response)
{
for (http::Response::ConstIterator iter = response.find("WWW-Authenticate");
iter != response.end(); ++iter) {
if (isBasicCredentials(iter->second)) {
BasicAuthenticator(_username, _password).authenticate(request);
return;
}
// else if (isDigestCredentials(iter->second))
// ; // TODO
}
}
开发者ID:,项目名称:,代码行数:13,代码来源:
示例8: Register
bool Client::Register()
{
Json::Value data(Json::objectValue);
data["ip"] = Config::getIPAddr();
data["port"] = Config::getListenPort();
data["name"] = Config::getServerName();
data["terrain-name"] = Config::getTerrainName();
data["max-clients"] = Config::getMaxClients();
data["version"] = RORNET_VERSION;
data["use-password"] = Config::isPublic();
m_server_path = "/" + Config::GetServerlistPath() + "/server-list";
Logger::Log(LOG_INFO, "Attempting to register on serverlist (%s)", m_server_path.c_str());
Http::Response response;
int result_code = this->HttpRequest(Http::METHOD_POST, data.toStyledString().c_str(), &response);
if (result_code < 0)
{
Logger::Log(LOG_ERROR, "Registration failed, result code: %d", result_code);
return false;
}
else if (result_code != 200)
{
Logger::Log(LOG_INFO, "Registration failed, response code: HTTP %d, body: %s", result_code, response.GetBody().c_str());
return false;
}
Json::Value root;
Json::Reader reader;
if (!reader.parse(response.GetBody().c_str(), root))
{
Logger::Log(LOG_ERROR, "Registration failed, invalid server response (JSON parsing failed)");
Logger::Log(LOG_DEBUG, "Raw response: %s", response.GetBody().c_str());
return false;
}
Json::Value trust_level = root["verified-level"];
Json::Value challenge = root["challenge"];
if (!root.isObject() || !trust_level.isNumeric() || !challenge.isString())
{
Logger::Log(LOG_ERROR, "Registration failed, incorrect response from server");
Logger::Log(LOG_DEBUG, "Raw response: %s", response.GetBody().c_str());
return false;
}
m_token = challenge.asString();
m_trust_level = trust_level.asInt();
m_is_registered = true;
return true;
}
开发者ID:only-a-ptr,项目名称:ror-server,代码行数:50,代码来源:master-server.cpp
示例9: response
void RFC6455::Client::HandleHandshake (const HTTP::Request& inRequest) {
HTTP::Response response (HTTP::Code::BAD_REQUEST, inRequest.mVersion);
bool isUpgraded (false);
try {
if (inRequest.GetHeaderValue ("Connection") == "Upgrade" &&
inRequest.GetHeaderValue ("Upgrade") == "websocket" &&
inRequest.GetHeaderValue ("Sec-WebSocket-Key") != "" &&
inRequest.mMethod == HTTP::Method::GET &&
inRequest.mVersion == HTTP::Version::V11
) {
const auto key (inRequest.GetHeaderValue ("Sec-WebSocket-Key"));
const auto keyWithMagicString (key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
char base64[SHA1_BASE64_SIZE];
sha1 (keyWithMagicString.c_str ()).finalize().print_base64 (base64);
response.SetHeader (HTTP::Header ("Connection", "Upgrade"));
response.SetHeader (HTTP::Header ("Upgrade", "websocket"));
response.SetHeader (HTTP::Header ("Sec-WebSocket-Accept", std::string (base64)));
response.mCode = HTTP::Code::SWITCHING_PROTOCOLS;
isUpgraded = true;
}
}
catch (...) {}
mResponseEncoder.Write (response);
{
using namespace HTTP;
LOGINFO << "HTTP/" << VersionToString (response.mVersion) << " " << MethodToString (inRequest.mMethod)
<< " " << inRequest.mPath << " - " << response.mCode << " " << CodeToString (response.mCode) << " - RFC6455";
}
if (!isUpgraded) {
Quit ();
}
else {
// Clear the stream, route the pipe through the frame decoder.
GetReadStream ().Clear ().Pipe (mFrameDecoder).Pipe (this, &Client::HandleReceivedFrame);
mResponseEncoder.Clear ();
mPayloadStringEncoder.Pipe (mFrameEncoder).Pipe (GetWriteStream ());
mPayloadBinaryEncoder.Pipe (mFrameEncoder);
}
}
开发者ID:Eelco81,项目名称:server-test-project,代码行数:50,代码来源:WebSockClient.cpp
示例10: RetrievePublicIp
bool RetrievePublicIp()
{
char url[300] = "";
sprintf(url, "/%s/get-public-ip", Config::GetServerlistPath().c_str());
Http::Response response;
int result_code = Http::Request(Http::METHOD_GET,
Config::GetServerlistHostC(), url, "application/json", "", &response);
if (result_code < 0)
{
Logger::Log(LOG_ERROR, "Failed to retrieve public IP address");
return false;
}
Config::setIPAddr(response.GetBody());
return true;
}
开发者ID:only-a-ptr,项目名称:ror-server,代码行数:16,代码来源:master-server.cpp
示例11: getPublicAddress
IpAddress IpAddress::getPublicAddress(Time timeout)
{
// The trick here is more complicated, because the only way
// to get our public IP address is to get it from a distant computer.
// Here we get the web page from http://www.sfml-dev.org/ip-provider.php
// and parse the result to extract our IP address
// (not very hard: the web page contains only our IP address).
Http server("www.sfml-dev.org");
Http::Request request("/ip-provider.php", Http::Request::Get);
Http::Response page = server.sendRequest(request, timeout);
if (page.getStatus() == Http::Response::Ok)
return IpAddress(page.getBody());
// Something failed: return an invalid address
return IpAddress();
}
开发者ID:BourgondAries,项目名称:SFML,代码行数:17,代码来源:IpAddress.cpp
示例12: handle
int Server::handle(http::Server* server, http::Request& request, http::Response& response)
{
dfk_userdata_t user = (dfk_userdata_t) {nativeHandle()};
return dfk_fileserver_handler(user,
server->nativeHandle(),
request.nativeHandle(),
response.nativeHandle());
}
开发者ID:ivochkin,项目名称:dfk,代码行数:8,代码来源:fileserver.cpp
示例13:
void API::VersionEndPoint::Get (const HTTP::Request& inRequest, HTTP::Response& outResponse) {
json j;
j["application"] = OS::Version::GetApplicationName ();
j["version"] = OS::Version::GetApplicationVersion ();
outResponse.mCode = HTTP::Code::OK;
outResponse.SetBody (j.dump (), "application/json");
}
开发者ID:Eelco81,项目名称:server-test-project,代码行数:9,代码来源:VersionEndPoint.cpp
示例14: doHttpPost
am_status_t BaseService::doHttpPost(const ServiceInfo& service,
const std::string& uriParameters,
const Http::CookieList& cookieList,
const BodyChunkList& bodyChunkList,
Http::Response& response,
std::size_t initialBufferLen,
const std::string &cert_nick_name,
bool doFormPost,
bool checkHTTPRetCode,
const ServerInfo **serverInfo) const
{
am_status_t status;
if(doFormPost) {
status = doRequest(service, postPrefixChunk, uriParameters,
cookieList, postFormSuffixChunk, bodyChunkList,
response, initialBufferLen, cert_nick_name,
serverInfo);
} else {
status = doRequest(service, postPrefixChunk, uriParameters,
cookieList, postSuffixChunk, bodyChunkList,
response, initialBufferLen, cert_nick_name,
serverInfo);
}
if (checkHTTPRetCode &&
(AM_SUCCESS == status && Http::OK != response.getStatus())) {
Http::Status httpStatus = response.getStatus();
if (Http::NOT_FOUND == httpStatus) {
status = AM_NOT_FOUND;
} else if (Http::FORBIDDEN == httpStatus) {
status = AM_ACCESS_DENIED;
} else {
Log::log(logModule, Log::LOG_WARNING,
"BaseService::doHttpPost() failed, HTTP error = %d",
httpStatus);
status = AM_HTTP_ERROR;
}
}
return status;
}
开发者ID:,项目名称:,代码行数:43,代码来源:
示例15: acceptRequest
void WebSocketFramer::acceptRequest(http::Request& request, http::Response& response)
{
if (util::icompare(request.get("Connection", ""), "upgrade") == 0 &&
util::icompare(request.get("Upgrade", ""), "websocket") == 0) {
std::string version = request.get("Sec-WebSocket-Version", "");
if (version.empty()) throw std::runtime_error("WebSocket error: Missing Sec-WebSocket-Version in handshake request"); //, ws::ErrorHandshakeNoVersion
if (version != ws::ProtocolVersion) throw std::runtime_error("WebSocket error: Unsupported WebSocket version requested: " + version); //, ws::ErrorHandshakeUnsupportedVersion
std::string key = util::trim(request.get("Sec-WebSocket-Key", ""));
if (key.empty()) throw std::runtime_error("WebSocket error: Missing Sec-WebSocket-Key in handshake request"); //, ws::ErrorHandshakeNoKey
response.setStatus(http::StatusCode::SwitchingProtocols);
response.set("Upgrade", "websocket");
response.set("Connection", "Upgrade");
response.set("Sec-WebSocket-Accept", computeAccept(key));
// Set headerState 2 since the handshake was accepted.
_headerState = 2;
}
else throw std::runtime_error("WebSocket error: No WebSocket handshake"); //, ws::ErrorNoHandshake
}
开发者ID:AsamQi,项目名称:libsourcey,代码行数:20,代码来源:websocket.cpp
示例16: handleRequest
void WPdfImage::handleRequest(const Http::Request& request,
Http::Response& response)
{
HPDF_SaveToStream(pdf_);
HPDF_ResetStream(pdf_);
response.setMimeType("application/pdf");
for (;;) {
HPDF_BYTE buf[4096];
HPDF_UINT32 siz = 4096;
HPDF_ReadFromStream (pdf_, buf, &siz);
if (siz == 0)
break;
response.out().write((const char *)buf, siz);
}
}
开发者ID:AlexanderKotliar,项目名称:wt,代码行数:20,代码来源:WPdfImage.C
示例17: handle_etag
void EtagStoreResource::handle_etag(const Http::Request& request,
Http::Response& response) {
// TODO http://redmine.webtoolkit.eu/issues/2471
// const std::string* cookie_value = request.getCookieValue(cookie_name_);
std::string cookies = request.headerValue("Cookie");
if (cookies.empty()) {
return;
}
std::string pattern = cookie_name_ + "=";
int cookie_begin = cookies.find(pattern);
if (cookie_begin == std::string::npos) {
return;
}
cookie_begin += pattern.length();
int cookie_end = cookies.find(';', cookie_begin);
int cookie_length = (cookie_end == -1) ? -1 : (cookie_end - cookie_begin);
std::string cookie_value = cookies.substr(cookie_begin, cookie_length);
//
std::string etag_value = request.headerValue(receive_header());
boost::mutex::scoped_lock lock(cookie_to_etag_mutex_);
Map::iterator it = cookie_to_etag_.find(cookie_value);
if (it == cookie_to_etag_.end()) {
return;
}
Etag& etag = it->second;
if (etag_value.empty()) {
etag_value = etag.def;
}
etag.from_client = etag_value;
if (!etag.to_client.empty()) {
response.addHeader(send_header(), etag.to_client);
etag.to_client.clear();
} else {
etag.handler(etag.from_client);
}
if (!etag.from_client.empty()) {
response.addHeader(send_header(), etag.from_client);
}
}
开发者ID:starius,项目名称:wt-classes,代码行数:39,代码来源:EtagStore.cpp
示例18: checkHandshakeResponse
bool WebSocketFramer::checkHandshakeResponse(http::Response& response)
{
assert(_mode == ws::ClientSide);
assert(_headerState == 1);
if (response.getStatus() == http::StatusCode::SwitchingProtocols)
{
// Complete handshake or throw
completeHandshake(response);
// Success
_headerState++;
assert(handshakeComplete());
return true;
}
else if (response.getStatus() == http::StatusCode::Unauthorized)
assert(0 && "authentication not implemented");
else
throw std::runtime_error("WebSocket error: Cannot upgrade to WebSocket connection: " + response.getReason()); //, ws::ErrorNoHandshake
// Need to resend request
return false;
}
开发者ID:AsamQi,项目名称:libsourcey,代码行数:22,代码来源:websocket.cpp
示例19: doHttpPost
am_status_t BaseService::doHttpPost(const ServiceInfo& service,
const std::string& uriParameters,
const Http::CookieList& cookieList,
const BodyChunkList& bodyChunkList,
Http::Response& response,
bool doFormPost,
bool checkHTTPRetCode,
const ServerInfo **serverInfo) const {
am_status_t status;
if (doFormPost) {
status = doRequest(service, BodyChunk(std::string(HTTP_POST_PREFIX)), uriParameters,
cookieList, BodyChunk(std::string(HTTP_POST_FORM_SUFFIX)), bodyChunkList,
response, serverInfo);
} else {
status = doRequest(service, BodyChunk(std::string(HTTP_POST_PREFIX)), uriParameters,
cookieList, BodyChunk(std::string(HTTP_POST_SUFFIX)), bodyChunkList,
response, serverInfo);
}
if (checkHTTPRetCode &&
(AM_SUCCESS == status && Http::OK != response.getStatus())) {
Http::Status httpStatus = response.getStatus();
if (Http::NOT_FOUND == httpStatus) {
status = AM_NOT_FOUND;
} else if (Http::FORBIDDEN == httpStatus) {
status = AM_ACCESS_DENIED;
} else {
Log::log(logModule, Log::LOG_ERROR,
"BaseService::doHttpPost() failed, HTTP error = %d",
httpStatus);
status = AM_HTTP_ERROR;
}
}
return status;
}
开发者ID:JonathanFu,项目名称:OpenAM-1,代码行数:38,代码来源:base_service.cpp
示例20: handleRequest
void gdTVPdfResource::handleRequest(const Http::Request& request, Http::Response& response)
{
// is not a continuation for more data of a previous request
if ( !request.continuation() ) {
if ( !m_pTV ) return;
std::string strPdf = gdWApp->getUserTmpFile("pdf");
fprintf(stderr, "construction du wtree2pdf\n");
gdViewToPdf* cPdf = new gdViewToPdf(strPdf.c_str(), m_pTV, 0, m_l1row);
if ( !cPdf->m_pPdf ) return;
fprintf(stderr, "Impression de la page\n");
cPdf->printPdfPage(1, 1, 0);
delete cPdf;
setFileName(strPdf);
}
WFileResource::handleRequest(request, response);
// this was the last data for the request
if ( !response.continuation() )
unlink(fileName().c_str());
}
开发者ID:Wittyshare,项目名称:gdwtcore,代码行数:19,代码来源:gdTreeViewPdfRes.cpp
注:本文中的http::Response类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论