本文整理汇总了C++中http::Request::GetHeaderValue方法的典型用法代码示例。如果您正苦于以下问题:C++ Request::GetHeaderValue方法的具体用法?C++ Request::GetHeaderValue怎么用?C++ Request::GetHeaderValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http::Request
的用法示例。
在下文中一共展示了Request::GetHeaderValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
示例2: response
void SSE::Client::HandleHandshake (const HTTP::Request& inRequest) {
HTTP::Response response (HTTP::Code::BAD_REQUEST, inRequest.mVersion);
bool isUpgraded (false);
try {
if (inRequest.GetHeaderValue ("Accept") == "text/event-stream" &&
inRequest.mMethod == HTTP::Method::GET &&
inRequest.mVersion == HTTP::Version::V11
) {
// Standard SSE headers
response.SetHeader (HTTP::Header ("Connection", "keep-alive"));
response.SetHeader (HTTP::Header ("Content-Type", "text/event-stream"));
// Prevent caching
response.SetHeader (HTTP::Header ("Cache-Control", "no-cache"));
// This SSE server most likely does not host the origin of the request
// ==> Enable CORS.
response.SetHeader (HTTP::Header ("Access-Control-Allow-Origin", "*"));
response.SetHeader (HTTP::Header ("Access-Control-Allow-Credentials", "true"));
// The response constructor sets the length to zero, this makes connections
// assume there is no more data coming. Note: there is a stream in response, so the body
// has variable length! Remove this header.
response.RemoveHeaders ("Content-Length");
// Optionally check for last event ID.
try {
const auto list = inRequest.GetHeaders ("Last-Event-ID");
if (!list.empty ()) {
uint8_t lastId = std::stoi (list[0].GetValue ());
mEventEncoder.SetLastId (lastId);
}
}
catch (...) {}
// Handshake completed.
response.mCode = HTTP::Code::OK;
isUpgraded = true;
}
}
catch (...) {}
// Send the handshake response
mResponseEncoder.Write (response);
{
using namespace HTTP;
LOGINFO << "HTTP/" << VersionToString (response.mVersion) << " " << MethodToString (inRequest.mMethod)
<< " " << inRequest.mPath << " - " << response.mCode << " " << CodeToString (response.mCode) << " - SSE";
}
if (!isUpgraded) {
Quit ();
}
else {
// Clear the read stream (SSE only contains outgoing events)
GetReadStream ().Clear ();
mResponseEncoder.Clear ();
mToStringConverter.Clear ();
mToPacketConverter.Clear ();
mRequestDecoder.Clear ();
mResponseEncoder.Clear ();
mEventEncoder.Pipe (mToPacketConverter).Pipe (GetWriteStream ());
}
}