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