当前位置: 首页>>代码示例>>C++>>正文


C++ http_request::reply方法代码示例

本文整理汇总了C++中http_request::reply方法的典型用法代码示例。如果您正苦于以下问题:C++ http_request::reply方法的具体用法?C++ http_request::reply怎么用?C++ http_request::reply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http_request的用法示例。


在下文中一共展示了http_request::reply方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: handle_delete

void MetaCDNReceiver::handle_delete(http_request message) {
	/*
	Use cases:
	1. when CDN deletes a file from itself to store some other file because of its limited capacity

	JSON Format
	Request
	{
		"FileName": "a.txt",
		"CdnId" : 2
	}

	Response: status OK or Forbidden (no json object included)
	*/
	try {
		int result;
		if(message.headers().content_type()==U("application/json")) {
			cout << endl << "---------------"<< endl;
			cout << message.to_string() << endl <<endl;

			json::value jsonObj = message.extract_json().get();
			int cdnId = jsonObj.at(U("CdnId")).as_integer();
			string fileName = utility::conversions::to_utf8string(jsonObj.at(U("FileName")).as_string());
			result = m_meta->deleteCdnFromMetaEntry(fileName, cdnId);
			message.reply(status_codes::OK, result==0? U("Deleted successfully") : U("Delete failed"));
		} else {
			message.reply(status_codes::Forbidden, U("Json object is required"));
		}
	} catch(json::json_exception &e) {
		message.reply(status_codes::Forbidden, U("Invalid json object"));
		return;
	}
}
开发者ID:KeyStorke,项目名称:Content-Distribution-Network,代码行数:33,代码来源:MetaCDNReceiver.cpp

示例2: handle_get

//
// A GET of the dealer resource produces a list of existing tables.
// 
void BlackJackDealer::handle_get(http_request message)
{
    ucout <<  message.to_string() << endl;

    auto paths = http::uri::split_path(http::uri::decode(message.relative_uri().path()));
    if (paths.empty())
    {
        message.reply(status_codes::OK, TablesAsJSON(U("Available Tables"), s_tables));
        return;
    }

    utility::string_t wtable_id = paths[0];
    const utility::string_t table_id = wtable_id;

    // Get information on a specific table.
    auto found = s_tables.find(table_id);
    if (found == s_tables.end())
    {
        message.reply(status_codes::NotFound);
    }
    else
    {
        message.reply(status_codes::OK, found->second->AsJSON());
    }
};
开发者ID:PKRoma,项目名称:cpprestsdk,代码行数:28,代码来源:Dealer.cpp

示例3: handle_get

// Handler to process HTTP::GET requests.
// Replies to the request with data.
void CasaLens::handle_get(http_request message)
{    
    auto path = message.relative_uri().path();
    auto content_data = m_htmlcontentmap.find(path);
    if (content_data == m_htmlcontentmap.end())
    {
        message.reply(status_codes::NotFound, U("Path not found")).then(std::bind(&handle_error, std::placeholders::_1));
        return;
    }

    auto file_name = std::get<0>(content_data->second);
    auto content_type = std::get<1>(content_data->second);
    concurrency::streams::fstream::open_istream(file_name, std::ios::in).then([=](concurrency::streams::istream is)
    {
        message.reply(status_codes::OK, is, content_type).then(std::bind(&handle_error, std::placeholders::_1));
    }).then([=](pplx::task<void>& t)
    {
        try
        {
            t.get();
        }
        catch(...)
        {
            // opening the file (open_istream) failed.
            // Reply with an error.
            message.reply(status_codes::InternalError).then(std::bind(&handle_error, std::placeholders::_1));
        }
    });
}
开发者ID:Insityou,项目名称:casablanca,代码行数:31,代码来源:casalens.cpp

示例4: handle_post

//
// A POST of the dealer resource creates a new table and returns a resource for
// that table.
// 
void BlackJackDealer::handle_post(http_request message)
{
    ucout <<  message.to_string() << endl;

    auto paths = uri::split_path(uri::decode(message.relative_uri().path()));
    
    if (paths.empty())
    {
        utility::ostringstream_t nextIdString;
        nextIdString << nextId;

        std::shared_ptr<DealerTable> tbl = std::make_shared<DealerTable>(nextId, 8, 6);
        s_tables[nextIdString.str()] = tbl;
        nextId += 1;

        message.reply(status_codes::OK, BJPutResponse(ST_PlaceBet, tbl->AsJSON()).AsJSON());
        return;
    }
    utility::string_t wtable_id = paths[0];
    const utility::string_t table_id = wtable_id;

    // Join an existing table.
    auto found = s_tables.find(table_id);
    if (found == s_tables.end())
    {
        message.reply(status_codes::NotFound);
        return;
    }

    auto table = std::static_pointer_cast<DealerTable>(found->second);

    if ( table->Players.size() < table->Capacity )
    {
        std::map<utility::string_t, utility::string_t> query = uri::split_query(uri::decode(message.request_uri().query()));

        auto cntEntry = query.find(QUERY_NAME);

        if (cntEntry != query.end() && !cntEntry->second.empty())
        {
            table->AddPlayer(Player(cntEntry->second));
            message.reply(status_codes::OK, BJPutResponse(ST_PlaceBet, table->AsJSON()).AsJSON());
        }
        else
        {
            message.reply(status_codes::Forbidden, U("Player name is required in query"));
        }
    }
    else
    {
        utility::ostringstream_t os;
        os << U("Table ") << table->Id << U(" is full");
        message.reply(status_codes::Forbidden, os.str());
    }
};
开发者ID:PKRoma,项目名称:cpprestsdk,代码行数:58,代码来源:Dealer.cpp

示例5: handle_put

//
// A PUT to a table resource makes a card request (hit / stay).
// 
void BlackJackDealer::handle_put(http_request message)
{
    ucout <<  message.to_string() << endl;

    auto paths = uri::split_path(uri::decode(message.relative_uri().path()));
    auto query = uri::split_query(uri::decode(message.relative_uri().query()));
    auto queryItr = query.find(REQUEST);
    if (paths.empty() || queryItr == query.end())
    {
        message.reply(status_codes::Forbidden, U("TableId and request are required."));
    }
    utility::string_t wtable_id = paths[0];
    utility::string_t request = queryItr->second;
    const utility::string_t table_id = wtable_id;

    // Get information on a specific table.
    auto found = s_tables.find(table_id);
    if ( found == s_tables.end() )
    {
        message.reply(status_codes::NotFound);
    }

    auto table = std::static_pointer_cast<DealerTable>(found->second);

    if ( request == BET )
    {
        table->Bet(message);
    }
    else if ( request == DOUBLE )
    {
        table->DoubleDown(message);
    }
    else if ( request == INSURE )
    {
        table->Insure(message);
    }
    else if ( request == HIT )
    {
        table->Hit(message);
    }
    else if ( request == STAY )
    {
        table->Stay(message);
    }
    else if ( request == REFRESH )
    {
        table->Wait(message);
    }
    else 
    {
        message.reply(status_codes::Forbidden, U("Unrecognized request"));
    }
};
开发者ID:PKRoma,项目名称:cpprestsdk,代码行数:56,代码来源:Dealer.cpp

示例6: handle_register

void MetaCDNReceiver::handle_register(http_request message) {
	/*
	-when a new CDN joins, it has to register itself to Meta Server

	JSON Format
	Request
	{
		"Type": 0, //0=for cdn, 1=for fss
		"IP": "1.1.1.1:4000", //the sender CDN's IP address + port(listening to incoming requests)
		"Lat": 23.00, //the sender CDN's location
		"Lng": 148.12
	}
	Response
	{
		"CdnId": 1 //the assigned id for the cdn
	}

	*/
	try {

		int assignedId = -1;
		if(message.headers().content_type()==U("application/json")) {
			cout << endl << "---------------"<< endl;
			cout << message.to_string() << endl <<endl;

			json::value jsonObj = message.extract_json().get();
			if(jsonObj.at(U("Type")).as_integer() == 0) {
				string ipAddr = utility::conversions::to_utf8string(jsonObj.at(U("IP")).as_string());
				//TODO: validate ip address
				Address cdnAddr(make_pair(jsonObj.at(U("Lat")).as_double(), jsonObj.at(U("Lng")).as_double()), ipAddr);
				assignedId = m_meta->registerCdn(cdnAddr);
				json::value respFinal = json::value::object();
				respFinal[U("CdnId")] = json::value::number(assignedId);
				message.reply(assignedId!=-1? status_codes::OK : status_codes::NotFound, respFinal);
			} else if(jsonObj.at(U("Type")).as_integer() == 1){
				string ipAddr = utility::conversions::to_utf8string(jsonObj.at(U("IP")).as_string());
				//TODO: validate ip address
				Address fssAddr(make_pair(jsonObj.at(U("Lat")).as_double(), jsonObj.at(U("Lng")).as_double()), ipAddr);
				m_meta->setFssAddr(fssAddr);
				message.reply(status_codes::OK, "FSS registration complete");
			} else {
				message.reply(status_codes::Forbidden, U("Invalid type"));
			}
		} else {
			message.reply(status_codes::Forbidden, U("Json object is required"));
		}
	} catch(json::json_exception &e) {
		message.reply(status_codes::Forbidden, U("Invalid json object"));
		return;
	}
}
开发者ID:KeyStorke,项目名称:Content-Distribution-Network,代码行数:51,代码来源:MetaCDNReceiver.cpp

示例7: if

void details::http_listener_impl::handle_request(http_request msg)
{
    // Specific method handler takes priority over general.
    const method &mtd = msg.method();
    if(m_supported_methods.count(mtd))
    {
        m_supported_methods[mtd](msg);
    }
    else if(mtd == methods::OPTIONS)
    {
        handle_options(msg);
    }
    else if(mtd == methods::TRCE)
    {
        handle_trace(msg);
    }
    else if(m_all_requests != nullptr)
    {
        m_all_requests(msg);
    }
    else
    {
        // Method is not supported.
        // Send back a list of supported methods to the client.
        http_response response(status_codes::MethodNotAllowed);
        response.headers().add(U("Allow"), get_supported_methods());
        msg.reply(response);
    }
}
开发者ID:PKRoma,项目名称:cpprestsdk,代码行数:29,代码来源:http_listener.cpp

示例8: handle_delete

//
// A DELETE of the player resource leaves the table.
// 
void BlackJackDealer::handle_delete(http_request message)
{
    ucout <<  message.to_string() << endl;

    auto paths = uri::split_path(uri::decode(message.relative_uri().path()));
    
    if (paths.empty())
    {
        message.reply(status_codes::Forbidden, U("TableId is required."));
        return;
    }
    utility::string_t wtable_id = paths[0];

    const utility::string_t table_id = wtable_id;

    // Get information on a specific table.
    auto found = s_tables.find(table_id);
    if (found == s_tables.end())
    {
        message.reply(status_codes::NotFound);
        return;
    }

    auto table = std::static_pointer_cast<DealerTable>(found->second);

    std::map<utility::string_t, utility::string_t> query = uri::split_query(uri::decode(message.request_uri().query()));

    auto cntEntry = query.find(QUERY_NAME);

    if ( cntEntry != query.end() )
    {
        if ( table->RemovePlayer(cntEntry->second) )
        {
            message.reply(status_codes::OK);
        }
        else
        {
            message.reply(status_codes::NotFound);
        }
    }
    else
    {
        message.reply(status_codes::Forbidden, U("Player name is required in query"));
    }
};
开发者ID:PKRoma,项目名称:cpprestsdk,代码行数:48,代码来源:Dealer.cpp

示例9: handle_get

void MyListener::handle_get(http_request message)
{
	web::uri req_uri = message.request_uri();
	utility::string_t req_query = req_uri.query();
	auto req_split_query = web::uri::split_query(req_query);
	//utility::string_t params;
	std::string error;
	for (auto it = req_split_query.begin(); it != req_split_query.end(); ++it)
	{
		//params += (*it).first + utility::conversions::to_string_t(": ") + (*it).second + utility::conversions::to_string_t("\n");
		// ***** Проверка логина *****
		if (utility::conversions::to_utf8string((*it).first) == "login")
		{
			std::string login = utility::conversions::to_utf8string((*it).second);
			for (auto iter = login.begin(); iter != login.end(); ++iter)
			{
				if (!(*iter >= 'a' && *iter <= 'z'))
					error += "Error in login. Unacceptable symbols\n";
			}
		}
		// ***** Проверка пароля *****
		if (utility::conversions::to_utf8string((*it).first) == "password")
		{
		
			std::string pass = utility::conversions::to_utf8string((*it).second);
			if (pass.length() < 8)
				error += "Error in password. Insufficient password length\n";
			for (auto iter = pass.begin(); iter != pass.end(); ++iter)
			{
				//if (!isdigit(*iter) && !isalpha(*iter) && !ispunct(*iter))
				if (!(*iter >= 33 && *iter <= 126))
				{			
					error += "Error in password. Unacceptable symbols\n";
				}	
			}
		}
	}
	if (error == "")
		message.reply(status_codes::OK, "OK");// "OK\n" + utility::conversions::to_utf8string(params));
	else
		message.reply(status_codes::BadRequest, error);// + '\n' + utility::conversions::to_utf8string(params));
	
		
	////message.reply(status_codes::OK, params);
}
开发者ID:Ibrammes,项目名称:RestWithSetup,代码行数:45,代码来源:MyListener.cpp

示例10: response

void
RestEngineUri::handle_delete(http_request request)
{
    std::cout << request.method() << " : " << request.absolute_uri().path() << std::endl;
    http_response response(status_codes::OK);
    std::string resultstr("Not Supported");
    std::pair<bool, std::string> result {true, std::string()};
    make_response(response, resultstr, result);
    request.reply(response);
}
开发者ID:Hitachi-Data-Systems,项目名称:ivy,代码行数:10,代码来源:RestEngineUri.cpp

示例11: fetch_data

void CasaLens::fetch_data(http_request message, const std::wstring& postal_code, const std::wstring& location)
{
    json::value resp_data;

    try
    {
        m_rwlock.lock_read();
        resp_data = m_data[postal_code];
        m_rwlock.unlock();

        if (resp_data.is_null())
        {
            std::vector<pplx::task<json::value>> tasks;

            tasks.push_back(get_events(postal_code));
            tasks.push_back(get_weather(postal_code));
            tasks.push_back(get_pictures(location, U("4")));
            tasks.push_back(get_movies(postal_code));

            pplx::when_all(tasks.begin(), tasks.end()).wait();
            resp_data = json::value::object();

            for (auto& iter : tasks)
            {
                auto jval = iter.get();
                auto key = jval.as_object().begin()->first;
                resp_data[key] = jval.as_object().begin()->second;
            }

            m_rwlock.lock();
            m_data[postal_code] = resp_data;
            m_rwlock.unlock();
        }

        // Reply with the aggregated JSON data
        message.reply(status_codes::OK, resp_data).then([](pplx::task<void> t) { handle_error(t); });
    }
    catch (...)
    {
        message.reply(status_codes::InternalError).then([](pplx::task<void> t) { handle_error(t); });
    }
}
开发者ID:Microsoft,项目名称:cpprestsdk,代码行数:42,代码来源:datafetcher.cpp

示例12: handle_post

// Respond to HTTP::POST messages
// Post data will contain the postal code or location string.
// Aggregate location data from different services and reply to the POST request.
void CasaLens::handle_post(http_request message)
{
    auto path = message.relative_uri().path();
    if (0 == path.compare(U("/")))
    {
        message.extract_string()
            .then([=](const utility::string_t& location) { get_data(message, location); })
            .then([](pplx::task<void> t) { handle_error(t); });
    }
    else
    {
        message.reply(status_codes::NotFound, U("Path not found")).then([](pplx::task<void> t) { handle_error(t); });
    }
}
开发者ID:Microsoft,项目名称:cpprestsdk,代码行数:17,代码来源:casalens.cpp

示例13: handle_get

void RDService::handle_get(http_request message)
{
	std::cout << "GET request got" << std::endl;
	web::uri reqUri = message.relative_uri();

	wcout << "Query:" << reqUri.query() << endl << reqUri.resource().to_string() << endl;

	utility::string_t queryStr = reqUri.query();
	
	auto path = reqUri.path();
	vector<utility::string_t> queryList = splitStringByAnd(queryStr);

	wstring conditions = U("");

	if (queryList.size() > 0)
	{
		conditions += queryList[0];
	}

	for (size_t i = 1; i < queryList.size(); i++)
	{
		conditions += U(" AND ") + queryList[i];
	}

	string finalCondition(conditions.begin(), conditions.end());

	vector<Vehicle> dbResult = DbHelper::getInstance()->getVehicleList((char *)finalCondition.c_str());

	string table = "";


	auto path2 = message.relative_uri().path();
	string reply;

	for (int i = 0; i < dbResult.size(); i++)
	{
		Vehicle v = dbResult[i];
		string tr = "";
		tr += v.Registration + "#";
		tr +=  to_string(v.Make) + "#";
		tr += "" + v.Model + "#";
		tr += "" + v.Owner + "#";
	
		table += tr;
	}

	utility::string_t replyText(table.begin(), table.end());
	message.reply(status_codes::OK, replyText).then([](pplx::task<void> t) { handle_error(t); });

}
开发者ID:razibdeb,项目名称:CPP-WebService,代码行数:50,代码来源:RDService.cpp

示例14: response

void
RestRollupsUri::handle_get(http_request request)
{
    std::cout << request.method() << " : " << request.absolute_uri().path() << std::endl;
    http_response response(status_codes::OK);
    std::string resultstr("Not Supported");
    std::pair<bool, std::string> result {true, std::string()};

    resultstr = m_s.show_rollup_structure();

    make_response(response, resultstr, result);
    request.reply(response);
    return;
}
开发者ID:Hitachi-Data-Systems,项目名称:ivy,代码行数:14,代码来源:RestRollupsUri.cpp

示例15: validator

void
RestRollupsUri::handle_post(http_request request)
{
    std::cout << request.method() << " : " << request.absolute_uri().path() << std::endl;
    int rc = 0;
    std::string resultstr;
    std::pair<bool, std::string> result {true, std::string()};

    char json[1024];

    // extract json from request
    snprintf(json, sizeof(json), "%s", request.extract_string(true).get().c_str());
    std::cout << "JSON:\n" << json << std::endl;

    rapidjson::Document document; 
    if (document.Parse(json).HasParseError())
    {
        rc = 1;
        resultstr += "document invalid";
    }

    rapidjson::SchemaValidator validator(*_schema);
    if (!document.Accept(validator)) {
        rc = 1;
        resultstr += get_schema_validation_error(&validator);
    }

    rapidjson::Value::MemberIterator name = document.FindMember("name");
    rapidjson::Value::MemberIterator nocsv = document.FindMember("nocsv");
    rapidjson::Value::MemberIterator quantity = document.FindMember("quantity");
    rapidjson::Value::MemberIterator maxdroop = document.FindMember("maxDroop");
    rapidjson::Value::MemberIterator maxsdroop_validation = document.FindMember("maxDroopMaxtoMinIOPSSection");

    // Execute Ivy Engine command
    if (rc == 0)
    {
        std::unique_lock<std::mutex> u_lk(goStatementMutex);
        std::pair<int, std::string> 
        rslt = m_s.create_rollup(name->value.GetString(),
                   (nocsv != document.MemberEnd() ? nocsv->value.GetBool() : false),
                   false /* have_quantity_validation */,
                   (maxsdroop_validation != document.MemberEnd() ? maxsdroop_validation->value.GetBool() : false),
                   (quantity != document.MemberEnd() ? quantity->value.GetInt() : 1),
                   (maxdroop != document.MemberEnd() ? maxdroop->value.GetDouble() : 6.95323e-310));
    }

    http_response response(status_codes::OK);
    make_response(response, resultstr, result);
    request.reply(response);
}
开发者ID:Hitachi-Data-Systems,项目名称:ivy,代码行数:50,代码来源:RestRollupsUri.cpp


注:本文中的http_request::reply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。