本文整理汇总了C++中http::Request类的典型用法代码示例。如果您正苦于以下问题:C++ Request类的具体用法?C++ Request怎么用?C++ Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: request
TEST_F (WebSockServerTester, FailedHandshakes_NoKey) {
HTTP::Request request (HTTP::Method::GET, "/");
request.SetHeader (HTTP::Header ("Connection", "Upgrade"));
request.SetHeader (HTTP::Header ("Upgrade", "websocket"));
VerifyBadRequest (request);
}
示例2: handleFileExportRequest
void handleFileExportRequest(const http::Request& request,
http::Response* pResponse)
{
// see if this is a single or multiple file request
std::string file = request.queryParamValue("file");
if (!file.empty())
{
// resolve alias and ensure that it exists
FilePath filePath = module_context::resolveAliasedPath(file);
if (!filePath.exists())
{
pResponse->setError(http::status::NotFound, "file doesn't exist");
return;
}
// get the name
std::string name = request.queryParamValue("name");
if (name.empty())
{
pResponse->setError(http::status::BadRequest, "name not specified");
return;
}
// download as attachment
setAttachmentResponse(request, name, filePath, pResponse);
}
else
{
handleMultipleFileExportRequest(request, pResponse);
}
}
示例3: Listen
bool Server::Listen()
{
m_valid = false;
if (!m_server.Listen())
return false;
//Debug("Handshaking...");
HTTP::Request handshake;
if (!handshake.Receive(m_server))
{
Error("Failed to process HTTP request");
}
map<string, string> & headers = handshake.Headers();
auto i = headers.find("Sec-WebSocket-Key");
if (i == headers.end())
{
Error("No Sec-WebSocket-Key header!");
for (i = headers.begin(); i != headers.end(); ++i)
{
Error("Key: %s = %s", i->first.c_str(), i->second.c_str());
}
return false;
}
//Debug("Finished handshake");
string magic = Foxbox::WS::Magic(i->second);
m_server.Send("HTTP/1.1 101 Switching Protocols\r\n");
m_server.Send("Upgrade: WebSocket\r\n");
m_server.Send("Connection: Upgrade\r\n");
m_server.Send("Sec-WebSocket-Accept: %s\r\n", magic.c_str());
m_server.Send("Sec-WebSocket-Protocol: %s\r\n\r\n",
headers["Sec-WebSocket-Protocol"].c_str());
m_valid = true;
return true;
}
示例4: updateAuthInfo
void Authenticator::updateAuthInfo(http::Request& request)
{
if (request.has("Authorization")) {
const std::string& authorization = request.get("Authorization");
if (isBasicCredentials(authorization)) {
BasicAuthenticator(_username, _password).authenticate(request);
}
// else if (isDigestCredentials(authorization))
// ; // TODO
}
}
示例5: handleFileShow
void handleFileShow(const http::Request& request, http::Response* pResponse)
{
// get the file path
FilePath filePath(request.queryParamValue("path"));
if (!filePath.exists())
{
pResponse->setNotFoundError(request.uri());
return;
}
// send it back
pResponse->setCacheWithRevalidationHeaders();
pResponse->setCacheableFile(filePath, request);
}
示例6: 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);
}
}
示例7: handleFilesRequest
void handleFilesRequest(const http::Request& request,
http::Response* pResponse)
{
Options& options = session::options();
if (options.programMode() != kSessionProgramModeServer)
{
pResponse->setError(http::status::NotFound,
request.uri() + " not found");
return;
}
// get prefix and uri
std::string prefix = "/files/";
std::string uri = request.uri();
// validate the uri
if (prefix.length() >= uri.length() || // prefix longer than uri
uri.find(prefix) != 0 || // uri doesn't start with prefix
uri.find("..") != std::string::npos) // uri has inavlid char sequence
{
pResponse->setError(http::status::NotFound,
request.uri() + " not found");
return;
}
// compute path to file
int prefixLen = prefix.length();
std::string relativePath = http::util::urlDecode(uri.substr(prefixLen));
if (relativePath.empty())
{
pResponse->setError(http::status::NotFound, request.uri() + " not found");
return;
}
// complete path to file
FilePath filePath = module_context::userHomePath().complete(relativePath);
// no directory listing available
if (filePath.isDirectory())
{
pResponse->setError(http::status::NotFound,
"No listing available for " + request.uri());
return;
}
pResponse->setNoCacheHeaders();
pResponse->setFile(filePath, request);
}
示例8: setAttachmentResponse
void setAttachmentResponse(const http::Request& request,
const std::string& filename,
const FilePath& attachmentPath,
http::Response* pResponse)
{
if (request.headerValue("User-Agent").find("MSIE") == std::string::npos)
{
pResponse->setNoCacheHeaders();
}
else
{
// Can't set full no-cache headers because this breaks downloads in IE
pResponse->setHeader("Expires", "Fri, 01 Jan 1990 00:00:00 GMT");
pResponse->setHeader("Cache-Control", "private");
}
// Can't rely on "filename*" in Content-Disposition header because not all
// browsers support non-ASCII characters here (e.g. Safari 5.0.5). If
// possible, make the requesting URL contain the UTF-8 byte escaped filename
// as the last path element.
pResponse->setHeader("Content-Disposition",
"attachment; filename*=UTF-8''"
+ http::util::urlEncode(filename, false));
pResponse->setHeader("Content-Type", "application/octet-stream");
pResponse->setBody(attachmentPath);
}
示例9: setMovedTemporarily
void Response::setMovedTemporarily(const http::Request& request,
const std::string& location)
{
std::string uri = URL::complete(request.absoluteUri(),
safeLocation(location));
setError(http::status::MovedTemporarily, uri);
setHeader("Location", uri);
}
示例10: 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());
}
示例11: runtime_error
BasicAuthenticator::BasicAuthenticator(const http::Request& request)
{
std::string scheme;
std::string authInfo;
request.getCredentials(scheme, authInfo);
if (util::icompare(scheme, "Basic") == 0) {
parseAuthInfo(authInfo);
} else
throw std::runtime_error("Basic authentication expected");
}
示例12: 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
}
示例13: 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());
}
}
示例14: handle_etag
void EtagStoreResource::handle_etag(const Http::Request& request,
Http::Response& response) {
// TODO http://redmine.webtoolkit.eu/issues/2471
// const std::string* cookie_value = request.getCookieValue(cookie_name_);
std::string cookies = request.headerValue("Cookie");
if (cookies.empty()) {
return;
}
std::string pattern = cookie_name_ + "=";
int cookie_begin = cookies.find(pattern);
if (cookie_begin == std::string::npos) {
return;
}
cookie_begin += pattern.length();
int cookie_end = cookies.find(';', cookie_begin);
int cookie_length = (cookie_end == -1) ? -1 : (cookie_end - cookie_begin);
std::string cookie_value = cookies.substr(cookie_begin, cookie_length);
//
std::string etag_value = request.headerValue(receive_header());
boost::mutex::scoped_lock lock(cookie_to_etag_mutex_);
Map::iterator it = cookie_to_etag_.find(cookie_value);
if (it == cookie_to_etag_.end()) {
return;
}
Etag& etag = it->second;
if (etag_value.empty()) {
etag_value = etag.def;
}
etag.from_client = etag_value;
if (!etag.to_client.empty()) {
response.addHeader(send_header(), etag.to_client);
etag.to_client.clear();
} else {
etag.handler(etag.from_client);
}
if (!etag.from_client.empty()) {
response.addHeader(send_header(), etag.from_client);
}
}
示例15: main
int main(int argc, char *argv[])
{
HTTP::HeaderSet hs;
hs.add("Content-Type", "text/plain");
assert(hs.has("Content-Type"));
hs.add("Content-Length", "50823");
hs.add("Rubbish", "123");
hs.remove("Rubbish");
assert(!hs.has("Rubbish"));
std::string hso = hs.toString();
assert_equal(hso, "Content-Length: 50823\r\nContent-Type: text/plain\r\n\r\n");
HTTP::HeaderSet *hsp = HTTP::HeaderSet::fromString(hso);
assert(hsp && "parsed header must be valid");
std::string hspo = hsp->toString();
assert_equal(hspo, hso);
//Test the HTTP::Request object.
HTTP::Request req;
req.type = HTTP::Request::kPOST;
req.path = "/meta.json";
req.headers.add("Content-Type", "application/json");
req.headers.add("Content-Length", "11");
req.headers.add("User-Agent", "auris-db");
req.content = "Hello World";
std::string reqo = req.toString();
assert_equal(reqo, "POST /meta.json HTTP/1.1\r\nContent-Length: 11\r\nContent-Type: application/json\r\nUser-Agent: auris-db\r\n\r\nHello World\r\n");
HTTP::Request *reqp = HTTP::Request::fromString(reqo);
assert(reqp && "parsed request must be valid");
std::string reqpo = reqp->toString();
assert_equal(reqpo, reqo);
std::cout << reqo;
return 0;
}