Start listening after beginning advices (#1147)
This commit is contained in:
parent
e81662f29b
commit
68b2a46a29
|
@ -584,13 +584,13 @@ void HttpAppFrameworkImpl::run()
|
||||||
staticFileRouterPtr_->init(ioLoops);
|
staticFileRouterPtr_->init(ioLoops);
|
||||||
websockCtrlsRouterPtr_->init();
|
websockCtrlsRouterPtr_->init();
|
||||||
getLoop()->queueInLoop([this]() {
|
getLoop()->queueInLoop([this]() {
|
||||||
// Let listener event loops run when everything is ready.
|
|
||||||
listenerManagerPtr_->startListening();
|
|
||||||
for (auto &adv : beginningAdvices_)
|
for (auto &adv : beginningAdvices_)
|
||||||
{
|
{
|
||||||
adv();
|
adv();
|
||||||
}
|
}
|
||||||
beginningAdvices_.clear();
|
beginningAdvices_.clear();
|
||||||
|
// Let listener event loops run when everything is ready.
|
||||||
|
listenerManagerPtr_->startListening();
|
||||||
});
|
});
|
||||||
getLoop()->loop();
|
getLoop()->loop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ set(INTEGRATION_TEST_SERVER_SOURCES
|
||||||
integration_test/server/DigestAuthFilter.cc
|
integration_test/server/DigestAuthFilter.cc
|
||||||
integration_test/server/MethodTest.cc
|
integration_test/server/MethodTest.cc
|
||||||
integration_test/server/RangeTestController.cc
|
integration_test/server/RangeTestController.cc
|
||||||
|
integration_test/server/BeginAdviceTest.cc
|
||||||
integration_test/server/main.cc)
|
integration_test/server/main.cc)
|
||||||
|
|
||||||
if(DROGON_CXX_STANDARD GREATER_EQUAL 20 AND HAS_COROUTINE)
|
if(DROGON_CXX_STANDARD GREATER_EQUAL 20 AND HAS_COROUTINE)
|
||||||
|
|
|
@ -66,9 +66,20 @@ void doTest(const HttpClientPtr &client, std::shared_ptr<test::Case> TEST_CTX)
|
||||||
else
|
else
|
||||||
client->addCookie(sessionID);
|
client->addCookie(sessionID);
|
||||||
|
|
||||||
/// Test session
|
/// Test begin advice
|
||||||
auto req = HttpRequest::newHttpRequest();
|
auto req = HttpRequest::newHttpRequest();
|
||||||
req->setMethod(drogon::Get);
|
req->setMethod(drogon::Get);
|
||||||
|
req->setPath("/test_begin_advice");
|
||||||
|
client->sendRequest(req,
|
||||||
|
[req, client, TEST_CTX](ReqResult result,
|
||||||
|
const HttpResponsePtr &resp) {
|
||||||
|
REQUIRE(result == ReqResult::Ok);
|
||||||
|
CHECK(resp->getBody() == "DrogonReady");
|
||||||
|
});
|
||||||
|
|
||||||
|
/// Test session
|
||||||
|
req = HttpRequest::newHttpRequest();
|
||||||
|
req->setMethod(drogon::Get);
|
||||||
req->setPath("/slow");
|
req->setPath("/slow");
|
||||||
client->sendRequest(
|
client->sendRequest(
|
||||||
req,
|
req,
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
#include "BeginAdviceTest.h"
|
||||||
|
|
||||||
|
std::string BeginAdviceTest::content_ = "Default content";
|
||||||
|
|
||||||
|
void BeginAdviceTest::asyncHandleHttpRequest(
|
||||||
|
const HttpRequestPtr &req,
|
||||||
|
std::function<void(const HttpResponsePtr &)> &&callback)
|
||||||
|
{
|
||||||
|
auto resp = HttpResponse::newHttpResponse();
|
||||||
|
resp->setBody(content_);
|
||||||
|
callback(resp);
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
#pragma once
|
||||||
|
#include <drogon/HttpSimpleController.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace drogon;
|
||||||
|
|
||||||
|
class BeginAdviceTest : public drogon::HttpSimpleController<BeginAdviceTest>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void asyncHandleHttpRequest(
|
||||||
|
const HttpRequestPtr &req,
|
||||||
|
std::function<void(const HttpResponsePtr &)> &&callback) override;
|
||||||
|
PATH_LIST_BEGIN
|
||||||
|
// list path definations here;
|
||||||
|
// PATH_ADD("/path","filter1","filter2",...);
|
||||||
|
PATH_ADD("/test_begin_advice", Get);
|
||||||
|
PATH_LIST_END
|
||||||
|
BeginAdviceTest()
|
||||||
|
{
|
||||||
|
LOG_DEBUG << "BeginAdviceTest constructor";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setContent(const std::string &content)
|
||||||
|
{
|
||||||
|
content_ = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static std::string content_;
|
||||||
|
};
|
|
@ -1,11 +1,13 @@
|
||||||
|
|
||||||
|
#include "BeginAdviceTest.h"
|
||||||
#include "CustomCtrl.h"
|
#include "CustomCtrl.h"
|
||||||
#include "CustomHeaderFilter.h"
|
#include "CustomHeaderFilter.h"
|
||||||
#include "DigestAuthFilter.h"
|
#include "DigestAuthFilter.h"
|
||||||
|
|
||||||
#include <drogon/drogon.h>
|
#include <drogon/drogon.h>
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
using namespace drogon;
|
using namespace drogon;
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
@ -367,5 +369,9 @@ int main()
|
||||||
<< std::string{drogon::utils::getHttpFullDate(
|
<< std::string{drogon::utils::getHttpFullDate(
|
||||||
trantor::Date::now())}
|
trantor::Date::now())}
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
|
app().registerBeginningAdvice(
|
||||||
|
[]() { BeginAdviceTest::setContent("DrogonReady"); });
|
||||||
|
|
||||||
app().run();
|
app().run();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue