ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Smersh/Redirector.cpp
Revision: 180
Committed: 2004-07-03T04:12:01-07:00 (20 years, 11 months ago) by Douglas Thrift
File size: 1795 byte(s)
Log Message:
Going nowhere, fast?

File Contents

# User Rev Content
1 Douglas Thrift 165 // Smersh
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #include "Redirector.hpp"
8 Douglas Thrift 172
9 Douglas Thrift 179 int Redirector::handle(Client* client)
10 Douglas Thrift 172 {
11 Douglas Thrift 179 ios::InputOutputStreamBufAdapter adapter(client->socket);
12 Douglas Thrift 180 iostream sio(&adapter);
13     Environment env;
14     stringstream post;
15     ostringstream log;
16     Status code(request(sio, env, post, log));
17 Douglas Thrift 174
18 Douglas Thrift 180 if (code == ok) code = env.get("REQUEST_METHOD") != "POST" ? found :
19     seeOther;
20 Douglas Thrift 174
21 Douglas Thrift 180 response(sio, code);
22    
23     bool head(env.get("REQUEST_METHOD") == "HEAD");
24     streamsize sent(0);
25    
26     if (code == found)
27     {
28     string location(redirect + '?' + query(post, env));
29    
30     sio << "Location: " << location << crlf;
31    
32     if (!head)
33     {
34     string reason(this->reason(code));
35     ostringstream content;
36    
37     content << "<html><head><title>" << code << ' ' << reason << "</tit"
38     << "le></head><body><h1>" << reason << "</h1><p>Don't come here"
39     << ", go <a href=\"" << location << "\">there</a>.</p><hr /><ad"
40     << "dress>" << server() << "</address></body></html>\n";
41     sio << "Content-Length: " << content.str().length() << crlf
42     << "Content-Type: text/html; charset=UTF-8\r\n\r\n";
43    
44     sio.write(content.str().data(), content.str().size());
45    
46     sent = content.str().size();
47     }
48     else sio << "Content-Type: text/html; charset=UTF-8\r\n\r\n";
49     }
50     else if (head) sio << "Content-Type: text/html; charset=UTF-8\r\n\r\n";
51     else sent = error(sio, code);
52    
53     ofstream fout(this->log.c_str(), ios_base::app);
54    
55     fout << inet_ntoa(client->ip->sin_addr) << " - - " << date(true) << ' '
56     << log.str() << code << ' ' << lexical_cast<string>(sent) << " \""
57     << env.get("HTTP_REFERER") << "\" \"" << env.get("HTTP_USER_AGENT")
58     << "\"\n";
59     sio << flush;
60    
61     client->socket.ShutdownWrite();
62    
63 Douglas Thrift 174 delete client;
64 Douglas Thrift 172 }
65 Douglas Thrift 180
66     string Redirector::query(istream& sin, const Environment& env)
67     {
68     ostringstream query;
69    
70     return query.str();
71     }

Properties

Name Value
svn:eol-style native
svn:keywords Id