virtual void handleRequest(HTTPServerRequest &req, HTTPServerResponse &resp){ resp.setStatus(HTTPResponse::HTTP_OK); resp.setContentType("text/html"); // Generate requested HTML file ostream& out = resp.send(); out << "<h1>Hello world! This files name is " << req.getURI() << "</h1>" << "<p>Host: " << req.getHost() << "</p>" << "<p>Method: " << req.getMethod() << "</p>"; out.flush(); cout << endl << "Client requested: =" << req.getURI() << endl; }
void PageRequestHandler::handleRequest(HTTPServerRequest &req, HTTPServerResponse &resp) { resp.setStatus(HTTPResponse::HTTP_OK); // std::cout << Poco::format("Received request %s", req.getURI()) << std::endl; string fileName = req.getURI() == "/" ? "index.html" : (req.getURI().substr(1)); if (stringEndsWith(fileName, ".html")) { resp.setContentType("text/html"); } else if (stringEndsWith(fileName, ".css")) { resp.setContentType("text/css"); } else if (stringEndsWith(fileName, ".js")) { resp.setContentType("application/javascript"); } else if (stringEndsWith(fileName, ".woff")) { resp.setContentType("font/woff"); } else { resp.setContentType("text/html"); } FileInputStream input(fileName); StreamCopier::copyStream(input, resp.send()); }
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) { StringTokenizer tok("/"); StringVector tized; tok.tokenize(request.getURI(), tized); if ( tized.size() == 4 ) { int z = as<int>(tized[1], 0); int x = as<int>(tized[2], 0); unsigned int y = as<int>(osgDB::getNameLessExtension(tized[3]),0); std::string ext = osgDB::getFileExtension(tized[3]); OE_DEBUG << "z=" << z << std::endl; OE_DEBUG << "x=" << x << std::endl; OE_DEBUG << "y=" << y << std::endl; OE_DEBUG << "ext=" << ext << std::endl; response.setChunkedTransferEncoding(true); osg::ref_ptr< osg::Image > image = _server->getTile(z, x, y); if (image) { osgDB::ReaderWriter* rw = osgDB::Registry::instance()->getReaderWriterForExtension(ext); if (rw) { std::string mime = "image/png"; if (ext == "jpeg" || ext == "jpg") { mime = "image/jpeg"; } response.setContentType(mime); std::ostream& ostr = response.send(); rw->writeImage(*image.get(), ostr); } } } response.setStatus(Poco::Net::HTTPResponse::HTTP_NOT_FOUND); }
virtual void handleRequest(HTTPServerRequest &req, HTTPServerResponse &resp){ resp.setStatus(HTTPResponse::HTTP_OK); resp.setContentType("text/html"); string fileName = req.getURI(); ostream& out = resp.send(); out << "<h1>Hello friend!</h1>" << "<p>Host: " << req.getHost() << "</p>" << "<p>Method: " << req.getMethod() << "</p>" << "<p>Filename: " << req.getURI() << "</p>"; out.flush(); /** Does not work StreamSocket strs = req.acceptConnection(); SocketStream ostr(strs); std::string file("test.in"); Poco::FileInputStream istr(file, std::ios::binary); StreamCopier::copyStream(istr, ostr); */ cout << endl << "URI=" << req.getURI() << endl; }