From 9707409e4d15eadac9b3c752c3c6877788943a58 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 25 Nov 2001 23:50:14 +0000 Subject: Wow, everything almost work!!! Amazing!!! --- lib/HttpServ.cc | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) (limited to 'lib/HttpServ.cc') diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc index c534741..9ab2959 100644 --- a/lib/HttpServ.cc +++ b/lib/HttpServ.cc @@ -46,18 +46,18 @@ String ProcessRequest::GetName() { int ProcessRequest::Do() { switch (current) { case 0: + if (!s.IsConnected()) return TASK_DONE; + c = new ReadJob(&s, &b); WaitFor(c); current = 1; - Suspend(); + Suspend(TASK_ON_HOLD); case 1: delete c; bad = false; - - if (!s.IsConnected()) return TASK_DONE; - + cerr << "Got a request\n----\n"; post = ParseUri(file, domain, &b); @@ -65,7 +65,7 @@ int ProcessRequest::Do() { len = -1; do { b >> t; - cerr << t << endl; + // cerr << t << endl; if ((t.strstr("Content-Length: ") == 0) || (t.strstr("Content-length: ") == 0)) { cerr << "Saw 'Content-Lenght:', reading length from '" << t.extract(16) << "'\n"; len = t.extract(16).to_int(); @@ -89,17 +89,23 @@ int ProcessRequest::Do() { Vars = new Variables(); } - c = new CopyJob(&s, &b, len); - WaitFor(c); current = 2; - Suspend(); + if (hasvars && (len)) { + c = new CopyJob(&s, &b, len); + WaitFor(c); + Suspend(); + } else { + c = 0; + } case 2: - delete c; - ParseVars(&s, len); + if (hasvars) { + if (c) delete c; + ParseVars(&b, len); + } cerr << " Domain = '" << domain << "' - File = '" << file << "'\n"; - + if (!bad) { // Nous vérifions le domaine. if (domain != "") { @@ -248,16 +254,26 @@ bool ProcessRequest::ParseUri(String & file, String & domain, Handle * s) { // p nous indiquera la position de la chaîne URL. switch (t[0]) { case 'P': /* POST? */ + cerr << "Do we have a POST request? "; if (t.extract(1, 4) == "OST ") { + cerr << "Yes.\n"; p = t.to_charp(5); post = true; - break; + } else { + cerr << "No.\n"; + bad = true; } + break; case 'G': /* GET? */ + cerr << "Do we have a GET request? "; if (t.extract(1, 3) == "ET ") { + cerr << "Yes.\n"; p = t.to_charp(4); - break; + } else { + cerr << "No.\n"; + bad = true; } + break; default: bad = true; } @@ -375,16 +391,20 @@ HttpServ::HttpServ(Action * ap, int port, const String & nname) throw (GeneralEx } Listener.SetNonBlock(); - WaitFor(&Listener, W4_STICKY); + WaitFor(&Listener, W4_STICKY | W4_READING); cerr << "Mini HTTP-Server '" << name << "' ready and listening for port " << port << endl; } int HttpServ::Do() { try { + Task * r; + Socket s = Listener.Accept(); s.SetNonBlock(); - new ProcessRequest(p, s, name, localport); + r = new ProcessRequest(p, s, name, localport); + r->SetBurst(); + r->SetCleanUp(); } catch (GeneralException) { } -- cgit v1.2.3