Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drogon::app().forward(...) does not perform URL escaping #2013

Open
Mis1eader-dev opened this issue Apr 25, 2024 · 2 comments
Open

drogon::app().forward(...) does not perform URL escaping #2013

Mis1eader-dev opened this issue Apr 25, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@Mis1eader-dev
Copy link
Member

Mis1eader-dev commented Apr 25, 2024

Describe the bug
Forwarding requests that contain spaces in the URL all fail to be resolved on the forwarded party.
After manually replacing spaces with their escaped equivalences it worked.

string path = req->path();
replaceAll(path, " ", "%20");
req->setPath(std::move(path));
drogon::app().forward(std::move(req), std::move(callback), host);

Solution
Perform URL escaping on the path before forwarding.

Alternative Solution
Have it use req->getOriginalPath() instead of req->path()

req->setPath(req->getOriginalPath());
drogon::app().forward(std::move(req), std::move(callback), host);
@Mis1eader-dev Mis1eader-dev added the bug Something isn't working label Apr 25, 2024
@ladaniprem
Copy link

#include <drogon/drogon.h>
#include

void forwardRequest(const std::shared_ptrdrogon::HttpRequest &req, const std::function<void(const drogon::HttpResponsePtr &)> &callback, const std::string &host) {

req->setPath(req->getOriginalPath());


drogon::app().forward(std::move(req), std::move(callback), host);

}

int main() {

drogon::app().registerHandler("/forward", [](const drogon::HttpRequestPtr &req, std::function<void (const drogon::HttpResponsePtr &)> &&callback) {
    std::string host = "http://example.com";  
    
    
    forwardRequest(req, std::move(callback), host);
});

// Start the Drogon application
drogon::app().run();
return 0;

}
please check the code I am not understand properly but try this .

@Mis1eader-dev
Copy link
Member Author

@ladaniprem the provided alternative solution does this, but I'm awaiting opinions of other maintainers as to whether we should alter request objects or alter the forward function itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants