access CGI values from WResource::handleRequest
Added by Tibor Peak over 7 years ago
Is there any way to access CGI values from within WResource::handleRequest, like it is possible from WApplication using env.getCgiValue()?
Particularly I would like to access the "REMOTE_USER" CGI value.
Thanks in advance.
Replies (6)
RE: access CGI values from WResource::handleRequest - Added by Roel Standaert over 7 years ago
I believe the REMOTE_USER value should be accessible with headerValue()
.
It could be useful for development to request all headers with headers()
(introduced since Wt 3.3.7).
Regards,
Roel
RE: access CGI values from WResource::handleRequest - Added by Tibor Peak over 7 years ago
I'm using Wt 3.3.3, so I cannot use headers().
I'm trying to use headerValue(), but no success.
It is an ISAPI application, user is authenticated by IIS.
There is also WApplication used on the default entry point and there I can successfully query the "REMOTE_USER" with: env.getCgiValue("REMOTE_USER").
Here is my code:
class pingReplyRsc : public Wt::WResource
{
public:
std::string pingReplyMsg;
pingReplyRsc(Wt::WObject *parent = 0)
: Wt::WResource(parent)
{
pingReplyMsg = "<html><head></head><body><br>ping reply<br></body></html>";
}
virtual void handleRequest(const Wt::Http::Request& request,
Wt::Http::Response& response)
{
std::string remoteUser;
myServer->log("info") << "ping request received";
remoteUser = request.headerValue("Remote_user");
myServer->log("info") << "request header REMOTE_USER: " << remoteUser.c_str();
remoteUser = request.headerValue("Remote_User");
myServer->log("info") << "request header REMOTE_USER: " << remoteUser.c_str();
remoteUser = request.headerValue("remote_user");
myServer->log("info") << "request header REMOTE_USER: " << remoteUser.c_str();
remoteUser = request.headerValue("REMOTE_USER");
myServer->log("info") << "request header REMOTE_USER: " << remoteUser.c_str();
response.setMimeType("text/html");
response.out().write(pingReplyMsg.c_str(), pingReplyMsg.length());
}
};
RE: access CGI values from WResource::handleRequest - Added by Roel Standaert over 7 years ago
Sorry, my mistake. It seems that REMOTE_USER
is not present in a header accessible through headerValue()
.
It seems that no method is currently present to retrieve the CGI environment variables. I'll add this method to Wt::Http::Request
.
Regards,
Roel
RE: access CGI values from WResource::handleRequest - Added by Roel Standaert over 7 years ago
The latest commit on GitHub contains a patch for Wt::Http::getCgiValue
.
Regards,
Roel
RE: access CGI values from WResource::handleRequest - Added by Tibor Peak over 7 years ago
I tried: it works, thanks again!
Never received such a prompt support from a software supplier/developer!
Tibor