#include #include "socket/webserver.h" //#include "Socket.h" void Get(webserver::http_request* r) { // Socket s = *(r->s_); std::string title; std::string body; std::string bgcolor="#ffffff"; std::string links = "
red " "
blue " "
form " "
authentication example [use adp as username and gmbh as password" "
show some HTTP header details " ; //@ server if(r->path_ == "/") { title = "Web Server Example"; body = "

Welcome to Rene's Web Server

" "I wonder what you're going to click" + links; } else if (r->path_ == "/red") { bgcolor = "#ff4444"; title = "You chose red"; body = "

Red

" + links; } else if (r->path_ == "/blue") { bgcolor = "#4444ff"; title = "You chose blue"; body = "

Blue

" + links; } else if (r->path_ == "/form") { title = "Fill a form"; body = "

Fill a form

"; body += "
" "" "" "" "" "
Field 1
Field 2
Field 3
" "
"; for (std::map::const_iterator i = r->params_.begin(); i != r->params_.end(); i++) { body += "
" + i->first + " = " + i->second; } body += "
" + links; } else if (r->path_ == "/auth") { if (r->authentication_given_) { if (r->username_ == "adp" && r->password_ == "gmbh") { body = "

Successfully authenticated

" + links; } else { body = "

Wrong username or password

" + links; r->auth_realm_ = "Private Stuff"; } } else { r->auth_realm_ = "Private Stuff"; } } else if (r->path_ == "/header") { title = "some HTTP header details"; body = std::string ("") + "" + "" + "" + "" + "
Accept:" + r->accept_ + "
Accept-Encoding:" + r->accept_encoding_ + "
Accept-Language:" + r->accept_language_ + "
User-Agent:" + r->user_agent_ + "
" + links; } else { r->status_ = "404 Not Found"; title = "Wrong URL"; body = "

Wrong URL

"; body += "Path is : >" + r->path_ + "<"; } r->answer_ = ""; r->answer_ += title; r->answer_ += ""; r->answer_ += body; r->answer_ += ""; } int main() { webserver(8080, Get); }