summaryrefslogtreecommitdiff
path: root/lib/HttpServ.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/HttpServ.cc')
-rw-r--r--lib/HttpServ.cc20
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc
index 602ebe0..ccff319 100644
--- a/lib/HttpServ.cc
+++ b/lib/HttpServ.cc
@@ -32,7 +32,7 @@ class ProcessRequest : public Task {
Action * p;
Socket s;
- String name;
+ String name, host;
Variables * Vars;
bool bad, hasvars, post;
};
@@ -60,18 +60,21 @@ int ProcessRequest::Do() {
bad = false;
- cerr << "---- Got a request\n";
+ cerr << "---- Got a request from handle " << s.GetHandle() << " \n";
post = ParseUri(file, domain, &b);
len = -1;
do {
b >> t;
- // cerr << "Read Request (n): " << 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();
}
+ if (t.strstr("Host: ") == 0) {
+ host = t.extract(6);
+ }
} while (t.strlen());
// cerr << "---- Processing it.\n";
@@ -152,6 +155,7 @@ int ProcessRequest::Do() {
try {
Handle * i = new Input(String("datas/") + file);
SendHeads(&b, GetMime(file), String("Accept-Ranges: bytes") + endhl + "Content-Length: " + (unsigned long long int) i->GetSize() + endhl, i->GetModif());
+ i->SetNonBlock();
a = new CopyJob(i, &s);
cerr << "File found, dumping.\n";
}
@@ -297,8 +301,10 @@ bool ProcessRequest::ParseUri(String & file, String & domain, Handle * s) {
posslash = Uri.strchr('/');
// Certains navigateurs indiqueront uniquement http://host comme URL.
if (posslash >= 0) {
+ host = Uri.extract(0, posslash - 1);
Uri = Uri.to_charp(posslash);
} else {
+ host = Uri;
Uri = "";
}
}
@@ -319,13 +325,13 @@ bool ProcessRequest::ParseUri(String & file, String & domain, Handle * s) {
void ProcessRequest::SendRedirect(Handle * s) {
*s << "HTTP/1.1 301 Moved Permanently" << endhl <<
"Server: " << name << endhl <<
- "Location: http://127.0.0.1:" << localport << "/bin/start" << endhl <<
+ "Location: http://" << host << "/bin/start" << endhl <<
"Cache-Control: no-cache" << 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 <<
- "<a href=\"http://localhost/bin/start\">start page</a></h2></b></center>" << endnl <<
+ "<a href=\"http://" << host << "/bin/start\">start page</a></h2></b></center>" << endnl <<
"</BODY></HTML>" << endnl;
}
@@ -346,9 +352,7 @@ void ProcessRequest::SendHeads(Handle * s, const String & mime, const String & e
strftime(buf, 1024, "%a, %d %b %Y %H:%M:%S GMT", ft);
}
*s << "Last-Modified: " << buf << endhl << extra <<
- "Cache-Control: no-cache" << endhl <<
- "Keep-Alive: timeout=0, max=0" << endhl <<
- "Connection: Keep-Alive" << endhl <<
+ "Connection: closed" << endhl <<
"Content-Type: " << mime << endhl << endhl;
}