diff options
author | pixel <pixel> | 2007-05-23 13:07:51 +0000 |
---|---|---|
committer | pixel <pixel> | 2007-05-23 13:07:51 +0000 |
commit | 101cc1939db21d7b2f55445a187421e4acedb383 (patch) | |
tree | 39c7010701b7397f284f55b8a3524113b4fa70d6 /lib | |
parent | 05031ad147604e1408c6b73357cf3f539f57a0d8 (diff) |
Code fixes on the new Domain system, in order to allow the 'builder'
task to work properly.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/HttpServ.cc | 76 |
1 files changed, 54 insertions, 22 deletions
diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc index 4ca4a4c..57809fd 100644 --- a/lib/HttpServ.cc +++ b/lib/HttpServ.cc @@ -213,13 +213,16 @@ int ProcessRequest::Do() throw(GeneralException) { if (a) a->Stop(); // std::cerr << "---- Sending header buffer.\n"; - c = new CopyJob(&b, &s, -1, false); - WaitFor(c); - current = 3; - Suspend(); + if (!d) { + c = new CopyJob(&b, &s, -1, false); + WaitFor(c); + current = 3; + Suspend(); + } case 3: - delete c; + if (!d) + delete c; if (a) { // std::cerr << "---- Sending contents.\n"; @@ -498,6 +501,43 @@ String HttpServ::GetName() { return String("Mini HTTP-Server '") + name + "'"; } +class BuildHttpResponse : public Task { + public: + BuildHttpResponse(HttpResponse * _hr, Handle * _out) : hr(_hr), out(_out) { SetBurst(); } + virtual ~BuildHttpResponse() { } + virtual String GetName() { return "BuildHttpResponse"; } + virtual int Do() throw (GeneralException) { + Buffer * b; + + switch (current) { + case 0: + if (hr->Prepared()) { + b = &hr->contents; + } else { + b = new Buffer(); + hr->PrepareResponse(b); + t = new CopyJob(&hr->contents, b); + t->DryRun(); + delete t; + } + + t = new CopyJob(b, out, -1, b != &hr->contents); + current = 1; + WaitFor(t); + Suspend(TASK_ON_HOLD); + + case 1: + delete t; + } + + return TASK_DONE; + } + private: + HttpResponse * hr; + Handle * out; + Task * t; +}; + HttpResponse::HttpResponse() : mime_type("text/html; charset=iso8859-1"), location(""), server_name("GruiK Server v0.2"), return_code(HTTP_200_OK), last_modified(time(NULL)), cache(true), already_prepared(false), builder(0) { } @@ -505,26 +545,15 @@ HttpResponse::~HttpResponse() { } Task * HttpResponse::BuildResponse(Handle * out) { - Buffer * b; - Task * t; ChainTasks::tasklist_t l; - - if (already_prepared) { - b = &contents; - } else { - b = new Buffer(); - PrepareResponse(b); - t = new CopyJob(&contents, b); - t->DryRun(); - delete t; - } - - t = new CopyJob(b, out, -1, b != &contents); + Task * t; + + t = new BuildHttpResponse(this, out); if (builder) { - l.push_back(t); l.push_back(builder); - return new ChainTasks(l); + l.push_back(t); + t = new ChainTasks(l); } return t; @@ -575,7 +604,10 @@ void HttpResponse::PrepareResponse(Handle * b) { } (*b) << "\r\n"; - +} + +bool HttpResponse::Prepared() { + return already_prepared; } String HttpResponse::code_to_string() { |