Merge request handler to server; add FileBody for serving static files.

This commit is contained in:
Chunting Gu
2019-07-12 16:05:01 +08:00
parent 91590b8ee8
commit 8b85248a34
12 changed files with 493 additions and 470 deletions
+11 -12
View File
@@ -5,7 +5,7 @@
#include <string>
#include <vector>
#include "boost/asio/ip/tcp.hpp" // for ip::tcp::socket
#include "boost/asio/ip/tcp.hpp"
#include "webcc/globals.h"
#include "webcc/request.h"
@@ -14,16 +14,13 @@
namespace webcc {
class Connection;
class ConnectionPool;
class RequestHandler;
using ConnectionPtr = std::shared_ptr<Connection>;
class Server;
class Connection : public std::enable_shared_from_this<Connection> {
public:
Connection(boost::asio::ip::tcp::socket socket, ConnectionPool* pool,
RequestHandler* handler);
Server* server);
~Connection() = default;
@@ -40,10 +37,10 @@ public:
// Close the socket.
void Close();
// Send response to client.
// Send a response to the client.
void SendResponse(ResponsePtr response);
// TODO: Remove
// Send a response with the given status and an empty body to the client.
void SendResponse(Status status);
private:
@@ -60,17 +57,17 @@ private:
// Shutdown the socket.
void Shutdown();
// Socket for the connection.
// The socket for the connection.
boost::asio::ip::tcp::socket socket_;
// The pool for this connection.
ConnectionPool* pool_;
// Buffer for incoming data.
// The buffer for incoming data.
std::vector<char> buffer_;
// The handler used to process the incoming request.
RequestHandler* request_handler_;
// The server.
Server* server_;
// The incoming request.
RequestPtr request_;
@@ -82,6 +79,8 @@ private:
ResponsePtr response_;
};
using ConnectionPtr = std::shared_ptr<Connection>;
} // namespace webcc
#endif // WEBCC_CONNECTION_H_