ADD_METHOD_TO(PageCtrl::RootRout,"",{Get , Post , Put , Patch , Delete , Head});
ADD_METHOD_TO(PageCtrl::RootRout,"/",{Get , Post , Put , Patch , Delete , Head});
METHOD_ADD(PageCtrl::RootRout,"",{Get , Post , Put , Patch , Delete , Head});
METHOD_ADD(PageCtrl::RootRout,"/",{Get , Post , Put , Patch , Delete , Head});
new
but it seg faults upon deletion.
Hi @an-tao
Is it possible to remove or change content-length or content-type of response as we need to test the caching of our cnd (made by nginx)?
In other words, I need to check the caching of my CDN for the while that there is no any cache-length on response headers and the origin server is drogon as there is no any limitation on (add/edit/remove headers on) it!
removeHeader method was not able to remove content-length!
I know that removing some headers like Content-Length can be dangerous but is there any solution for my problem?
All The Best,
Hadi
currently you can't do that, you need to change drogon code to achieve that.
Apologies if this has already been answered somewhere. If I wanted to do a soft restart (without killing the parent process) of an application using Drogon, how might I cleanly resume Drogon?
There is no API of drogon to do that, you have to change drogon code to achieve that. please refer to the run() method of drogon::app().
Hello. I create controller by command: drogon_ctl create controller PingController:
PingController.h:
#pragma once
#include <drogon/HttpSimpleController.h>
using namespace drogon;
class PingController : public drogon::HttpSimpleController<PingController>
{
public:
virtual void asyncHandleHttpRequest(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback) override;
PATH_LIST_BEGIN
PATH_ADD("/PING", Get);
PATH_LIST_END
};
PingController.c:
#include "PingController.h"
void PingController::asyncHandleHttpRequest(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback)
{
// write your application logic here
auto resp = HttpResponse::newHttpResponse();
resp->setStatusCode(k200OK);
resp->setContentTypeCode(CT_TEXT_HTML);
resp->setBody("PONG");
callback(resp);
}
but when I try to call http://localhost/PING i get 404 Not Found
LOG_TRACE << "log body";
I desire above line results a line in the log file but it doesn't.
why?
( I have set the log option correctly and I run the app in the Debug mode and others log have written to log file properly.)
ADD_METHOD_TO(Ctrl::handleSome, "/path/to/handler", "filter1","filter2","filter3");
It is possible with METHOD_ADD to chain filters?
@thylacinelol
if you configure document_root directory and add *.html files, public can access it,
even if it's located on document_root
/docs/how-to-x.html
this is also equilevant as domain.tld[:port-if-any]/docs/how-to-y.html
open this https://drogon.org/images/drogon-concise-white.png and look https://github.com/drogonframework/drogon-website/tree/master/content/images
@thylacinelol
something like this doable with c++20
Home.h
namespace MyProject
{
namespace controllers
{
class Home
: public drogon::HttpController<Home>
{
public:
METHOD_LIST_BEGIN
ADD_METHOD_TO(Home::HomePage, "/", drogon::Get);
ADD_METHOD_TO(Home::HelloPage, "/hello", drogon::Get);
METHOD_LIST_END
void HomePage(const drogon::HttpRequestPtr &req,
std::function<void(const drogon::HttpResponsePtr&)>&&callback);
drogon::AsyncTask HelloPage(const drogon::HttpRequestPtr req,
std::function<void(const drogon::HttpResponsePtr&)>callback);
}; // class Home
} // namespace controllers
} // namespace MyProject
Home.cc
#include "Home.h"
using namespace backendV1::controllers;
void Home::HomePage(const drogon::HttpRequestPtr &req,
std::function<void(const drogon::HttpResponsePtr&)>&&callback)
{
// ... some logic
}
drogon::AsyncTask Home::HelloPage(const drogon::HttpRequestPtr req,
std::function<void(const drogon::HttpResponsePtr&)>callback)
{
auto client = drogon::HttpClient::newHttpClient("http://www.localhost.com:8001");
auto request = drogon::HttpRequest::newHttpRequest();
request->setMethod(drogon::Get);
request->setPath("/hello.html");
auto foo = co_await client->sendRequestCoro(request);
auto bar = foo->getBody();
std::string baz{bar};
resp = drogon::HttpResponse::newHttpResponse();
resp->setBody(baz);
callback(resp);
}