Project

General

Profile

Support #1322 ยป test.cpp

Somsubhra Sharangi, 06/11/2012 02:16 AM

 
#include <Wt/WServer>
#include <Wt/WResource>
#include <Wt/Http/Response>
#include <Wt/WFileResource>

using namespace Wt;

class GhostFileResource : public Wt::WResource
{
public:
virtual ~GhostFileResource(){
beingDeleted();
}
protected:
virtual void handleRequest(const Wt::Http::Request &request,Wt::Http::Response &response){
std::string fetch_command_prefix = "wget http://www.webtoolkit.eu/videos";
std::string dynamic_command = fetch_command_prefix + request.path();
std::cout<< dynamic_command <<std::endl;
system(dynamic_command.c_str());
//maybe do some more processing here to finally generate the file
WFileResource *file = new WFileResource( "/sintel_trailer.mp4" );
response.setMimeType ("video/mp4");
response.out() << file;
}
};

int main(int argc, char **argv)
{
try {
WServer server(argv[0]);
server.setServerConfiguration(argc, argv);

GhostFileResource gfr;
//ask for a file that currently does not exist on server
server.addResource(&gfr, "/sintel_trailer.mp4");

if (server.start()) {
WServer::waitForShutdown();
server.stop();
}
} catch (WServer::Exception& e) {
std::cerr << e.what() << std::endl;
} catch (std::exception &e) {
std::cerr << "exception: " << e.what() << std::endl;
}
}

    (1-1/1)