@@ -31,6 +31,7 @@ struct application { | |||||
void set_header(HTTPHeader *h) { worker.set_header(h); } | void set_header(HTTPHeader *h) { worker.set_header(h); } | ||||
void add_header(string s) { worker.add_header(s); } | void add_header(string s) { worker.add_header(s); } | ||||
void set_cookie(cgicc::HTTPCookie const &c) { worker.set_cookie(c); } | void set_cookie(cgicc::HTTPCookie const &c) { worker.set_cookie(c); } | ||||
void set_user_io() { worker.set_user_io(); } | |||||
HTTPHeader &header() { return worker.header(); } | HTTPHeader &header() { return worker.header(); } | ||||
@@ -13,14 +13,40 @@ public: | |||||
url.add("^/test$",boost::bind(&my_hello_world::test,this)); | url.add("^/test$",boost::bind(&my_hello_world::test,this)); | ||||
url.add("^/test2$",boost::bind(&my_hello_world::test2,this)); | url.add("^/test2$",boost::bind(&my_hello_world::test2,this)); | ||||
url.add("^/cache$",boost::bind(&my_hello_world::cache_test,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"); | use_template("view2"); | ||||
}; | }; | ||||
void test(); | void test(); | ||||
void png(); | |||||
void test2(); | void test2(); | ||||
void std(); | void std(); | ||||
void cache_test(); | void cache_test(); | ||||
}; | }; | ||||
void my_hello_world::png() | |||||
{ | |||||
ifstream file("test.png"); | |||||
if(!file) { | |||||
cout<<"File test.png not found"; | |||||
return ; | |||||
} | |||||
vector<char> buffer(1024); | |||||
set_user_io(); | |||||
ostream &cout=cgi_conn->cout(); | |||||
set_header(new cgicc::HTTPContentHeader("image/png")); | |||||
session.save(); | |||||
cout<<header(); | |||||
for(;;) { | |||||
file.read(&buffer.front(),1024); | |||||
cout.write(&buffer.front(),file.gcount()); | |||||
if(file.eof()) | |||||
break; | |||||
} | |||||
file.close(); | |||||
} | |||||
void my_hello_world::test2() | void my_hello_world::test2() | ||||
{ | { | ||||
@@ -94,6 +94,7 @@ bool session_interface::load() | |||||
timeout_val=timeout_val_def; | timeout_val=timeout_val_def; | ||||
how=how_def; | how=how_def; | ||||
string ar; | string ar; | ||||
saved=false; | |||||
if(!storage.get() || !storage->load(this,ar,timeout_in)) { | if(!storage.get() || !storage->load(this,ar,timeout_in)) { | ||||
return false; | return false; | ||||
} | } | ||||
@@ -210,6 +211,8 @@ void session_interface::update_exposed() | |||||
void session_interface::save() | void session_interface::save() | ||||
{ | { | ||||
if(saved) | |||||
return; | |||||
check(); | check(); | ||||
new_session = data_copy.empty() && !data.empty(); | new_session = data_copy.empty() && !data.empty(); | ||||
if(data.empty()) { | if(data.empty()) { | ||||
@@ -242,6 +245,7 @@ void session_interface::save() | |||||
temp_cookie.clear(); | temp_cookie.clear(); | ||||
update_exposed(); | update_exposed(); | ||||
saved=true; | |||||
} | } | ||||
void session_interface::on_start() | void session_interface::on_start() | ||||
@@ -42,13 +42,13 @@ class session_interface : private boost::noncopyable { | |||||
// Information from session data | // Information from session data | ||||
time_t timeout_in; | time_t timeout_in; | ||||
bool new_session; | bool new_session; | ||||
bool saved; | |||||
int cookie_age(); | int cookie_age(); | ||||
time_t session_age(); | time_t session_age(); | ||||
void check(); | void check(); | ||||
bool load(); | bool load(); | ||||
void save(); | |||||
void update_exposed(); | void update_exposed(); | ||||
std::string temp_cookie; | std::string temp_cookie; | ||||
@@ -87,6 +87,7 @@ public: | |||||
void set_expiration(int h); | void set_expiration(int h); | ||||
void set_age(); | void set_age(); | ||||
void set_expiration(); | void set_expiration(); | ||||
void save(); | |||||
// Special interface | // Special interface | ||||
void set_session_cookie(std::string const &data); | void set_session_cookie(std::string const &data); | ||||
@@ -50,6 +50,11 @@ void worker_thread::set_cookie(cgicc::HTTPCookie const &c) | |||||
response_header->setCookie(c); | response_header->setCookie(c); | ||||
} | } | ||||
void worker_thread::set_user_io() | |||||
{ | |||||
user_io=true; | |||||
} | |||||
void worker_thread::set_lang(string const &s) | void worker_thread::set_lang(string const &s) | ||||
{ | { | ||||
lang=s; | lang=s; | ||||
@@ -80,6 +85,7 @@ void worker_thread::run(cgicc_connection &cgi_conn) | |||||
set_header(new HTTPHTMLHeader); | set_header(new HTTPHTMLHeader); | ||||
gzip=gzip_done=false; | gzip=gzip_done=false; | ||||
user_io=false; | |||||
string encoding; | string encoding; | ||||
if((encoding=cgi_conn.env("HTTP_ACCEPT_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"; | cgi_out<<*h<<"\n"; | ||||
} | } | ||||
if(user_io) { | |||||
// user controls it's IO | |||||
return; | |||||
} | |||||
string out=out_buf.str(); | string out=out_buf.str(); | ||||
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); | render(current_template,name,content,cout); | ||||
}; | }; | ||||
} | } | ||||
@@ -41,6 +41,7 @@ class worker_thread: private boost::noncopyable { | |||||
list<string> other_headers; | list<string> other_headers; | ||||
base_cache *caching_module; | base_cache *caching_module; | ||||
bool user_io; | |||||
bool gzip; | bool gzip; | ||||
bool gzip_done; | bool gzip_done; | ||||
stringbuf out_buf; | stringbuf out_buf; | ||||
@@ -68,6 +69,7 @@ public: | |||||
void set_header(HTTPHeader *h); | void set_header(HTTPHeader *h); | ||||
void add_header(string s); | void add_header(string s); | ||||
void set_cookie(cgicc::HTTPCookie const &c); | void set_cookie(cgicc::HTTPCookie const &c); | ||||
void set_user_io(); | |||||
HTTPHeader &header(); | HTTPHeader &header(); | ||||