rakesh wrote:You do not need multiple instances of your app. The server will create new instances of the HTTPRequestHandler to handle each (concurrent) request.
rakesh wrote:It all depends upon how you set state. If you store individual request/session state in the main application class, you need to re-engineer your system.
unsigned short port = (unsigned short) config().getInt("HTTPFormServer.port", 9980);
ServerSocket svs(port);
HTTPServer srv(new FormRequestHandlerFactory, svs, new HTTPServerParams);
srv.start();
waitForTerminationRequest();
srv.stop();
if (request.getURI() == "/") {return new HtmlPage;}
Application& app = Application::instance();
app.logger().information("Request from " + request.clientAddress().toString());
HTMLForm form(request, request.stream());
response.setChunkedTransferEncoding(true);
response.setContentType("text/html");
std::ostream& ostr = response.send();
NameValueCollection::ConstIterator it;
NameValueCollection::ConstIterator end;
string username, password;
bool login=false;
if (!form.empty()) //als form niet leeg is: dus als er data is ingevoerd
{
it = form.begin(); //zie definitie van it & end;
end = form.end();
for (; it != end; ++it) //itereren over alle paren van de form
{
temp1=it->first;
temp2=it->second;
if (temp1=="user") {username=temp2;}
if (temp1=="pass") {password=temp2;}
}
if (username=="rof" && password=="lol") {login=true;}
}
if (login==false)
{
ostr <<
"<html><head>";
...
}
if (login==true)
{
ostr <<
"<html><head>";
...
}
rakesh wrote:You should be using regular HTTP session handling features like cookies, or URL encoding your URL's with sessionId values etc.
HTTPCookie cooki(username, password);
cooki.setMaxAge(1200);
cooki.setPath(“/”);
response.addCookie(cooki);class FormRequestHandlerFactory: public HTTPRequestHandlerFactory
{
public:
FormRequestHandlerFactory() {}
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
{
if (request.getURI() == "/") {return new HtmlServer;}
...
HTTPCookie(
const std::string & name,
const std::string & value
);Poco::Net::NameValueCollection cookies;
request.getCookies(cookies);
NameValueCollection::ConstIterator it;
NameValueCollection::ConstIterator end;
if (!cookies.empty())
{ it = cookies.begin();
end = cookies.end();
for (; it != end; ++it)
{
first=it->first;
second=it->second;
cout<<endl<<first<<":"<<second<<endl;
}
}if (username=="foo" && password=="bar")
{
Poco::Net::HTTPCookie userdata("username", username);
userdata.setMaxAge(3600);
response.addCookie(userdata);
} Users browsing this forum: No registered users and 1 guest