Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    HadiAbbasi
    @HadiAbbasi
    Hi there...
    I don't know Am I right or not!
    But I can't define a controller (handler) for empty path!
    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});
    and there is no any drogon action on root request like:
    http://mysite.com/
    Clément Gamé 🧠
    @WintermeW_twitter
    Hi, i have a little question regarding Filters and the request object ref passed as parameter: I implemented an authentication filter that is properly working except one thing: Whenever i try to inject some user claims in the request (userId, profile_type etc..) with the help of req->setParameter(param_name,value) for later use in my controllers, the other query params seem added by the user in the URL seem to disappear. Am i doing something wrong ? What is the correct way for a filter to inject data in the request for later reuse by the controllers ?
    Clément Gamé 🧠
    @WintermeW_twitter
    (note that i'd rather keep the auth mechanism sessionless)
    An Tao
    @an-tao
    @WintermeW_twitter you could use the attributes of a request object to do that.
    image.png
    Clément Gamé 🧠
    @WintermeW_twitter
    @an-tao ok great, thank you
    HadiAbbasi
    @HadiAbbasi
    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
    Maurice Barnett
    @r3cebarnett
    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?
    It looks like drogon::app() returns a singleton and I can't find a way to reset it. I also tried to create my own instance of an HttpAppFramework object using newbut it seg faults upon deletion.
    An Tao
    @an-tao

    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.

    3 replies

    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().

    An Tao
    @an-tao
    34bb5dfa8eb48d33aaa91c2f603bf30.jpg
    @HadiAbbasi You don't need to define a route for an empty path as it is equivalent to "/"
    3 replies
    1111mp
    @1111mp
    image.png
    When I customize the filter, the lambda function passes the fccb execution causing the program to crash
    image.png
    Assertion failed: (idx < storage_.size()), function getThreadData, file IOThreadStorage.h, line 100.
    can someone help me
    please
    thank you very much
    1111mp
    @1111mp
    Probably know the reason, here you need to use the synchronous execCommandSync method.
    An Tao
    @an-tao
    you should use the fast redis client to ensure that the storage is accessed in IO threads (not in the thread used by redis client)
    jamal rashidi
    @jamalrashidi1_twitter

    hello
    I have a problem with Trantor on Windows compiled with MSVC 2017 x64. I got the below error when running a simple TCP server using Trantor :

    ERROR SO_REUSEPORT is not supported.

    An Tao
    @an-tao
        TcpServer(EventLoop *loop,
                  const InetAddress &address,
                  const std::string &name,
                  bool reUseAddr = true,
                  bool reUsePort = true);
    you can set the last parameter to false
    5 replies
    Okami チム
    @okami.mks:matrix.org
    [m]
    installing vcpkg was a struggle, XD
    demenkovms
    @demenkovms

    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

    An Tao
    @an-tao
    did you re-cmake your project after adding this controller?
    demenkovms
    @demenkovms
    yes, of course )
    aliakbarrashidi
    @aliakbarrashidi:matrix.org
    [m]

    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.)

    An Tao
    @an-tao
    Did you set the log_level to TRACE?
    3 replies
    jamal rashidi
    @jamalrashidi1_twitter
    Is it possible to have nested drogon::HttpFilter for a request?
    I want some requests go through multiple HttpFilters.
    An Tao
    @an-tao
    ADD_METHOD_TO(Ctrl::handleSome, "/path/to/handler", "filter1","filter2","filter3");
    jamal rashidi
    @jamalrashidi1_twitter
    Thanks

    ADD_METHOD_TO(Ctrl::handleSome, "/path/to/handler", "filter1","filter2","filter3");

    It is possible with METHOD_ADD to chain filters?

    An Tao
    @an-tao
    yes
    jamal rashidi
    @jamalrashidi1_twitter
    Thanks again
    Ghasem Ramezani
    @another-ghasem
    Hi, Why the CMake files(like DrogonUtilities.cmake) are explicitly removed in the Conan recipe? How could I use functions like drogon_create_views?
    Hiderr
    @Hiderrr
    Hello, I've got a little question regarding drogon's framework usage.
    Is there any recommended way of handling HTTP requests' authorization? (Is it maybe possible to allow filters to take parameters such as an Array of required permissions? (enum values e.g.))
    Rafael Bugajewski
    @rbugajewski
    thylacinelol
    @thylacinelol
    Hi
    Is it possible to automatically route paths to static html files?
    For example, make http://localhost:3000/hello serve http://localhost:3000/hello.html if the html file exists?
    P.R.
    @prothegee

    @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
    @thylacinelol
    @prothegee yep, serving files works fine - I can access the page via domain.tld[:port]/hello.html, however, I want to remove the .html, so that you can access the filehello.html via domain.tld[:port]/hello.
    P.R.
    @prothegee

    @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);
    }
    image.png
    I didn't know that was doable till now, LOL
    P.R.
    @prothegee
    Otherwise I didn't know yet for another solution
    P.R.
    @prothegee
    image.png
    thylacinelol
    @thylacinelol
    woah nice, thanks!