本文整理汇总了C++中http::Response类的典型用法代码示例。如果您正苦于以下问题:C++ Response类的具体用法?C++ Response怎么用?C++ Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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;
}
示例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;
}
示例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
}
示例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());
}
}
示例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);
}
示例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
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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();
}
示例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());
}
示例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");
}
示例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;
}
示例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
}