Browse Source

- Returned buffered IO for embedded system -- the change was incorrect

- Manager class is now more friendly for CGI scripts
master
Artyom Beilis 15 years ago
parent
commit
788aa1ab74
6 changed files with 13 additions and 68 deletions
  1. +0
    -1
      application.h
  2. +0
    -7
      hello_world.cpp
  3. +4
    -4
      manager.cpp
  4. +1
    -1
      manager.h
  5. +8
    -54
      worker_thread.cpp
  6. +0
    -1
      worker_thread.h

+ 0
- 1
application.h View File

@@ -31,7 +31,6 @@ 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 flush_headers() { worker.flush_headers(); }
void set_user_io() { worker.set_user_io(); }
void no_gzip() { worker.no_gzip(); }



+ 0
- 7
hello_world.cpp View File

@@ -49,7 +49,6 @@ void my_hello_world::png()

void my_hello_world::test2()
{
ostringstream cout;
if(!session.is_set("test")) {
session["test"]="1";
cout<<"Set 1";
@@ -86,14 +85,11 @@ void my_hello_world::test2()
cout<<"Error";
}
}
flush_headers();
this->cout<<cout.str();

}

void my_hello_world::test()
{
ostringstream cout;
if(!session.is_set("time")) {
cout<<"No Time\n";
}
@@ -120,8 +116,6 @@ void my_hello_world::test()
//session.clear();
}
session.set<time_t>("time",time(NULL));
flush_headers();
this->cout<<cout.str();
}

void my_hello_world::std()
@@ -156,7 +150,6 @@ void my_hello_world::cache_test()
{
string tmp;
bool from_cache=true;
flush_headers();
if(!cache.fetch_frame("test",tmp,true)) {
tmp="test value";
from_cache=false;


+ 4
- 4
manager.cpp View File

@@ -694,14 +694,14 @@ void manager::set_gettext(transtext::trans_factory *s)
gettext=auto_ptr<transtext::trans_factory>(s);
}

manager::manager()
manager::manager(char const *f)
{
config.load(0,NULL);
config.load(0,NULL,f);
}

manager::manager(char const *f)
manager::manager(int argc, char **argv,char const *file)
{
config.load(0,NULL,f);
config.load(argc,argv,file);
}

manager::manager(int argc, char **argv)


+ 1
- 1
manager.h View File

@@ -233,9 +233,9 @@ public:
void set_gettext(transtext::trans_factory *);
void set_sessions(session_backend_factory);

manager();
manager(char const *file);
manager(int argc, char **argv);
manager(int argc, char **argv,char const *file);
~manager();
void execute();
};


+ 8
- 54
worker_thread.cpp View File

@@ -54,7 +54,7 @@ void worker_thread::set_cookie(cgicc::HTTPCookie const &c)
response_header->setCookie(c);
}

void worker_thread::flush_headers()
void worker_thread::set_user_io()
{
ostream &cout=cgi_conn->cout();
for(list<string>::iterator h=other_headers.begin();h!=other_headers.end();h++) {
@@ -62,11 +62,6 @@ void worker_thread::flush_headers()
}
session.save();
cout<<header();
}

void worker_thread::set_user_io()
{
flush_headers();
user_io=true;
}

@@ -86,45 +81,6 @@ HTTPHeader &worker_thread::header()
return *response_header;
}

#ifdef CPPCMS_EMBEDDED

void worker_thread::run(cgicc_connection &cgi_conn)
{
cgi=&cgi_conn.cgi();
env=&(cgi->getEnvironment());
other_headers.clear();
set_lang("");
cout.rdbuf(cgi_conn.cout().rdbuf()); // Set output buffer;
this->cgi_conn=&cgi_conn;

set_header(new HTTPHTMLHeader);

if(app.config.lval("server.disable_xpowered_by",0)==0) {
add_header("X-Powered-By: " PACKAGE_NAME "/" PACKAGE_VERSION);
}

try {
/**********/
session.on_start();
main();
session.on_end();
/**********/
if(response_header.get() == NULL) {
throw cppcms_error("Looks like a bug");
}
}
catch(std::exception const &e) {
string msg=e.what();
cout<<HTTPStatusHeader(500,msg);
cout<<"<html><body><p>"+msg+"</p><body></html>";
other_headers.clear();
return;
}
}

#else

void worker_thread::run(cgicc_connection &cgi_conn)
{
cgi=&cgi_conn.cgi();
@@ -140,14 +96,15 @@ void worker_thread::run(cgicc_connection &cgi_conn)

gzip=gzip_done=false;
user_io=false;
string encoding;

#ifndef CPPCMS_EMBEDDED
string encoding;
if((encoding=cgi_conn.env("HTTP_ACCEPT_ENCODING"))!="") {
if(strstr(encoding.c_str(),"gzip")!=NULL) {
gzip=app.config.lval("gzip.enable",1);
}
}
#endif
if(app.config.lval("server.disable_xpowered_by",0)==0) {
add_header("X-Powered-By: " PACKAGE_NAME "/" PACKAGE_VERSION);
}
@@ -185,7 +142,7 @@ void worker_thread::run(cgicc_connection &cgi_conn)

string out=out_buf.str();
out_buf.str("");
#ifndef CPPCMS_EMBEDDED
if(gzip) {
if(out.size()>0) {
if(gzip_done){
@@ -206,15 +163,15 @@ void worker_thread::run(cgicc_connection &cgi_conn)
cgi_out<<*response_header;
}
}
else {
else
#endif
{
cgi_out<<"Content-Length: "<<out.size()<<"\n";
cgi_out<<*response_header;
cgi_out<<out;
}
}

#endif


void worker_thread::no_gzip()
{
@@ -223,9 +180,6 @@ void worker_thread::no_gzip()

void worker_thread::render(string tmpl,string name,base_content &content,ostream &out )
{
#if defined(CPPCMS_EMBEDDED)
flush_headers();
#endif
using cppcms::details::views_storage;
base_view::settings s(this,&out);
auto_ptr<base_view> p(views_storage::instance().fetch_view(tmpl,name,s,&content));


+ 0
- 1
worker_thread.h View File

@@ -70,7 +70,6 @@ public:
void add_header(string s);
void set_cookie(cgicc::HTTPCookie const &c);
void set_user_io();
void flush_headers();
void no_gzip();

HTTPHeader &header();


Loading…
Cancel
Save