summaryrefslogtreecommitdiff
path: root/lib/HttpServ.cc
diff options
context:
space:
mode:
authorPixel <Pixel>2001-11-26 23:11:40 +0000
committerPixel <Pixel>2001-11-26 23:11:40 +0000
commit3baa9d168c02a8734b95d1cc467601b6aaf2f6e4 (patch)
tree6c254e9d75dee5a1e305283788fea3d3fff2a445 /lib/HttpServ.cc
parent3aa63fcbddbce8762ad0f3f54d90ad985c0f9c41 (diff)
Big job here. Many bugs out. Hurray!!
Diffstat (limited to 'lib/HttpServ.cc')
-rw-r--r--lib/HttpServ.cc59
1 files changed, 37 insertions, 22 deletions
diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc
index 1fa656a..8b28878 100644
--- a/lib/HttpServ.cc
+++ b/lib/HttpServ.cc
@@ -21,7 +21,7 @@ class ProcessRequest : public Task {
bool ParseUri(String &, String &, Handle *);
void ParseVars(Handle *, int);
void ShowError(Handle *);
- void SendHeads(Handle *, const String &);
+ void SendHeads(Handle *, const String &, const String & = "", time_t = -1);
void SendRedirect(Handle *);
String file, domain, t;
@@ -58,19 +58,21 @@ int ProcessRequest::Do() {
bad = false;
- cerr << "Got a request\n----\n";
+ cerr << "---- Got a request\n";
post = ParseUri(file, domain, &b);
len = -1;
do {
b >> t;
- // cerr << t << endl;
+ cerr << "Read Request (n): " << 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();
}
} while (t.strlen());
+
+ cerr << "---- Processing it.\n";
hasvars = false;
@@ -78,6 +80,7 @@ int ProcessRequest::Do() {
// On a pas eu de ligne 'Content-Length' mais on a eu une méthode POST.
// Cela est une erreur.
if (len == -1) {
+ cerr << "Error: method POST but no Content-Length\n";
bad = true;
Vars = new Variables();
} else {
@@ -114,6 +117,9 @@ int ProcessRequest::Do() {
if (domain == "/image") bad = false;
if (domain == "/bin") bad = false;
if (domain == "/") bad = false;
+ if (bad) {
+ cerr << "Error: bad domain.\n";
+ }
} else {
// L'url sans domaine ni fichier est valide. (cela arrive sur certains navigateurs...)
bad = (file != "");
@@ -132,7 +138,7 @@ int ProcessRequest::Do() {
} else if (domain == "/bin") {
// Le domaine 'bin' est réservé aux actions. On cherche donc l'action à effectuer.
if ((f = p->Look4URL(file))) {
- SendHeads(&s, "text/html");
+ SendHeads(&b, "text/html");
a = f->Do(Vars, &s);
} else {
ShowError(&b);
@@ -143,8 +149,8 @@ int ProcessRequest::Do() {
// d'input renvoie une erreur.
try {
Handle * i = new Input(String("datas/") + file);
- SendHeads(&b, GetMime(file));
- a = new CopyJob(i, &s, -1, true);
+ SendHeads(&b, GetMime(file), String("Accept-Ranges: bytes") + endhl + "Content-Length: " + (unsigned long long int) i->GetSize() + endhl, i->GetModif());
+ a = new CopyJob(i, &s);
cerr << "File found, dumping.\n";
}
catch (IOGeneral e) {
@@ -157,7 +163,8 @@ int ProcessRequest::Do() {
if (a) a->Stop();
delete Vars;
- c = new CopyJob(&b, &s);
+ cerr << "---- Sending header buffer.\n";
+ c = new CopyJob(&b, &s, -1, false);
WaitFor(c);
current = 3;
Suspend();
@@ -166,6 +173,7 @@ int ProcessRequest::Do() {
delete c;
if (a) {
+ cerr << "---- Sending contents.\n";
a->Restart();
WaitFor(a);
current = 4;
@@ -175,7 +183,7 @@ int ProcessRequest::Do() {
case 4:
if (a) delete a;
- cerr << "----\n";
+ cerr << "---- End of Request.\n";
}
return TASK_DONE;
}
@@ -247,34 +255,31 @@ bool ProcessRequest::ParseUri(String & file, String & domain, Handle * s) {
ssize_t sppos;
*s >> t;
- cerr << t << endl;
+ cerr << "Read Request (1): " << t << endl;
bad = false;
// 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;
} else {
- cerr << "No.\n";
+ cerr << "Error: unknow request.\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);
} else {
- cerr << "No.\n";
+ cerr << "Error: unknow request.\n";
bad = true;
}
break;
default:
+ cerr << "Error: unknow request.\n";
bad = true;
}
@@ -314,7 +319,7 @@ void ProcessRequest::SendRedirect(Handle * s) {
"Server: " << name << endhl <<
"Location: http://127.0.0.1:" << localport << "/bin/start" << endhl <<
"Cache-Control: no-cache" << endhl <<
- "Connection-Type: closed" << endhl <<
+ "Connection: closed" << endhl <<
"Content-Type: text/html" << endhl << endhl <<
"<HTML><HEAD><TITLE>301 - Moved Permanently</TITLE></HEAD>" << endnl <<
"<BODY><center><b><h2>You should be redirected to the " << endnl << endnl <<
@@ -326,12 +331,22 @@ void ProcessRequest::SendRedirect(Handle * s) {
* Nous envoyons les entetes de réponse HTTP.
*/
-void ProcessRequest::SendHeads(Handle * s, const String & mime) {
+void ProcessRequest::SendHeads(Handle * s, const String & mime, const String & extra, time_t lm) {
+ time_t t = time(NULL);
+ struct tm * ft = gmtime(&t);
+ char buf[1024];
+ strftime(buf, 1024, "%a, %d %b %Y %H:%M:%S GMT", ft);
*s << "HTTP/1.1 200 OK" << endhl <<
- "Server: " << name << endhl <<
- "Cache-Control: no-cache" << endhl <<
- "Connection-Type: closed" << endhl <<
- "Content-Type: " << mime << endhl << endhl;
+ "Date: " << buf << endhl <<
+ "Server: " << name << endhl;
+ if (lm >=0) {
+ ft = gmtime(&lm);
+ strftime(buf, 1024, "%a, %d %b %Y %H:%M:%S GMT", ft);
+ }
+ *s << "Last-Modified: " << buf << endhl << extra <<
+ "Keep-Alive: timeout=0, max=0" << endhl <<
+ "Connection: Keep-Alive" << endhl <<
+ "Content-Type: " << mime << endhl << endhl;
}
/*
@@ -342,7 +357,7 @@ void ProcessRequest::ShowError(Handle * s) {
*s << "HTTP/1.1 404 Not Found" << endhl <<
"Server: " << name << endhl <<
"Cache-Control: no-cache" << endhl <<
- "Connection-Type: closed" << endhl <<
+ "Connection: closed" << endhl <<
"Content-Type: text/html" << endhl << endhl <<
"<HTML><HEAD><TITLE>404 - Error</TITLE></HEAD>" << endnl <<
"<BODY><center><b><h2>The server was unable to process your query</h2></b></center>" << endnl <<