diff --git a/application.h b/application.h index fa92e7f..63c8eff 100644 --- a/application.h +++ b/application.h @@ -31,6 +31,7 @@ struct application { void set_header(HTTPHeader *h) { worker.set_header(h); } void add_header(string s) { worker.add_header(s); } void set_cookie(cgicc::HTTPCookie const &c) { worker.set_cookie(c); } + void set_user_io() { worker.set_user_io(); } HTTPHeader &header() { return worker.header(); } diff --git a/hello_world.cpp b/hello_world.cpp index 4ea7b0d..a4ad616 100644 --- a/hello_world.cpp +++ b/hello_world.cpp @@ -13,14 +13,40 @@ public: url.add("^/test$",boost::bind(&my_hello_world::test,this)); url.add("^/test2$",boost::bind(&my_hello_world::test2,this)); url.add("^/cache$",boost::bind(&my_hello_world::cache_test,this)); + url.add("^/png$",boost::bind(&my_hello_world::png,this)); use_template("view2"); }; void test(); + void png(); void test2(); void std(); void cache_test(); }; +void my_hello_world::png() +{ + ifstream file("test.png"); + if(!file) { + cout<<"File test.png not found"; + return ; + } + vector buffer(1024); + set_user_io(); + + ostream &cout=cgi_conn->cout(); + set_header(new cgicc::HTTPContentHeader("image/png")); + session.save(); + cout<load(this,ar,timeout_in)) { return false; } @@ -210,6 +211,8 @@ void session_interface::update_exposed() void session_interface::save() { + if(saved) + return; check(); new_session = data_copy.empty() && !data.empty(); if(data.empty()) { @@ -242,6 +245,7 @@ void session_interface::save() temp_cookie.clear(); update_exposed(); + saved=true; } void session_interface::on_start() diff --git a/session_interface.h b/session_interface.h index d433bd4..26fa6d3 100644 --- a/session_interface.h +++ b/session_interface.h @@ -42,13 +42,13 @@ class session_interface : private boost::noncopyable { // Information from session data time_t timeout_in; bool new_session; + bool saved; int cookie_age(); time_t session_age(); void check(); bool load(); - void save(); void update_exposed(); std::string temp_cookie; @@ -87,6 +87,7 @@ public: void set_expiration(int h); void set_age(); void set_expiration(); + void save(); // Special interface void set_session_cookie(std::string const &data); diff --git a/worker_thread.cpp b/worker_thread.cpp index 5fc4b4b..f643028 100644 --- a/worker_thread.cpp +++ b/worker_thread.cpp @@ -50,6 +50,11 @@ void worker_thread::set_cookie(cgicc::HTTPCookie const &c) response_header->setCookie(c); } +void worker_thread::set_user_io() +{ + user_io=true; +} + void worker_thread::set_lang(string const &s) { lang=s; @@ -80,6 +85,7 @@ void worker_thread::run(cgicc_connection &cgi_conn) set_header(new HTTPHTMLHeader); gzip=gzip_done=false; + user_io=false; string encoding; if((encoding=cgi_conn.env("HTTP_ACCEPT_ENCODING"))!="") { @@ -116,6 +122,11 @@ void worker_thread::run(cgicc_connection &cgi_conn) cgi_out<<*h<<"\n"; } + if(user_io) { + // user controls it's IO + return; + } + string out=out_buf.str(); out_buf.str(""); @@ -170,6 +181,8 @@ void worker_thread::render(string name,base_content &content) render(current_template,name,content,cout); }; + + } diff --git a/worker_thread.h b/worker_thread.h index f5d2a80..c264ad1 100644 --- a/worker_thread.h +++ b/worker_thread.h @@ -41,6 +41,7 @@ class worker_thread: private boost::noncopyable { list other_headers; base_cache *caching_module; + bool user_io; bool gzip; bool gzip_done; stringbuf out_buf; @@ -68,6 +69,7 @@ public: void set_header(HTTPHeader *h); void add_header(string s); void set_cookie(cgicc::HTTPCookie const &c); + void set_user_io(); HTTPHeader &header();