本文整理汇总了C++中http::Request类的典型用法代码示例。如果您正苦于以下问题:C++ Request类的具体用法?C++ Request怎么用?C++ Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:Eelco81,项目名称:server-test-project,代码行数:7,代码来源:WebSockServerTester.cpp
示例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);
}
}
开发者ID:lionelc,项目名称:rstudio,代码行数:31,代码来源:SessionFiles.cpp
示例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;
}
开发者ID:szmoore,项目名称:foxbox,代码行数:34,代码来源:websocket.cpp
示例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
}
}
开发者ID:,项目名称:,代码行数:12,代码来源:
示例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);
}
开发者ID:Wisling,项目名称:rstudio,代码行数:14,代码来源:SessionWorkbench.cpp
示例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);
}
}
开发者ID:Eelco81,项目名称:server-test-project,代码行数:50,代码来源:WebSockClient.cpp
示例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);
}
开发者ID:lionelc,项目名称:rstudio,代码行数:49,代码来源:SessionFiles.cpp
示例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);
}
开发者ID:howarthjw,项目名称:rstudio,代码行数:25,代码来源:SessionFiles.cpp
示例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);
}
开发者ID:seugerry,项目名称:rstudio,代码行数:8,代码来源:Response.cpp
示例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());
}
开发者ID:ivochkin,项目名称:dfk,代码行数:8,代码来源:fileserver.cpp
示例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");
}
开发者ID:,项目名称:,代码行数:10,代码来源:
示例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
}
开发者ID:AsamQi,项目名称:libsourcey,代码行数:20,代码来源:websocket.cpp
示例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());
}
}
开发者ID:AlexanderKotliar,项目名称:wt,代码行数:12,代码来源:WRestResource.C
示例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);
}
}
开发者ID:starius,项目名称:wt-classes,代码行数:39,代码来源:EtagStore.cpp
示例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;
}
开发者ID:fabianschuiki,项目名称:Auris,代码行数:39,代码来源:HTTP.cpp
示例16: deliver
void Server::deliver(http::Request& req) {
/*
google::protobuf::io::OstreamOutputStream out(&std::cerr);
google::protobuf::TextFormat::Print(req_, &out);
std::cout << "done\n";
*/
wire::Message msg;
msg.set_destination("/harq-http");
msg.set_payload(req.SerializeAsString());
queue_->write(msg);
}
开发者ID:evanphx,项目名称:harq-http,代码行数:13,代码来源:server.cpp
示例17: onRequest
void onRequest(http::Request &request)
{
std::string ext = ".html";
std::string &url = request.getUrl(); // Retrieve a reference to he url in the request
std::string extension = url.substr(url.size() - ext.size());
if (extension == ".html") // If the url ends in ".html"
{
std::string nUrl = url.substr(0, url.size() - ext.size());
nUrl += ".php";
url.assign(nUrl); // Update the url, our work here is done
}
}
开发者ID:zia-okapi,项目名称:zia-okapi,代码行数:14,代码来源:BasicRewrite.cpp
示例18: validateCSRFForm
bool validateCSRFForm(const http::Request& request,
http::Response* pResponse)
{
// extract token from HTTP cookie (set above)
std::string headerToken = request.cookieValue(kCSRFTokenName);
http::Fields fields;
// parse the form and check for a matching token
http::util::parseForm(request.body(), &fields);
std::string bodyToken = http::util::fieldValue<std::string>(fields,
kCSRFTokenName, "");
// report an error if they don't match
if (headerToken.empty() || bodyToken != headerToken)
{
pResponse->setStatusCode(http::status::BadRequest);
pResponse->setBody("Missing or incorrect token.");
return false;
}
// all is well
return true;
}
开发者ID:rlugojr,项目名称:rstudio,代码行数:23,代码来源:ServerCSRFToken.cpp
示例19: handleContentRequest
void handleContentRequest(const http::Request& request, http::Response* pResponse)
{
// get content file info
std::string title;
FilePath contentFilePath;
Error error = contentFileInfo(request.uri(), &title, &contentFilePath);
if (error)
{
pResponse->setError(error);
return;
}
// set private cache forever headers
pResponse->setPrivateCacheForeverHeaders();
// set file
pResponse->setFile(contentFilePath, request);
bool isUtf8 = true;
if (boost::algorithm::starts_with(contentFilePath.mimeContentType(), "text/"))
{
// If the content looks like valid UTF-8, assume it is. Otherwise, assume
// it's the system encoding.
std::string contents;
error = core::readStringFromFile(contentFilePath, &contents);
if (!error)
{
for (std::string::iterator pos = contents.begin(); pos != contents.end(); )
{
error = string_utils::utf8Advance(pos, 1, contents.end(), &pos);
if (error)
{
isUtf8 = false;
break;
}
}
}
}
// reset content-type with charset
pResponse->setContentType(contentFilePath.mimeContentType() +
std::string("; charset=") +
(isUtf8 ? "UTF-8" : ::locale2charset(NULL)));
// set title header
pResponse->setHeader("Title", title);
}
开发者ID:kiwiroy,项目名称:rstudio,代码行数:47,代码来源:SessionContentUrls.cpp
示例20: handleRequest
void gdTVPdfResource::handleRequest(const Http::Request& request, Http::Response& response)
{
// is not a continuation for more data of a previous request
if ( !request.continuation() ) {
if ( !m_pTV ) return;
std::string strPdf = gdWApp->getUserTmpFile("pdf");
fprintf(stderr, "construction du wtree2pdf\n");
gdViewToPdf* cPdf = new gdViewToPdf(strPdf.c_str(), m_pTV, 0, m_l1row);
if ( !cPdf->m_pPdf ) return;
fprintf(stderr, "Impression de la page\n");
cPdf->printPdfPage(1, 1, 0);
delete cPdf;
setFileName(strPdf);
}
WFileResource::handleRequest(request, response);
// this was the last data for the request
if ( !response.continuation() )
unlink(fileName().c_str());
}
开发者ID:Wittyshare,项目名称:gdwtcore,代码行数:19,代码来源:gdTreeViewPdfRes.cpp
注:本文中的http::Request类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论