summaryrefslogtreecommitdiffabout
path: root/lib/sitecing_interface_cgi.cc
Side-by-side diff
Diffstat (limited to 'lib/sitecing_interface_cgi.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/sitecing_interface_cgi.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/sitecing_interface_cgi.cc b/lib/sitecing_interface_cgi.cc
index 59ae25a..1acb23c 100644
--- a/lib/sitecing_interface_cgi.cc
+++ b/lib/sitecing_interface_cgi.cc
@@ -1,48 +1,50 @@
#include <cassert>
#include "sitecing/sitecing_interface_cgi.h"
namespace sitecing {
sitecing_interface_cgi::sitecing_interface_cgi(sitespace *s)
: outs(&prebuffer), sitecing_interface(&outs), ss(s), cgigw(NULL), headers_flushed(false) {
}
void sitecing_interface_cgi::prepare(kingate::cgi_gateway *cg) {
cgigw = cg;
headers.clear();
headers["Content-Type"] = "text/html";
prebuffer.str("");
headers_flushed = false;
set_buffering(true);
}
void sitecing_interface_cgi::flush(bool keep_buffering) {
assert(cgigw);
flush_headers();
if(is_buffering()) {
streampos count = prebuffer.pubseekoff(0,ios_base::cur,ios_base::out);
- cgigw->out().write(prebuffer.str().c_str(),count);
+ if(count>0) {
+ cgigw->out().write(prebuffer.str().c_str(),count);
+ }
prebuffer.str("");
}
cgigw->out().flush();
set_buffering(keep_buffering);
}
void sitecing_interface_cgi::set_buffering(bool do_buffer) {
if(!do_buffer)
flush_headers();
outs.rdbuf(do_buffer?&prebuffer:cgigw->out().rdbuf());
}
bool sitecing_interface_cgi::is_buffering() {
return outs.rdbuf()==&prebuffer;
}
void sitecing_interface_cgi::flush_headers() {
assert(cgigw);
if(headers_flushed)
return;
for(kingate::headers::const_iterator i=headers.begin();i!=headers.end();i++)
cgigw->out() << i->first << ": " << i->second << "\n";
cgigw->out() << "\n";
headers_flushed = true;