本文整理汇总了C++中request_type类的典型用法代码示例。如果您正苦于以下问题:C++ request_type类的具体用法?C++ request_type怎么用?C++ request_type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了request_type类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: process_handshake
lib::error_code process_handshake(request_type const & req,
std::string const & subprotocol, response_type & res) const
{
std::array<char, 16> key_final;
// copy key1 into final key
decode_client_key(req.get_header("Sec-WebSocket-Key1"), &key_final[0]);
// copy key2 into final key
decode_client_key(req.get_header("Sec-WebSocket-Key2"), &key_final[4]);
// copy key3 into final key
// key3 should be exactly 8 bytes. If it is more it will be truncated
// if it is less the final key will almost certainly be wrong.
// TODO: decide if it is best to silently fail here or produce some sort
// of warning or exception.
const std::string& key3 = req.get_header("Sec-WebSocket-Key3");
auto sz = std::min(size_t(8), key3.size());
std::copy(key3.begin(),
key3.begin() + sz,
key_final.begin() + 8);
res.append_header(
"Sec-WebSocket-Key3",
md5::md5_hash_string(std::string(key_final.begin(), key_final.end()))
);
res.append_header("Upgrade","WebSocket");
res.append_header("Connection","Upgrade");
// Echo back client's origin unless our local application set a
// more restrictive one.
if (res.get_header("Sec-WebSocket-Origin") == "") {
res.append_header("Sec-WebSocket-Origin",req.get_header("Origin"));
}
// Echo back the client's request host unless our local application
// set a different one.
if (res.get_header("Sec-WebSocket-Location") == "") {
uri_ptr uri = get_uri(req);
res.append_header("Sec-WebSocket-Location",uri->str());
}
if (subprotocol != "") {
res.replace_header("Sec-WebSocket-Protocol",subprotocol);
}
return lib::error_code();
}
开发者ID:thomasouvre,项目名称:casablanca,代码行数:49,代码来源:hybi00.hpp
示例2: validate_server_handshake_response
/**
* @param req The original request sent
* @param res The reponse to generate
* @return An error code, 0 on success, non-zero for other errors
*/
lib::error_code validate_server_handshake_response(request_type const & req,
response_type& res) const
{
// A valid response has an HTTP 101 switching protocols code
if (res.get_status_code() != http::status_code::switching_protocols) {
return error::make_error_code(error::invalid_http_status);
}
// And the upgrade token in an upgrade header
std::string const & upgrade_header = res.get_header("Upgrade");
if (utility::ci_find_substr(upgrade_header, constants::upgrade_token,
sizeof(constants::upgrade_token)-1) == upgrade_header.end())
{
return error::make_error_code(error::missing_required_header);
}
// And the websocket token in the connection header
std::string const & con_header = res.get_header("Connection");
if (utility::ci_find_substr(con_header, constants::connection_token,
sizeof(constants::connection_token)-1) == con_header.end())
{
return error::make_error_code(error::missing_required_header);
}
// And has a valid Sec-WebSocket-Accept value
std::string key = req.get_header("Sec-WebSocket-Key");
lib::error_code ec = process_handshake_key(key);
if (ec || key != res.get_header("Sec-WebSocket-Accept")) {
return error::make_error_code(error::missing_required_header);
}
return lib::error_code();
}
开发者ID:mkm85,项目名称:websocketpp,代码行数:39,代码来源:hybi13.hpp
示例3: request_type
request_type (request_type & packet)
{
setPCode (packet.getPCode ());
server_flag = packet.server_flag;
area = packet.area;
key.clone (packet.key);
}
开发者ID:IsCaster,项目名称:tair-rdb,代码行数:8,代码来源:type_packet.hpp
示例4: extract_subprotocols
lib::error_code extract_subprotocols(request_type const & req,
std::vector<std::string> & subprotocol_list)
{
if (!req.get_header("Sec-WebSocket-Protocol").empty()) {
http::parameter_list p;
if (!req.get_header_as_plist("Sec-WebSocket-Protocol",p)) {
http::parameter_list::const_iterator it;
for (it = p.begin(); it != p.end(); ++it) {
subprotocol_list.push_back(it->first);
}
} else {
return error::make_error_code(error::subprotocol_parse_error);
}
}
return lib::error_code();
}
开发者ID:mkm85,项目名称:websocketpp,代码行数:18,代码来源:hybi13.hpp
示例5: validate_handshake
lib::error_code validate_handshake(request_type const & r) const {
if (r.get_method() != "GET") {
return make_error_code(error::invalid_http_method);
}
if (r.get_version() != "HTTP/1.1") {
return make_error_code(error::invalid_http_version);
}
// required headers
// Host is required by HTTP/1.1
// Connection is required by is_websocket_handshake
// Upgrade is required by is_websocket_handshake
if (r.get_header("Sec-WebSocket-Key") == "") {
return make_error_code(error::missing_required_header);
}
return lib::error_code();
}
开发者ID:mkm85,项目名称:websocketpp,代码行数:19,代码来源:hybi13.hpp
示例6: get_uri
uri_ptr get_uri(request_type const & request) const {
std::string h = request.get_header("Host");
size_t last_colon = h.rfind(":");
size_t last_sbrace = h.rfind("]");
// no : = hostname with no port
// last : before ] = ipv6 literal with no port
// : with no ] = hostname with port
// : after ] = ipv6 literal with port
if (last_colon == std::string::npos ||
(last_sbrace != std::string::npos && last_sbrace > last_colon))
{
return uri_ptr(new uri(base::m_secure, h, request.get_uri()));
} else {
return uri_ptr(new uri(base::m_secure,
h.substr(0,last_colon),
h.substr(last_colon+1),
request.get_uri()));
}
// TODO: check if get_uri is a full uri
}
开发者ID:thomasouvre,项目名称:casablanca,代码行数:24,代码来源:hybi00.hpp
示例7: client_handshake_request
lib::error_code client_handshake_request(request_type& req, uri_ptr uri,
std::vector<std::string> const & subprotocols) const
{
req.set_method("GET");
req.set_uri(uri->get_resource());
req.set_version("HTTP/1.1");
req.append_header("Upgrade", "websocket");
req.append_header("Connection", "Upgrade");
req.replace_header("Sec-WebSocket-Version", "13");
req.replace_header("Host", uri->get_host_port());
if (!subprotocols.empty())
{
std::ostringstream result;
std::vector<std::string>::const_iterator it = subprotocols.begin();
result << *it++;
while (it != subprotocols.end())
{
result << ", " << *it++;
}
req.replace_header("Sec-WebSocket-Protocol", result.str());
}
// Generate handshake key
frame::uint32_converter conv;
unsigned char raw_key[16];
for (int i = 0; i < 4; i++)
{
conv.i = m_rng();
std::copy(conv.c, conv.c + 4, &raw_key[i * 4]);
}
req.replace_header("Sec-WebSocket-Key", base64_encode(raw_key, 16));
return lib::error_code();
}
开发者ID:satirev,项目名称:ShootBurger,代码行数:39,代码来源:hybi13.hpp
示例8: process_handshake
/* TODO: the 'subprotocol' parameter may need to be expanded into a more
* generic struct if other user input parameters to the processed handshake
* are found.
*/
lib::error_code process_handshake(request_type const & request,
std::string const & subprotocol, response_type & response) const
{
std::string server_key = request.get_header("Sec-WebSocket-Key");
lib::error_code ec = process_handshake_key(server_key);
if (ec) {
return ec;
}
response.replace_header("Sec-WebSocket-Accept",server_key);
response.append_header("Upgrade",constants::upgrade_token);
response.append_header("Connection",constants::connection_token);
if (!subprotocol.empty()) {
response.replace_header("Sec-WebSocket-Protocol",subprotocol);
}
return lib::error_code();
}
开发者ID:mkm85,项目名称:websocketpp,代码行数:25,代码来源:hybi13.hpp
示例9: prepare_request
void prepare_request(request_type &packet) {
set_state(has_request);
payload_length_ = packet.get_payload_length();
buffer_ = packet.get_buffer();
}
开发者ID:Fox-Alpha,项目名称:nscp,代码行数:5,代码来源:nrpe_client_protocol.hpp
示例10: prepare_request
void prepare_request(request_type &packet) {
set_state(has_request);
buffer_ = packet.write();
}
开发者ID:0000-bigtree,项目名称:nscp,代码行数:4,代码来源:nscp_client_protocol.hpp
注:本文中的request_type类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论