mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-05-06 17:51:36 +02:00
Work on fixing compile.
This commit is contained in:
parent
647694b576
commit
7d000bb5b5
@ -68,6 +68,8 @@ env_base.use_ptrcall = False
|
|||||||
env_base.module_version_string = ""
|
env_base.module_version_string = ""
|
||||||
env_base.msvc = False
|
env_base.msvc = False
|
||||||
|
|
||||||
|
env_base.ParseConfig("pkg-config uuid --cflags --libs")
|
||||||
|
|
||||||
# avoid issues when building with different versions of python out of the same directory
|
# avoid issues when building with different versions of python out of the same directory
|
||||||
env_base.SConsignFile(".sconsign{0}.dblite".format(pickle.HIGHEST_PROTOCOL))
|
env_base.SConsignFile(".sconsign{0}.dblite".format(pickle.HIGHEST_PROTOCOL))
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ int HttpFileImpl::save(const std::string &path) const
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto &uploadPath = HttpAppFrameworkImpl::instance().getUploadPath();
|
auto &uploadPath = Application::get_instance()->getUploadPath();
|
||||||
if (uploadPath[uploadPath.length() - 1] == '/')
|
if (uploadPath[uploadPath.length() - 1] == '/')
|
||||||
tmpPath = uploadPath + path;
|
tmpPath = uploadPath + path;
|
||||||
else
|
else
|
||||||
@ -59,7 +59,7 @@ int HttpFileImpl::save(const std::string &path) const
|
|||||||
}
|
}
|
||||||
int HttpFileImpl::save() const
|
int HttpFileImpl::save() const
|
||||||
{
|
{
|
||||||
return save(HttpAppFrameworkImpl::instance().getUploadPath());
|
return save(Application::get_instance()->getUploadPath());
|
||||||
}
|
}
|
||||||
int HttpFileImpl::saveAs(const std::string &filename) const
|
int HttpFileImpl::saveAs(const std::string &filename) const
|
||||||
{
|
{
|
||||||
@ -74,7 +74,7 @@ int HttpFileImpl::saveAs(const std::string &filename) const
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto &uploadPath = HttpAppFrameworkImpl::instance().getUploadPath();
|
auto &uploadPath = Application::get_instance()->getUploadPath();
|
||||||
if (uploadPath[uploadPath.length() - 1] == '/')
|
if (uploadPath[uploadPath.length() - 1] == '/')
|
||||||
pathAndFileName = uploadPath + filename;
|
pathAndFileName = uploadPath + filename;
|
||||||
else
|
else
|
||||||
|
@ -251,7 +251,7 @@ void Application::run() {
|
|||||||
// A fast database client instance should be created in the main event
|
// A fast database client instance should be created in the main event
|
||||||
// loop, so put the main loop into ioLoops.
|
// loop, so put the main loop into ioLoops.
|
||||||
|
|
||||||
ioLoops.push_back(get_loop());
|
//ioLoops.push_back(get_loop());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
dbClientManagerPtr_->createDbClients(ioLoops);
|
dbClientManagerPtr_->createDbClients(ioLoops);
|
||||||
|
@ -15,8 +15,11 @@
|
|||||||
|
|
||||||
#include "core/http_server_callbacks.h"
|
#include "core/http_server_callbacks.h"
|
||||||
|
|
||||||
|
#include "core/listener_manager.h"
|
||||||
|
|
||||||
|
using namespace drogon;
|
||||||
|
|
||||||
class Request;
|
class Request;
|
||||||
class ListenerManager;
|
|
||||||
|
|
||||||
class Application {
|
class Application {
|
||||||
public:
|
public:
|
||||||
@ -54,6 +57,50 @@ public:
|
|||||||
|
|
||||||
std::unique_ptr<ListenerManager> listenerManagerPtr_;
|
std::unique_ptr<ListenerManager> listenerManagerPtr_;
|
||||||
|
|
||||||
|
size_t getClientMaxBodySize() const {
|
||||||
|
return clientMaxBodySize_;
|
||||||
|
}
|
||||||
|
size_t getClientMaxMemoryBodySize() const {
|
||||||
|
return clientMaxMemoryBodySize_;
|
||||||
|
}
|
||||||
|
size_t getClientMaxWebSocketMessageSize() const {
|
||||||
|
return clientMaxWebSocketMessageSize_;
|
||||||
|
}
|
||||||
|
size_t keepaliveRequestsNumber() const {
|
||||||
|
return keepaliveRequestsNumber_;
|
||||||
|
}
|
||||||
|
size_t pipeliningRequestsNumber() const {
|
||||||
|
return pipeliningRequestsNumber_;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sendDateHeader() const {
|
||||||
|
return enableDateHeader_;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sendServerHeader() const {
|
||||||
|
return enableServerHeader_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &getServerHeaderString() const {
|
||||||
|
return serverHeader_;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual const std::string &getUploadPath() const {
|
||||||
|
return uploadPath_;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual size_t getCurrentThreadIndex() const {
|
||||||
|
auto *loop = trantor::EventLoop::getEventLoopOfCurrentThread();
|
||||||
|
if (loop) {
|
||||||
|
return loop->index();
|
||||||
|
}
|
||||||
|
#ifdef _WIN32
|
||||||
|
return size_t(-1);
|
||||||
|
#else
|
||||||
|
return std::numeric_limits<size_t>::max();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static HandlerInstance index_func;
|
static HandlerInstance index_func;
|
||||||
static std::map<std::string, HandlerInstance> main_route_map;
|
static std::map<std::string, HandlerInstance> main_route_map;
|
||||||
@ -71,6 +118,16 @@ public:
|
|||||||
private:
|
private:
|
||||||
static Application *_instance;
|
static Application *_instance;
|
||||||
bool _running;
|
bool _running;
|
||||||
|
|
||||||
|
size_t clientMaxBodySize_{ 1024 * 1024 };
|
||||||
|
size_t clientMaxMemoryBodySize_{ 64 * 1024 };
|
||||||
|
size_t clientMaxWebSocketMessageSize_{ 128 * 1024 };
|
||||||
|
size_t keepaliveRequestsNumber_{ 0 };
|
||||||
|
size_t pipeliningRequestsNumber_{ 0 };
|
||||||
|
std::string uploadPath_;
|
||||||
|
bool enableServerHeader_{ false };
|
||||||
|
std::string serverHeader_{ "Server: rcpp_cms\r\n" };
|
||||||
|
bool enableDateHeader_{ true };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -648,7 +648,7 @@ HttpRequest::~HttpRequest()
|
|||||||
|
|
||||||
void HttpRequest::reserveBodySize(size_t length)
|
void HttpRequest::reserveBodySize(size_t length)
|
||||||
{
|
{
|
||||||
if (length <= HttpAppFrameworkImpl::instance().getClientMaxMemoryBodySize())
|
if (length <= Application::get_instance()->getClientMaxMemoryBodySize())
|
||||||
{
|
{
|
||||||
content_.reserve(length);
|
content_.reserve(length);
|
||||||
}
|
}
|
||||||
@ -668,7 +668,7 @@ void HttpRequest::appendToBody(const char *data, size_t length)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (content_.length() + length <=
|
if (content_.length() + length <=
|
||||||
HttpAppFrameworkImpl::instance().getClientMaxMemoryBodySize())
|
Application::get_instance()->getClientMaxMemoryBodySize())
|
||||||
{
|
{
|
||||||
content_.append(data, length);
|
content_.append(data, length);
|
||||||
}
|
}
|
||||||
@ -685,7 +685,7 @@ void HttpRequest::appendToBody(const char *data, size_t length)
|
|||||||
void HttpRequest::createTmpFile()
|
void HttpRequest::createTmpFile()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
auto tmpfile = HttpAppFrameworkImpl::instance().getUploadPath();
|
auto tmpfile = Application::get_instance()->getUploadPath();
|
||||||
|
|
||||||
|
|
||||||
auto fileName = utils::getUuid();
|
auto fileName = utils::getUuid();
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace drogon {
|
namespace drogon {
|
||||||
|
|
||||||
class HttpRequest;
|
class HttpRequest;
|
||||||
using HttpRequestPtr = std::shared_ptr<HttpRequest>;
|
using HttpRequestPtr = std::shared_ptr<HttpRequest>;
|
||||||
|
|
||||||
@ -164,6 +165,8 @@ public:
|
|||||||
return fromRequest<T>(*this);
|
return fromRequest<T>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool setMethod(const char *start, const char *end);
|
||||||
|
|
||||||
/// Return the method string of the request, such as GET, POST, etc.
|
/// Return the method string of the request, such as GET, POST, etc.
|
||||||
virtual const char *methodString() const;
|
virtual const char *methodString() const;
|
||||||
const char *getMethodString() const {
|
const char *getMethodString() const {
|
||||||
|
@ -14,8 +14,10 @@
|
|||||||
|
|
||||||
#include "core/http_request_parser.h"
|
#include "core/http_request_parser.h"
|
||||||
|
|
||||||
|
//#include "core/http_server_callbacks.h"
|
||||||
|
|
||||||
#include "core/http_response.h"
|
#include "core/http_response.h"
|
||||||
#include "http_request.h"
|
#include "core/http_request.h"
|
||||||
#include "core/http_utils.h"
|
#include "core/http_utils.h"
|
||||||
#include <core/http_types.h>
|
#include <core/http_types.h>
|
||||||
|
|
||||||
@ -23,6 +25,8 @@
|
|||||||
#include <trantor/utils/Logger.h>
|
#include <trantor/utils/Logger.h>
|
||||||
#include <trantor/utils/MsgBuffer.h>
|
#include <trantor/utils/MsgBuffer.h>
|
||||||
|
|
||||||
|
#include "core/application.h"
|
||||||
|
|
||||||
using namespace trantor;
|
using namespace trantor;
|
||||||
using namespace drogon;
|
using namespace drogon;
|
||||||
|
|
||||||
@ -83,10 +87,10 @@ bool HttpRequestParser::processRequestLine(const char *begin, const char *end)
|
|||||||
}
|
}
|
||||||
return succeed;
|
return succeed;
|
||||||
}
|
}
|
||||||
HttpRequestPtr HttpRequestParser::makeRequestForPool(HttpRequestImpl *ptr)
|
HttpRequestPtr HttpRequestParser::makeRequestForPool(HttpRequest *ptr)
|
||||||
{
|
{
|
||||||
std::weak_ptr<HttpRequestParser> weakPtr = shared_from_this();
|
std::weak_ptr<HttpRequestParser> weakPtr = shared_from_this();
|
||||||
return std::shared_ptr<HttpRequestImpl>(ptr, [weakPtr](HttpRequestImpl *p) {
|
return std::shared_ptr<HttpRequest>(ptr, [weakPtr](HttpRequest *p) {
|
||||||
auto thisPtr = weakPtr.lock();
|
auto thisPtr = weakPtr.lock();
|
||||||
if (thisPtr)
|
if (thisPtr)
|
||||||
{
|
{
|
||||||
@ -118,7 +122,7 @@ void HttpRequestParser::reset()
|
|||||||
status_ = HttpRequestParseStatus::kExpectMethod;
|
status_ = HttpRequestParseStatus::kExpectMethod;
|
||||||
if (requestsPool_.empty())
|
if (requestsPool_.empty())
|
||||||
{
|
{
|
||||||
request_ = makeRequestForPool(new HttpRequestImpl(loop_));
|
request_ = makeRequestForPool(new HttpRequest(loop_));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -264,13 +268,11 @@ bool HttpRequestParser::parseRequest(MsgBuffer *buf)
|
|||||||
if (connPtr)
|
if (connPtr)
|
||||||
{
|
{
|
||||||
auto resp = HttpResponse::newHttpResponse();
|
auto resp = HttpResponse::newHttpResponse();
|
||||||
if (currentContentLength_ >
|
if (currentContentLength_ > Application::get_instance()->getClientMaxBodySize())
|
||||||
HttpAppFrameworkImpl::instance()
|
|
||||||
.getClientMaxBodySize())
|
|
||||||
{
|
{
|
||||||
resp->setStatusCode(k413RequestEntityTooLarge);
|
resp->setStatusCode(k413RequestEntityTooLarge);
|
||||||
auto httpString =
|
auto httpString =
|
||||||
static_cast<HttpResponseImpl *>(resp.get())
|
static_cast<HttpResponse *>(resp.get())
|
||||||
->renderToBuffer();
|
->renderToBuffer();
|
||||||
reset();
|
reset();
|
||||||
connPtr->send(std::move(*httpString));
|
connPtr->send(std::move(*httpString));
|
||||||
@ -279,7 +281,7 @@ bool HttpRequestParser::parseRequest(MsgBuffer *buf)
|
|||||||
{
|
{
|
||||||
resp->setStatusCode(k100Continue);
|
resp->setStatusCode(k100Continue);
|
||||||
auto httpString =
|
auto httpString =
|
||||||
static_cast<HttpResponseImpl *>(resp.get())
|
static_cast<HttpResponse *>(resp.get())
|
||||||
->renderToBuffer();
|
->renderToBuffer();
|
||||||
connPtr->send(std::move(*httpString));
|
connPtr->send(std::move(*httpString));
|
||||||
}
|
}
|
||||||
@ -297,9 +299,7 @@ bool HttpRequestParser::parseRequest(MsgBuffer *buf)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (currentContentLength_ >
|
else if (currentContentLength_ > Application::get_instance()->getClientMaxBodySize())
|
||||||
HttpAppFrameworkImpl::instance()
|
|
||||||
.getClientMaxBodySize())
|
|
||||||
{
|
{
|
||||||
buf->retrieveAll();
|
buf->retrieveAll();
|
||||||
shutdownConnection(k413RequestEntityTooLarge);
|
shutdownConnection(k413RequestEntityTooLarge);
|
||||||
@ -365,8 +365,7 @@ bool HttpRequestParser::parseRequest(MsgBuffer *buf)
|
|||||||
// responsePtr_->currentChunkLength_;
|
// responsePtr_->currentChunkLength_;
|
||||||
if (currentChunkLength_ != 0)
|
if (currentChunkLength_ != 0)
|
||||||
{
|
{
|
||||||
if (currentChunkLength_ + currentContentLength_ >
|
if (currentChunkLength_ + currentContentLength_ > Application::get_instance()->getClientMaxBodySize())
|
||||||
HttpAppFrameworkImpl::instance().getClientMaxBodySize())
|
|
||||||
{
|
{
|
||||||
buf->retrieveAll();
|
buf->retrieveAll();
|
||||||
shutdownConnection(k413RequestEntityTooLarge);
|
shutdownConnection(k413RequestEntityTooLarge);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -22,7 +22,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
#include "core/http_utils.h"
|
#include "core/http_utils.h"
|
||||||
|
|
||||||
#include "http_message_body.h"
|
#include "http_message_body.h"
|
||||||
@ -38,12 +37,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
|
||||||
namespace drogon {
|
namespace drogon {
|
||||||
/// Abstract class for webapp developer to get or set the Http response;
|
/// Abstract class for webapp developer to get or set the Http response;
|
||||||
class HttpResponse;
|
class HttpResponse;
|
||||||
using HttpResponsePtr = std::shared_ptr<HttpResponse>;
|
using HttpResponsePtr = std::shared_ptr<HttpResponse>;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This template is used to convert a response object to a custom
|
* @brief This template is used to convert a response object to a custom
|
||||||
* type object. Users must specialize the template for a particular type.
|
* type object. Users must specialize the template for a particular type.
|
||||||
@ -77,7 +76,8 @@ inline HttpResponsePtr toResponse<Json::Value &>(Json::Value &pJson) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class HttpResponse {
|
class HttpResponse {
|
||||||
friend class HttpResponseParser;
|
friend class HttpResponseParser;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief This template enables automatic type conversion. For using this
|
* @brief This template enables automatic type conversion. For using this
|
||||||
@ -105,7 +105,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the status code such as 200, 404
|
/// Get the status code such as 200, 404
|
||||||
virtual HttpStatusCode statusCode() const {
|
virtual HttpStatusCode statusCode() const {
|
||||||
return statusCode_;
|
return statusCode_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,13 +114,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the status code of the response.
|
/// Set the status code of the response.
|
||||||
virtual void setStatusCode(HttpStatusCode code) {
|
virtual void setStatusCode(HttpStatusCode code) {
|
||||||
statusCode_ = code;
|
statusCode_ = code;
|
||||||
setStatusMessage(statusCodeToString(code));
|
setStatusMessage(statusCodeToString(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the creation timestamp of the response.
|
/// Get the creation timestamp of the response.
|
||||||
virtual const trantor::Date &creationDate() const {
|
virtual const trantor::Date &creationDate() const {
|
||||||
return creationDate_;
|
return creationDate_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the http version, http1.0 or http1.1
|
/// Set the http version, http1.0 or http1.1
|
||||||
virtual void setVersion(const Version v) {
|
virtual void setVersion(const Version v) {
|
||||||
version_ = v;
|
version_ = v;
|
||||||
if (version_ == Version::kHttp10) {
|
if (version_ == Version::kHttp10) {
|
||||||
closeConnection_ = true;
|
closeConnection_ = true;
|
||||||
@ -143,26 +143,25 @@ public:
|
|||||||
* is closed immediately after sending the last byte of the response. It's
|
* is closed immediately after sending the last byte of the response. It's
|
||||||
* false by default when the response is created.
|
* false by default when the response is created.
|
||||||
*/
|
*/
|
||||||
virtual void setCloseConnection(bool on) {
|
virtual void setCloseConnection(bool on) {
|
||||||
closeConnection_ = on;
|
closeConnection_ = on;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the status set by the setCloseConnetion() method.
|
/// Get the status set by the setCloseConnetion() method.
|
||||||
|
|
||||||
virtual bool ifCloseConnection() const {
|
virtual bool ifCloseConnection() const {
|
||||||
return closeConnection_;
|
return closeConnection_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the response content type, such as text/html, text/plaint, image/png
|
/// Set the response content type, such as text/html, text/plaint, image/png
|
||||||
/// and so on. If the content type
|
/// and so on. If the content type
|
||||||
/// is a text type, the character set is utf8.
|
/// is a text type, the character set is utf8.
|
||||||
virtual void setContentTypeCode(ContentType type) {
|
virtual void setContentTypeCode(ContentType type) {
|
||||||
contentType_ = type;
|
contentType_ = type;
|
||||||
setContentType(webContentTypeToString(type));
|
setContentType(webContentTypeToString(type));
|
||||||
flagForParsingContentType_ = true;
|
flagForParsingContentType_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Set the response content type and the content-type string, The string
|
/// Set the response content type and the content-type string, The string
|
||||||
/// must contain the header name and CRLF.
|
/// must contain the header name and CRLF.
|
||||||
/// For example, "content-type: text/plain\r\n"
|
/// For example, "content-type: text/plain\r\n"
|
||||||
@ -183,8 +182,17 @@ public:
|
|||||||
/// virtual void setContentTypeCodeAndCharacterSet(ContentType type, const
|
/// virtual void setContentTypeCodeAndCharacterSet(ContentType type, const
|
||||||
/// std::string &charSet = "utf-8") = 0;
|
/// std::string &charSet = "utf-8") = 0;
|
||||||
|
|
||||||
|
const std::string &getHeaderBy(const std::string &lowerKey) const {
|
||||||
|
const static std::string defaultVal;
|
||||||
|
auto iter = headers_.find(lowerKey);
|
||||||
|
if (iter == headers_.end()) {
|
||||||
|
return defaultVal;
|
||||||
|
}
|
||||||
|
return iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the response content type.
|
/// Get the response content type.
|
||||||
virtual ContentType contentType() const {
|
virtual ContentType contentType() const {
|
||||||
if (!flagForParsingContentType_) {
|
if (!flagForParsingContentType_) {
|
||||||
flagForParsingContentType_ = true;
|
flagForParsingContentType_ = true;
|
||||||
auto &contentTypeString = getHeaderBy("content-type");
|
auto &contentTypeString = getHeaderBy("content-type");
|
||||||
@ -208,44 +216,32 @@ public:
|
|||||||
return contentType();
|
return contentType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::string &getHeaderBy(const std::string &lowerKey) const {
|
|
||||||
const static std::string defaultVal;
|
|
||||||
auto iter = headers_.find(lowerKey);
|
|
||||||
if (iter == headers_.end()) {
|
|
||||||
return defaultVal;
|
|
||||||
}
|
|
||||||
return iter->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Get the header string identified by the key parameter.
|
/// Get the header string identified by the key parameter.
|
||||||
/**
|
/**
|
||||||
* @note
|
* @note
|
||||||
* If there is no the header, a empty string is retured.
|
* If there is no the header, a empty string is retured.
|
||||||
* The key is case insensitive
|
* The key is case insensitive
|
||||||
*/
|
*/
|
||||||
virtual const std::string &getHeader(const std::string &key) const {
|
virtual const std::string &getHeader(const std::string &key) const {
|
||||||
auto field = key;
|
auto field = key;
|
||||||
transform(field.begin(), field.end(), field.begin(), ::tolower);
|
transform(field.begin(), field.end(), field.begin(), ::tolower);
|
||||||
return getHeaderBy(field);
|
return getHeaderBy(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const std::string &getHeader(std::string &&key) const {
|
virtual const std::string &getHeader(std::string &&key) const {
|
||||||
transform(key.begin(), key.end(), key.begin(), ::tolower);
|
transform(key.begin(), key.end(), key.begin(), ::tolower);
|
||||||
return getHeaderBy(key);
|
return getHeaderBy(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Remove the header identified by the key parameter.
|
/// Remove the header identified by the key parameter.
|
||||||
virtual void removeHeader(const std::string &key) {
|
virtual void removeHeader(const std::string &key) {
|
||||||
auto field = key;
|
auto field = key;
|
||||||
transform(field.begin(), field.end(), field.begin(), ::tolower);
|
transform(field.begin(), field.end(), field.begin(), ::tolower);
|
||||||
removeHeaderBy(field);
|
removeHeaderBy(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove the header identified by the key parameter.
|
/// Remove the header identified by the key parameter.
|
||||||
virtual void removeHeader(std::string &&key) {
|
virtual void removeHeader(std::string &&key) {
|
||||||
transform(key.begin(), key.end(), key.begin(), ::tolower);
|
transform(key.begin(), key.end(), key.begin(), ::tolower);
|
||||||
removeHeaderBy(key);
|
removeHeaderBy(key);
|
||||||
}
|
}
|
||||||
@ -254,10 +250,9 @@ public:
|
|||||||
headers_.erase(lowerKey);
|
headers_.erase(lowerKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Get all headers of the response
|
/// Get all headers of the response
|
||||||
virtual const std::unordered_map<std::string, std::string> &headers()
|
virtual const std::unordered_map<std::string, std::string> &headers()
|
||||||
const {
|
const {
|
||||||
return headers_;
|
return headers_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,7 +263,7 @@ public:
|
|||||||
|
|
||||||
/// Add a header.
|
/// Add a header.
|
||||||
virtual void addHeader(const std::string &key,
|
virtual void addHeader(const std::string &key,
|
||||||
const std::string &value) {
|
const std::string &value) {
|
||||||
fullHeaderString_.reset();
|
fullHeaderString_.reset();
|
||||||
auto field = key;
|
auto field = key;
|
||||||
transform(field.begin(), field.end(), field.begin(), ::tolower);
|
transform(field.begin(), field.end(), field.begin(), ::tolower);
|
||||||
@ -276,33 +271,33 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Add a header.
|
/// Add a header.
|
||||||
virtual void addHeader(const std::string &key, std::string &&value) {
|
virtual void addHeader(const std::string &key, std::string &&value) {
|
||||||
fullHeaderString_.reset();
|
fullHeaderString_.reset();
|
||||||
auto field = key;
|
auto field = key;
|
||||||
transform(field.begin(), field.end(), field.begin(), ::tolower);
|
transform(field.begin(), field.end(), field.begin(), ::tolower);
|
||||||
headers_[std::move(field)] = std::move(value);
|
headers_[std::move(field)] = std::move(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addHeader(const char *start, const char *colon, const char *end);
|
void addHeader(const char *start, const char *colon, const char *end);
|
||||||
|
|
||||||
/// Add a cookie
|
/// Add a cookie
|
||||||
virtual void addCookie(const std::string &key,
|
virtual void addCookie(const std::string &key,
|
||||||
const std::string &value) {
|
const std::string &value) {
|
||||||
cookies_[key] = Cookie(key, value);
|
cookies_[key] = Cookie(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a cookie
|
/// Add a cookie
|
||||||
virtual void addCookie(const Cookie &cookie) {
|
virtual void addCookie(const Cookie &cookie) {
|
||||||
cookies_[cookie.key()] = cookie;
|
cookies_[cookie.key()] = cookie;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void addCookie(Cookie &&cookie) {
|
virtual void addCookie(Cookie &&cookie) {
|
||||||
cookies_[cookie.key()] = std::move(cookie);
|
cookies_[cookie.key()] = std::move(cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the cookie identified by the key parameter.
|
/// Get the cookie identified by the key parameter.
|
||||||
/// If there is no the cookie, the empty cookie is retured.
|
/// If there is no the cookie, the empty cookie is retured.
|
||||||
virtual const Cookie &getCookie(const std::string &key) const {
|
virtual const Cookie &getCookie(const std::string &key) const {
|
||||||
static const Cookie defaultCookie;
|
static const Cookie defaultCookie;
|
||||||
auto it = cookies_.find(key);
|
auto it = cookies_.find(key);
|
||||||
if (it != cookies_.end()) {
|
if (it != cookies_.end()) {
|
||||||
@ -313,7 +308,7 @@ public:
|
|||||||
|
|
||||||
/// Get all cookies.
|
/// Get all cookies.
|
||||||
virtual const std::unordered_map<std::string, Cookie> &cookies()
|
virtual const std::unordered_map<std::string, Cookie> &cookies()
|
||||||
const {
|
const {
|
||||||
return cookies_;
|
return cookies_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,7 +318,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Remove the cookie identified by the key parameter.
|
/// Remove the cookie identified by the key parameter.
|
||||||
virtual void removeCookie(const std::string &key) {
|
virtual void removeCookie(const std::string &key) {
|
||||||
cookies_.erase(key);
|
cookies_.erase(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,11 +326,11 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @note The body must match the content type
|
* @note The body must match the content type
|
||||||
*/
|
*/
|
||||||
virtual void setBody(const std::string &body) {
|
virtual void setBody(const std::string &body) {
|
||||||
bodyPtr_ = std::make_shared<HttpMessageStringBody>(body);
|
bodyPtr_ = std::make_shared<HttpMessageStringBody>(body);
|
||||||
}
|
}
|
||||||
/// Set the response body(content).
|
/// Set the response body(content).
|
||||||
virtual void setBody(std::string &&body) {
|
virtual void setBody(std::string &&body) {
|
||||||
bodyPtr_ = std::make_shared<HttpMessageStringBody>(std::move(body));
|
bodyPtr_ = std::make_shared<HttpMessageStringBody>(std::move(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,7 +356,7 @@ public:
|
|||||||
* kHttp10 means Http version is 1.0
|
* kHttp10 means Http version is 1.0
|
||||||
* kHttp11 means Http verison is 1.1
|
* kHttp11 means Http verison is 1.1
|
||||||
*/
|
*/
|
||||||
virtual Version version() const {
|
virtual Version version() const {
|
||||||
return version_;
|
return version_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,7 +371,7 @@ public:
|
|||||||
/// Set the expiration time of the response cache in memory.
|
/// Set the expiration time of the response cache in memory.
|
||||||
/// in seconds, 0 means always cache, negative means not cache, default is
|
/// in seconds, 0 means always cache, negative means not cache, default is
|
||||||
/// -1.
|
/// -1.
|
||||||
virtual void setExpiredTime(ssize_t expiredTime) {
|
virtual void setExpiredTime(ssize_t expiredTime) {
|
||||||
expriedTime_ = expiredTime;
|
expriedTime_ = expiredTime;
|
||||||
datePos_ = std::string::npos;
|
datePos_ = std::string::npos;
|
||||||
if (expriedTime_ < 0 && version_ == Version::kHttp10) {
|
if (expriedTime_ < 0 && version_ == Version::kHttp10) {
|
||||||
@ -384,9 +379,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Get the expiration time of the response.
|
/// Get the expiration time of the response.
|
||||||
virtual ssize_t expiredTime() const {
|
virtual ssize_t expiredTime() const {
|
||||||
return expriedTime_;
|
return expriedTime_;
|
||||||
}
|
}
|
||||||
ssize_t getExpiredTime() const {
|
ssize_t getExpiredTime() const {
|
||||||
@ -396,7 +390,7 @@ public:
|
|||||||
/// Get the json object from the server response.
|
/// Get the json object from the server response.
|
||||||
/// If the response is not in json format, then a empty shared_ptr is
|
/// If the response is not in json format, then a empty shared_ptr is
|
||||||
/// retured.
|
/// retured.
|
||||||
virtual const std::shared_ptr<Json::Value> &jsonObject() const {
|
virtual const std::shared_ptr<Json::Value> &jsonObject() const {
|
||||||
// Not multi-thread safe but good, because we basically call this
|
// Not multi-thread safe but good, because we basically call this
|
||||||
// function in a single thread
|
// function in a single thread
|
||||||
if (!flagForParsingJson_) {
|
if (!flagForParsingJson_) {
|
||||||
@ -409,7 +403,6 @@ public:
|
|||||||
return jsonObject();
|
return jsonObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void setJsonObject(const Json::Value &pJson) {
|
void setJsonObject(const Json::Value &pJson) {
|
||||||
flagForParsingJson_ = true;
|
flagForParsingJson_ = true;
|
||||||
flagForSerializingJson_ = false;
|
flagForSerializingJson_ = false;
|
||||||
@ -454,8 +447,6 @@ public:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the error message of parsing the JSON body received from peer.
|
* @brief Get the error message of parsing the JSON body received from peer.
|
||||||
* This method usually is called after getting a empty shared_ptr object
|
* This method usually is called after getting a empty shared_ptr object
|
||||||
@ -464,7 +455,7 @@ public:
|
|||||||
* @return const std::string& The error message. An empty string is returned
|
* @return const std::string& The error message. An empty string is returned
|
||||||
* when no error occurs.
|
* when no error occurs.
|
||||||
*/
|
*/
|
||||||
virtual const std::string &getJsonError() const {
|
virtual const std::string &getJsonError() const {
|
||||||
const static std::string none{ "" };
|
const static std::string none{ "" };
|
||||||
if (jsonParsingErrorPtr_)
|
if (jsonParsingErrorPtr_)
|
||||||
return *jsonParsingErrorPtr_;
|
return *jsonParsingErrorPtr_;
|
||||||
@ -480,20 +471,18 @@ public:
|
|||||||
*
|
*
|
||||||
* @param flag
|
* @param flag
|
||||||
*/
|
*/
|
||||||
virtual void setPassThrough(bool flag) {
|
virtual void setPassThrough(bool flag) {
|
||||||
passThrough_ = flag;
|
passThrough_ = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void redirect(const std::string &url) {
|
void redirect(const std::string &url) {
|
||||||
headers_["location"] = url;
|
headers_["location"] = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<trantor::MsgBuffer> renderToBuffer();
|
std::shared_ptr<trantor::MsgBuffer> renderToBuffer();
|
||||||
void renderToBuffer(trantor::MsgBuffer &buffer);
|
void renderToBuffer(trantor::MsgBuffer &buffer);
|
||||||
std::shared_ptr<trantor::MsgBuffer> renderHeaderForHeadMethod();
|
std::shared_ptr<trantor::MsgBuffer> renderHeaderForHeadMethod();
|
||||||
|
|
||||||
|
|
||||||
/* The following methods are a series of factory methods that help users
|
/* The following methods are a series of factory methods that help users
|
||||||
* create response objects. */
|
* create response objects. */
|
||||||
|
|
||||||
@ -564,25 +553,23 @@ public:
|
|||||||
|
|
||||||
virtual ~HttpResponse();
|
virtual ~HttpResponse();
|
||||||
|
|
||||||
|
|
||||||
// virtual void setContentTypeCodeAndCharacterSet(ContentType type, const
|
// virtual void setContentTypeCodeAndCharacterSet(ContentType type, const
|
||||||
// std::string &charSet = "utf-8")
|
// std::string &charSet = "utf-8")
|
||||||
// {
|
// {
|
||||||
// contentType_ = type;
|
// contentType_ = type;
|
||||||
// setContentType(webContentTypeAndCharsetToString(type, charSet));
|
// setContentType(webContentTypeAndCharsetToString(type, charSet));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void swap(HttpResponse &that) noexcept;
|
void swap(HttpResponse &that) noexcept;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void makeHeaderString(trantor::MsgBuffer &headerString);
|
void makeHeaderString(trantor::MsgBuffer &headerString);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void setBody(const char *body, size_t len) {
|
virtual void setBody(const char *body, size_t len) {
|
||||||
bodyPtr_ = std::make_shared<HttpMessageStringViewBody>(body, len);
|
bodyPtr_ = std::make_shared<HttpMessageStringViewBody>(body, len);
|
||||||
}
|
}
|
||||||
virtual const char *getBodyData() const {
|
virtual const char *getBodyData() const {
|
||||||
if (!flagForSerializingJson_ && jsonPtr_) {
|
if (!flagForSerializingJson_ && jsonPtr_) {
|
||||||
generateBodyFromJson();
|
generateBodyFromJson();
|
||||||
} else if (!bodyPtr_) {
|
} else if (!bodyPtr_) {
|
||||||
@ -591,25 +578,23 @@ private:
|
|||||||
return bodyPtr_->data();
|
return bodyPtr_->data();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t getBodyLength() const {
|
virtual size_t getBodyLength() const {
|
||||||
if (bodyPtr_)
|
if (bodyPtr_)
|
||||||
return bodyPtr_->length();
|
return bodyPtr_->length();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void parseJson() const;
|
void parseJson() const;
|
||||||
|
|
||||||
virtual void setContentTypeCodeAndCustomString(
|
virtual void setContentTypeCodeAndCustomString(
|
||||||
ContentType type,
|
ContentType type,
|
||||||
const char *typeString,
|
const char *typeString,
|
||||||
size_t typeStringLength) {
|
size_t typeStringLength) {
|
||||||
contentType_ = type;
|
contentType_ = type;
|
||||||
flagForParsingContentType_ = true;
|
flagForParsingContentType_ = true;
|
||||||
setContentType(string_view{ typeString, typeStringLength });
|
setContentType(string_view{ typeString, typeStringLength });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::unordered_map<std::string, std::string> headers_;
|
std::unordered_map<std::string, std::string> headers_;
|
||||||
std::unordered_map<std::string, Cookie> cookies_;
|
std::unordered_map<std::string, Cookie> cookies_;
|
||||||
|
|
||||||
@ -643,7 +628,6 @@ private:
|
|||||||
void setStatusMessage(const string_view &message) {
|
void setStatusMessage(const string_view &message) {
|
||||||
statusMessage_ = message;
|
statusMessage_ = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
@ -15,7 +15,7 @@ void HTTPServer::http_callback_handler(Request *request) {
|
|||||||
Application::handle_request(request);
|
Application::handle_request(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPServer::httpEnterCallbackDefault(const HTTPParser &httpParser, const HttpSession::Ptr &session) {
|
void HTTPServer::httpEnterCallbackDefault(const brynet::net::http::HTTPParser &httpParser, const brynet::net::http::HttpSession::Ptr &session) {
|
||||||
Request *request = RequestPool::get_request();
|
Request *request = RequestPool::get_request();
|
||||||
|
|
||||||
request->http_parser = &httpParser;
|
request->http_parser = &httpParser;
|
||||||
@ -30,7 +30,7 @@ void HTTPServer::httpEnterCallbackDefault(const HTTPParser &httpParser, const Ht
|
|||||||
http_callback_handler(request);
|
http_callback_handler(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPServer::wsEnterCallbackDefault(const HttpSession::Ptr &httpSession, WebSocketFormat::WebSocketFrameType opcode, const std::string &payload) {
|
void HTTPServer::wsEnterCallbackDefault(const brynet::net::http::HttpSession::Ptr &httpSession, brynet::net::http::WebSocketFormat::WebSocketFrameType opcode, const std::string &payload) {
|
||||||
|
|
||||||
std::cout << "frame enter of type:" << int(opcode) << std::endl;
|
std::cout << "frame enter of type:" << int(opcode) << std::endl;
|
||||||
std::cout << "payload is:" << payload << std::endl;
|
std::cout << "payload is:" << payload << std::endl;
|
||||||
@ -51,7 +51,7 @@ void HTTPServer::initialize_old() {
|
|||||||
|
|
||||||
configure_old();
|
configure_old();
|
||||||
|
|
||||||
service = TcpService::Create();
|
service = brynet::net::TcpService::Create();
|
||||||
service->startWorkerThread(threads);
|
service->startWorkerThread(threads);
|
||||||
|
|
||||||
int p_port = port;
|
int p_port = port;
|
||||||
@ -60,22 +60,22 @@ void HTTPServer::initialize_old() {
|
|||||||
if (listenBuilder)
|
if (listenBuilder)
|
||||||
delete listenBuilder;
|
delete listenBuilder;
|
||||||
|
|
||||||
listenBuilder = new wrapper::HttpListenerBuilder();
|
listenBuilder = new brynet::net::wrapper::HttpListenerBuilder();
|
||||||
listenBuilder->configureService(service);
|
listenBuilder->configureService(service);
|
||||||
|
|
||||||
listenBuilder->configureSocketOptions({
|
listenBuilder->configureSocketOptions({
|
||||||
[](TcpSocket &socket) {
|
[](brynet::net::TcpSocket &socket) {
|
||||||
socket.setNodelay();
|
socket.setNodelay();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
listenBuilder->configureConnectionOptions({ AddSocketOption::WithMaxRecvBufferSize(1024) });
|
listenBuilder->configureConnectionOptions({ brynet::net::AddSocketOption::WithMaxRecvBufferSize(1024) });
|
||||||
|
|
||||||
listenBuilder->configureListen([p_port](wrapper::BuildListenConfig builder) {
|
listenBuilder->configureListen([p_port](brynet::net::wrapper::BuildListenConfig builder) {
|
||||||
builder.setAddr(false, "0.0.0.0", p_port);
|
builder.setAddr(false, "0.0.0.0", p_port);
|
||||||
});
|
});
|
||||||
|
|
||||||
listenBuilder->configureEnterCallback([](const HttpSession::Ptr &httpSession, HttpSessionHandlers &handlers) {
|
listenBuilder->configureEnterCallback([](const brynet::net::http::HttpSession::Ptr &httpSession, brynet::net::http::HttpSessionHandlers &handlers) {
|
||||||
handlers.setHttpCallback(HTTPServer::httpEnterCallbackDefault);
|
handlers.setHttpCallback(HTTPServer::httpEnterCallbackDefault);
|
||||||
handlers.setWSCallback(HTTPServer::wsEnterCallbackDefault);
|
handlers.setWSCallback(HTTPServer::wsEnterCallbackDefault);
|
||||||
});
|
});
|
||||||
@ -203,13 +203,14 @@ void HTTPServer::main_loop() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Create all listeners.
|
// Create all listeners.
|
||||||
|
/*
|
||||||
auto ioLoops = listenerManagerPtr_->createListeners(
|
auto ioLoops = listenerManagerPtr_->createListeners(
|
||||||
std::bind(&HttpAppFrameworkImpl::onAsyncRequest, this, _1, _2),
|
std::bind(&Application::onAsyncRequest, this, _1, _2),
|
||||||
std::bind(&HttpAppFrameworkImpl::onNewWebsockRequest, this, _1, _2, _3),
|
std::bind(&Application::onNewWebsockRequest, this, _1, _2, _3),
|
||||||
std::bind(&HttpAppFrameworkImpl::onConnection, this, _1),
|
std::bind(&Application::onConnection, this, _1),
|
||||||
idleConnectionTimeout_,
|
Application::get_instance()->idleConnectionTimeout_,
|
||||||
sslCertPath_,
|
Application::get_instance()->sslCertPath_,
|
||||||
sslKeyPath_,
|
Application::get_instance()->sslKeyPath_,
|
||||||
threads,
|
threads,
|
||||||
syncAdvices_);
|
syncAdvices_);
|
||||||
|
|
||||||
@ -221,11 +222,11 @@ void HTTPServer::main_loop() {
|
|||||||
|
|
||||||
|
|
||||||
getLoop()->setIndex(threads);
|
getLoop()->setIndex(threads);
|
||||||
|
*/
|
||||||
// A fast database client instance should be created in the main event
|
// A fast database client instance should be created in the main event
|
||||||
// loop, so put the main loop into ioLoops.
|
// loop, so put the main loop into ioLoops.
|
||||||
|
|
||||||
ioLoops.push_back(getLoop());
|
//ioLoops.push_back(getLoop());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
dbClientManagerPtr_->createDbClients(ioLoops);
|
dbClientManagerPtr_->createDbClients(ioLoops);
|
||||||
@ -235,7 +236,8 @@ void HTTPServer::main_loop() {
|
|||||||
websockCtrlsRouterPtr_->init();
|
websockCtrlsRouterPtr_->init();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
getLoop()->queueInLoop([this]() {
|
/*
|
||||||
|
get_loop()->queueInLoop([this]() {
|
||||||
// Let listener event loops run when everything is ready.
|
// Let listener event loops run when everything is ready.
|
||||||
listenerManagerPtr_->startListening();
|
listenerManagerPtr_->startListening();
|
||||||
|
|
||||||
@ -245,14 +247,8 @@ void HTTPServer::main_loop() {
|
|||||||
|
|
||||||
beginningAdvices_.clear();
|
beginningAdvices_.clear();
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
getLoop()->loop();
|
get_loop()->loop();
|
||||||
}
|
|
||||||
|
|
||||||
trantor::EventLoop *HttpAppFrameworkImpl::get_loop() const
|
|
||||||
{
|
|
||||||
static trantor::EventLoop loop;
|
|
||||||
return &loop;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPServer::HTTPServer() {
|
HTTPServer::HTTPServer() {
|
||||||
|
@ -16,12 +16,14 @@
|
|||||||
#include <trantor/net/callbacks.h>
|
#include <trantor/net/callbacks.h>
|
||||||
#include <trantor/utils/NonCopyable.h>
|
#include <trantor/utils/NonCopyable.h>
|
||||||
|
|
||||||
#include "core/http_server_callbacks.h"
|
|
||||||
#include "core/http_request_parser.h"
|
#include "core/http_request_parser.h"
|
||||||
|
#include "core/http_server_callbacks.h"
|
||||||
|
|
||||||
using namespace brynet;
|
//using namespace brynet;
|
||||||
using namespace brynet::net;
|
//using namespace brynet::net;
|
||||||
using namespace brynet::net::http;
|
//using namespace brynet::net::http;
|
||||||
|
|
||||||
|
using namespace drogon;
|
||||||
|
|
||||||
class Request;
|
class Request;
|
||||||
|
|
||||||
@ -29,13 +31,13 @@ class HTTPServer {
|
|||||||
public:
|
public:
|
||||||
int port;
|
int port;
|
||||||
int threads;
|
int threads;
|
||||||
std::shared_ptr<TcpService> service;
|
std::shared_ptr<brynet::net::TcpService> service;
|
||||||
wrapper::HttpListenerBuilder *listenBuilder;
|
brynet::net::wrapper::HttpListenerBuilder *listenBuilder;
|
||||||
|
|
||||||
static void http_callback_handler(Request *response);
|
static void http_callback_handler(Request *response);
|
||||||
|
|
||||||
static void httpEnterCallbackDefault(const HTTPParser &httpParser, const HttpSession::Ptr &session);
|
static void httpEnterCallbackDefault(const brynet::net::http::HTTPParser &httpParser, const brynet::net::http::HttpSession::Ptr &session);
|
||||||
static void wsEnterCallbackDefault(const HttpSession::Ptr &httpSession, WebSocketFormat::WebSocketFrameType opcode, const std::string &payload);
|
static void wsEnterCallbackDefault(const brynet::net::http::HttpSession::Ptr &httpSession, brynet::net::http::WebSocketFormat::WebSocketFrameType opcode, const std::string &payload);
|
||||||
|
|
||||||
virtual void configure_old();
|
virtual void configure_old();
|
||||||
virtual void initialize_old();
|
virtual void initialize_old();
|
||||||
@ -47,7 +49,7 @@ public:
|
|||||||
|
|
||||||
void main_loop();
|
void main_loop();
|
||||||
|
|
||||||
trantor::EventLoop *getLoop() const {
|
trantor::EventLoop *get_loop() const {
|
||||||
return server_.getLoop();
|
return server_.getLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +104,7 @@ protected:
|
|||||||
WebSocketNewAsyncCallback newWebsocketCallback_;
|
WebSocketNewAsyncCallback newWebsocketCallback_;
|
||||||
trantor::ConnectionCallback connectionCallback_;
|
trantor::ConnectionCallback connectionCallback_;
|
||||||
const std::vector<std::function<HttpResponsePtr(const HttpRequestPtr &)> > &syncAdvices_;
|
const std::vector<std::function<HttpResponsePtr(const HttpRequestPtr &)> > &syncAdvices_;
|
||||||
|
bool _running{ false };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
namespace drogon {
|
||||||
|
|
||||||
class HttpRequest;
|
class HttpRequest;
|
||||||
using HttpRequestPtr = std::shared_ptr<HttpRequest>;
|
using HttpRequestPtr = std::shared_ptr<HttpRequest>;
|
||||||
class HttpResponse;
|
class HttpResponse;
|
||||||
@ -16,4 +18,6 @@ using HttpAsyncCallback = std::function<void(const HttpRequestPtr &,std::functio
|
|||||||
using WebSocketNewAsyncCallback = std::function<void(const HttpRequestPtr &, std::function<void(const HttpResponsePtr &)> &&,
|
using WebSocketNewAsyncCallback = std::function<void(const HttpRequestPtr &, std::function<void(const HttpResponsePtr &)> &&,
|
||||||
const WebSocketConnectionPtr &)>;
|
const WebSocketConnectionPtr &)>;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -21,6 +21,8 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
#include "core/application.h"
|
||||||
|
|
||||||
namespace drogon
|
namespace drogon
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -68,7 +70,7 @@ class IOThreadStorage : public trantor::NonCopyable
|
|||||||
{
|
{
|
||||||
static_assert(std::is_constructible<C, Args &&...>::value,
|
static_assert(std::is_constructible<C, Args &&...>::value,
|
||||||
"Unable to construct storage with given signature");
|
"Unable to construct storage with given signature");
|
||||||
size_t numThreads = app().getThreadNum();
|
size_t numThreads = Application::get_instance()->threadNum_;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
assert(numThreads > 0 && numThreads != size_t(-1));
|
assert(numThreads > 0 && numThreads != size_t(-1));
|
||||||
#else
|
#else
|
||||||
@ -100,14 +102,14 @@ class IOThreadStorage : public trantor::NonCopyable
|
|||||||
*/
|
*/
|
||||||
inline ValueType &getThreadData()
|
inline ValueType &getThreadData()
|
||||||
{
|
{
|
||||||
size_t idx = app().getCurrentThreadIndex();
|
size_t idx = Application::get_instance()->getCurrentThreadIndex();
|
||||||
assert(idx < storage_.size());
|
assert(idx < storage_.size());
|
||||||
return storage_[idx];
|
return storage_[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const ValueType &getThreadData() const
|
inline const ValueType &getThreadData() const
|
||||||
{
|
{
|
||||||
size_t idx = app().getCurrentThreadIndex();
|
size_t idx = Application::get_instance()->getCurrentThreadIndex();
|
||||||
assert(idx < storage_.size());
|
assert(idx < storage_.size());
|
||||||
return storage_[idx];
|
return storage_[idx];
|
||||||
}
|
}
|
||||||
@ -119,21 +121,21 @@ class IOThreadStorage : public trantor::NonCopyable
|
|||||||
*/
|
*/
|
||||||
inline void setThreadData(const ValueType &newData)
|
inline void setThreadData(const ValueType &newData)
|
||||||
{
|
{
|
||||||
size_t idx = app().getCurrentThreadIndex();
|
size_t idx = Application::get_instance()->getCurrentThreadIndex();
|
||||||
assert(idx < storage_.size());
|
assert(idx < storage_.size());
|
||||||
storage_[idx] = newData;
|
storage_[idx] = newData;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setThreadData(ValueType &&newData)
|
inline void setThreadData(ValueType &&newData)
|
||||||
{
|
{
|
||||||
size_t idx = app().getCurrentThreadIndex();
|
size_t idx = Application::get_instance()->getCurrentThreadIndex();
|
||||||
assert(idx < storage_.size());
|
assert(idx < storage_.size());
|
||||||
storage_[idx] = std::move(newData);
|
storage_[idx] = std::move(newData);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ValueType *operator->()
|
inline ValueType *operator->()
|
||||||
{
|
{
|
||||||
size_t idx = app().getCurrentThreadIndex();
|
size_t idx = Application::get_instance()->getCurrentThreadIndex();
|
||||||
assert(idx < storage_.size());
|
assert(idx < storage_.size());
|
||||||
return &storage_[idx];
|
return &storage_[idx];
|
||||||
}
|
}
|
||||||
@ -145,7 +147,7 @@ class IOThreadStorage : public trantor::NonCopyable
|
|||||||
|
|
||||||
inline const ValueType *operator->() const
|
inline const ValueType *operator->() const
|
||||||
{
|
{
|
||||||
size_t idx = app().getCurrentThreadIndex();
|
size_t idx = Application::get_instance()->getCurrentThreadIndex();
|
||||||
assert(idx < storage_.size());
|
assert(idx < storage_.size());
|
||||||
return &storage_[idx];
|
return &storage_[idx];
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <trantor/utils/Logger.h>
|
#include <trantor/utils/Logger.h>
|
||||||
|
|
||||||
|
#include "core/application.h"
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@ -83,7 +85,7 @@ std::vector<trantor::EventLoop *> ListenerManager::createListeners(
|
|||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
DrogonFileLocker lock;
|
DrogonFileLocker lock;
|
||||||
// Check whether the port is in use.
|
// Check whether the port is in use.
|
||||||
TcpServer server(HttpAppFrameworkImpl::instance().getLoop(),
|
TcpServer server(Application::get_instance()->get_loop(),
|
||||||
InetAddress(ip, listener.port_, isIpv6),
|
InetAddress(ip, listener.port_, isIpv6),
|
||||||
"drogonPortTest",
|
"drogonPortTest",
|
||||||
true,
|
true,
|
||||||
@ -118,12 +120,13 @@ std::vector<trantor::EventLoop *> ListenerManager::createListeners(
|
|||||||
serverPtr->enableSSL(cert, key);
|
serverPtr->enableSSL(cert, key);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
serverPtr->setHttpAsyncCallback(httpCallback);
|
serverPtr->setHttpAsyncCallback(httpCallback);
|
||||||
serverPtr->setNewWebsocketCallback(webSocketCallback);
|
serverPtr->setNewWebsocketCallback(webSocketCallback);
|
||||||
serverPtr->setConnectionCallback(connectionCallback);
|
serverPtr->setConnectionCallback(connectionCallback);
|
||||||
serverPtr->kickoffIdleConnections(connectionTimeout);
|
serverPtr->kickoffIdleConnections(connectionTimeout);
|
||||||
serverPtr->start();
|
serverPtr->start();
|
||||||
|
*/
|
||||||
servers_.push_back(serverPtr);
|
servers_.push_back(serverPtr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,7 +210,7 @@ trantor::EventLoop *ListenerManager::getIOLoop(size_t id) const {
|
|||||||
|
|
||||||
void ListenerManager::stopListening() {
|
void ListenerManager::stopListening() {
|
||||||
for (auto &serverPtr : servers_) {
|
for (auto &serverPtr : servers_) {
|
||||||
serverPtr->stop();
|
//serverPtr->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto loop : ioLoops_) {
|
for (auto loop : ioLoops_) {
|
||||||
|
@ -51,7 +51,7 @@ void Request::send() {
|
|||||||
|
|
||||||
std::string result = response->getResult();
|
std::string result = response->getResult();
|
||||||
|
|
||||||
const HttpSession::Ptr lsession = (*session);
|
const brynet::net::http::HttpSession::Ptr lsession = (*session);
|
||||||
|
|
||||||
(*session)->send(result.c_str(), result.size(), [lsession]() { lsession->postShutdown(); });
|
(*session)->send(result.c_str(), result.size(), [lsession]() { lsession->postShutdown(); });
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ void Request::send_file(const std::string &p_file_path) {
|
|||||||
|
|
||||||
response->addHeadValue("Connection", "Close");
|
response->addHeadValue("Connection", "Close");
|
||||||
std::string result = "HTTP/1.1 200 OK\r\nConnection: Close\r\n\r\n";
|
std::string result = "HTTP/1.1 200 OK\r\nConnection: Close\r\n\r\n";
|
||||||
const HttpSession::Ptr lsession = (*session);
|
const brynet::net::http::HttpSession::Ptr lsession = (*session);
|
||||||
|
|
||||||
(*session)->send(result.c_str(), result.size(), [this]() { this->_progress_send_file(); });
|
(*session)->send(result.c_str(), result.size(), [this]() { this->_progress_send_file(); });
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ void Request::reset() {
|
|||||||
if (response)
|
if (response)
|
||||||
delete response;
|
delete response;
|
||||||
|
|
||||||
response = new HttpResponse();
|
response = new brynet::net::http::HttpResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Request::setup_url_stack() {
|
void Request::setup_url_stack() {
|
||||||
@ -186,7 +186,7 @@ Request::~Request() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Request::_progress_send_file() {
|
void Request::_progress_send_file() {
|
||||||
const HttpSession::Ptr lsession = (*session);
|
const brynet::net::http::HttpSession::Ptr lsession = (*session);
|
||||||
|
|
||||||
if (current_file_progress >= file_size) {
|
if (current_file_progress >= file_size) {
|
||||||
lsession->postShutdown();
|
lsession->postShutdown();
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <core/Utilities.h>
|
#include <core/utilities.h>
|
||||||
#include <trantor/utils/Logger.h>
|
#include <trantor/utils/Logger.h>
|
||||||
|
|
||||||
#ifdef OpenSSL_FOUND
|
#ifdef OpenSSL_FOUND
|
||||||
|
@ -6,9 +6,10 @@ env.core_sources = []
|
|||||||
|
|
||||||
#env.add_source_files(env.core_sources, "*.cpp")
|
#env.add_source_files(env.core_sources, "*.cpp")
|
||||||
|
|
||||||
env.add_source_files(env.core_sources, "./trantor/net/*.cc")
|
|
||||||
env.add_source_files(env.core_sources, "./trantor/net/inner/*.cc")
|
|
||||||
env.add_source_files(env.core_sources, "./trantor/net/inner/poller/*.cc")
|
env.add_source_files(env.core_sources, "./trantor/net/inner/poller/*.cc")
|
||||||
|
env.add_source_files(env.core_sources, "./trantor/net/inner/*.cc")
|
||||||
|
env.add_source_files(env.core_sources, "./trantor/net/*.cc")
|
||||||
|
|
||||||
|
|
||||||
env.core_sources.append("./trantor/utils/AsyncFileLogger.cc")
|
env.core_sources.append("./trantor/utils/AsyncFileLogger.cc")
|
||||||
env.core_sources.append("./trantor/utils/ConcurrentTaskQueue.cc")
|
env.core_sources.append("./trantor/utils/ConcurrentTaskQueue.cc")
|
||||||
|
@ -50,6 +50,7 @@ class TcpServer : NonCopyable
|
|||||||
const std::string &name,
|
const std::string &name,
|
||||||
bool reUseAddr = true,
|
bool reUseAddr = true,
|
||||||
bool reUsePort = true);
|
bool reUsePort = true);
|
||||||
|
TcpServer() {}
|
||||||
~TcpServer();
|
~TcpServer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user