forked from futurewei-cloud/caerus-dikeCS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdikeCS.cpp
70 lines (57 loc) · 1.75 KB
/
dikeCS.cpp
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
#include <Poco/Net/ServerSocket.h>
#include <Poco/Net/HTTPServer.h>
#include <Poco/Net/HTTPRequestHandler.h>
#include <Poco/Net/HTTPRequestHandlerFactory.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/Net/HTTPServerRequest.h>
#include <Poco/Net/HTTPServerResponse.h>
#include <Poco/Util/ServerApplication.h>
#include <Poco/Util/AbstractConfiguration.h>
#include <Poco/Util/XMLConfiguration.h>
#include <iostream>
#include "S3Handlers.hpp"
#include "TimeUtil.hpp"
using namespace Poco::Net;
using namespace Poco::Util;
using namespace std;
class DikeRequestHandlerFactory : public HTTPRequestHandlerFactory {
public:
virtual HTTPRequestHandler* createRequestHandler(const HTTPServerRequest & req) {
cout << TimeUtil().Yellow() << TimeUtil().Now() << " Start " << TimeUtil().Reset();
cout << req.getURI() << endl;
if(string::npos != req.getURI().find("list-type=2&")){
return new ListObjectsV2;
}
if(string::npos != req.getURI().find("select&select-type=2")){
return new SelectObjectContent;
}
if(req.getMethod() == HTTPRequest::HTTP_PUT) {
return new PutObject;
}
if(req.getMethod() == HTTPRequest::HTTP_GET) {
return new GetObject;
}
req.write(cout);
cout << endl;
return NULL;
}
};
class DikeServerApp : public ServerApplication
{
protected:
int main(const vector<string> &)
{
HTTPServer s(new DikeRequestHandlerFactory, ServerSocket(9000), new HTTPServerParams);
s.start();
cout << endl << "Server started" << endl;
waitForTerminationRequest(); // wait for CTRL-C or kill
cout << endl << "Shutting down..." << endl;
s.stop();
return Application::EXIT_OK;
}
};
int main(int argc, char** argv)
{
DikeServerApp app;
return app.run(argc, argv);
}