-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestsite.cpp
More file actions
85 lines (73 loc) · 2.57 KB
/
testsite.cpp
File metadata and controls
85 lines (73 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <bulkrays/bulkrays.h>
namespace bulkrays {
using namespace std;
class TestSite_SimpleParrot : virtual public TreatRequest {
public:
TestSite_SimpleParrot () : TreatRequest () {}
~TestSite_SimpleParrot () {}
virtual TReqResult output (ostream &cout, HTTPRequest &req) {
stringstream head;
// head << req.version << " 200 OK" << endl
head << "HTTP/1.1" << " 200 OK" << endl
<< "Server: BulkRays/" << BULKRAYSVERSION << endl
<< "Content-Type: text/html;charset=UTF-8" << endl
<< "Connection: keep-alive" << endl
// << "Accept-Ranges: bytes" << endl
;
stringstream s;
s << "<!DOCTYPE html " << endl
<< " PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" << endl
<< " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" << endl
<< "<html xmlns='http://www.w3.org/1999/xhtml'>" << endl;
s << "<head><title>" << req.req_uri << "</title></head>" << endl;
s << "<body>" << endl;
s << "<div>" << endl;
s << "<tt>" << endl;
s << "<div>" << req.method << "</div>" << endl
<< "<div>" << req.req_uri << "</div>" << endl
<< "<div>" << req.version << "</div>" << endl;
s << "</tt>" << endl;
s << "</div>" << endl;
s << "<div>" << endl;
MimeHeader::iterator mi;
for (mi=req.mime.begin() ; mi!=req.mime.end() ; mi++)
s << "<div><i>mime</i>[<b><tt>" << mi->first << "</tt></b>] = <tt><b>" << mi->second << "</b></tt></div>" << endl;
s << "</div>" << endl;
s << "</body>" << endl;
s << "</html>" << endl;
head << "Content-Length: " << s.str().size() << endl;
head << endl;
cout << head.str() << s.str();
return TRCompleted;
}
};
class TestSite_SimpleURIMapper : virtual public URIMapper {
public:
TestSite_SimpleParrot simpleparrot;
TestSite_SimpleURIMapper() : URIMapper() {}
~TestSite_SimpleURIMapper() {}
virtual TreatRequest* treatrequest (HTTPRequest &req) {
return &simpleparrot;
}
};
TestSite_SimpleURIMapper *mapper = NULL;
int testsite_global (BSOperation op) {
switch (op) {
case StartUp:
mapper = new TestSite_SimpleURIMapper();
if (mapper == NULL) {
cerr << "bulkrays::testsite_global could not allocate TestSite_SimpleURIMapper" << endl;
return -1;
}
hostmapper["bulkrays.zz"] = mapper;
hostmapper["bulkrays.zz:10080"] = mapper;
return 0;
case ShutDown:
if (mapper == NULL) return -1;
hostmapper.deregisterall (mapper);
delete (mapper);
return 0;
}
return -1; // simply to quiet warnings ...
}
}