описал интерфейсную часть аутентификации, пока оставил без реализации
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
|
||||
|
||||
namespace http::server {
|
||||
using request_handler = std::function<void(const Request &req, reply &rep)>;
|
||||
using request_handler = std::function<void(const Request &req, Reply &rep)>;
|
||||
|
||||
class ConnectionManager;
|
||||
/// Represents a single Connection from a client. Base class
|
||||
@@ -71,7 +71,7 @@ namespace http::server {
|
||||
RequestParser request_parser_;
|
||||
|
||||
/// The reply to be sent back to the client.
|
||||
reply reply_;
|
||||
Reply reply_;
|
||||
};
|
||||
|
||||
class SslConnection final : public ConnectionBase, public std::enable_shared_from_this<SslConnection> {
|
||||
@@ -113,7 +113,7 @@ namespace http::server {
|
||||
RequestParser request_parser_;
|
||||
|
||||
/// The reply to be sent back to the client.
|
||||
reply reply_;
|
||||
Reply reply_;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<ConnectionBase> connection_ptr;
|
||||
|
@@ -68,7 +68,7 @@ namespace http::server {
|
||||
const char crlf[] = {'\r', '\n'};
|
||||
} // namespace misc_strings
|
||||
|
||||
std::vector<boost::asio::const_buffer> reply::to_buffers() const {
|
||||
std::vector<boost::asio::const_buffer> Reply::to_buffers() const {
|
||||
std::vector<boost::asio::const_buffer> buffers;
|
||||
buffers.push_back(status_strings::to_buffer(status));
|
||||
for (const auto & h : headers) {
|
||||
@@ -206,7 +206,7 @@ namespace http::server {
|
||||
}
|
||||
} // namespace stock_replies
|
||||
|
||||
void stockReply(status_type status, reply& rep) {
|
||||
void stockReply(status_type status, Reply& rep) {
|
||||
rep.status = status;
|
||||
rep.headers.clear();
|
||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::text_html)});
|
||||
|
@@ -28,7 +28,7 @@ namespace http::server {
|
||||
};
|
||||
|
||||
/// A reply to be sent to a client.
|
||||
struct reply {
|
||||
struct Reply {
|
||||
status_type status;
|
||||
|
||||
/// The headers to be included in the reply.
|
||||
@@ -44,7 +44,7 @@ namespace http::server {
|
||||
};
|
||||
|
||||
/// Get a stock reply.
|
||||
void stockReply(status_type status, reply& rep);
|
||||
void stockReply(status_type status, Reply& rep);
|
||||
|
||||
} // namespace http::Server
|
||||
|
||||
|
@@ -30,7 +30,7 @@ http::resource::StaticFileResource::StaticFileResource(const std::string &path,
|
||||
#endif
|
||||
}
|
||||
|
||||
void http::resource::StaticFileResource::handle(const server::Request &req, server::reply &rep) {
|
||||
void http::resource::StaticFileResource::handle(const server::Request &req, server::Reply &rep) {
|
||||
if (req.method != "GET") {
|
||||
stockReply(server::bad_request, rep);
|
||||
return;
|
||||
@@ -56,7 +56,7 @@ http::resource::GenericResource::GenericResource(const std::string &path, const
|
||||
this->path = path;
|
||||
}
|
||||
|
||||
void http::resource::GenericResource::handle(const server::Request &req, server::reply &rep) {
|
||||
void http::resource::GenericResource::handle(const server::Request &req, server::Reply &rep) {
|
||||
this->generator_(req, rep);
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,7 @@ namespace http::resource {
|
||||
public:
|
||||
std::string path;
|
||||
|
||||
virtual void handle(const server::Request &req, server::reply &rep) = 0;
|
||||
virtual void handle(const server::Request &req, server::Reply &rep) = 0;
|
||||
|
||||
virtual ~BasicResource() = default;
|
||||
};
|
||||
@@ -34,12 +34,12 @@ namespace http::resource {
|
||||
public:
|
||||
StaticFileResource(const std::string& path, const std::string& filePath, server::mime_types::Mime type);
|
||||
|
||||
void handle(const server::Request &req, server::reply &rep) override;
|
||||
void handle(const server::Request &req, server::Reply &rep) override;
|
||||
|
||||
~StaticFileResource() override;
|
||||
};
|
||||
|
||||
using respGenerator = std::function<void(const server::Request &req, server::reply &rep)>;
|
||||
using respGenerator = std::function<void(const server::Request &req, server::Reply &rep)>;
|
||||
|
||||
/**
|
||||
* Класс ресурса для POST-запросов
|
||||
@@ -51,7 +51,7 @@ namespace http::resource {
|
||||
public:
|
||||
GenericResource(const std::string& path, const respGenerator& generator);
|
||||
|
||||
void handle(const server::Request &req, server::reply &rep) override;
|
||||
void handle(const server::Request &req, server::Reply &rep) override;
|
||||
|
||||
~GenericResource() override;
|
||||
};
|
||||
|
@@ -111,7 +111,7 @@ namespace http::server {
|
||||
});
|
||||
}
|
||||
|
||||
void Server::requestHandler(const Request &req, reply &rep) {
|
||||
void Server::requestHandler(const Request &req, Reply &rep) {
|
||||
// Request path must be absolute and not contain "..".
|
||||
if (req.url->path.empty() || req.url->path[0] != '/' || req.url->path.find("..") != std::string::npos) {
|
||||
stockReply(bad_request, rep);
|
||||
|
@@ -74,7 +74,7 @@ namespace http::server {
|
||||
ConnectionManager connection_manager_;
|
||||
|
||||
/// Handle a request and produce a reply.
|
||||
void requestHandler(const Request &req, reply &rep);
|
||||
void requestHandler(const Request &req, Reply &rep);
|
||||
};
|
||||
} // namespace http::Server
|
||||
|
||||
|
Reference in New Issue
Block a user