1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#include "cvmfs_config.h" |
6 |
|
|
#include "uri_map.h" |
7 |
|
|
|
8 |
|
|
#include <cassert> |
9 |
|
|
|
10 |
|
|
#include "webapi/fcgi.h" |
11 |
|
|
|
12 |
|
|
using namespace std; // NOLINT |
13 |
|
|
|
14 |
|
|
WebRequest::WebRequest() : verb_(kUnknown) { } |
15 |
|
|
|
16 |
|
|
WebRequest *WebRequest::CreateFromCgiHeaders(FastCgi *fcgi) { |
17 |
|
|
WebRequest *request = new WebRequest(); |
18 |
|
|
string method; |
19 |
|
|
fcgi->GetParam("REQUEST_METHOD", &method); |
20 |
|
|
if (method == "GET") |
21 |
|
|
request->verb_ = WebRequest::kGet; |
22 |
|
|
else if (method == "PUT") |
23 |
|
|
request->verb_ = WebRequest::kPut; |
24 |
|
|
else if (method == "POST") |
25 |
|
|
request->verb_ = WebRequest::kPost; |
26 |
|
|
else if (method == "DELETE") |
27 |
|
|
request->verb_ = WebRequest::kDelete; |
28 |
|
|
else |
29 |
|
|
request->verb_ = WebRequest::kUnknown; |
30 |
|
|
fcgi->GetParam("REQUEST_URI", &request->uri_); |
31 |
|
|
return request; |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
|
35 |
|
|
//------------------------------------------------------------------------------ |
36 |
|
|
|
37 |
|
|
|
38 |
|
140 |
void UriMap::Register(const string &uri_spec, UriHandler *handler) { |
39 |
|
140 |
Pathspec path_spec(uri_spec); |
40 |
✓✗✗✓
|
140 |
assert(path_spec.IsValid() && path_spec.IsAbsolute()); |
41 |
|
140 |
rules_.push_back(Match(path_spec, handler)); |
42 |
|
140 |
} |
43 |
|
|
|
44 |
|
|
|
45 |
|
196 |
UriHandler *UriMap::Route(const std::string &uri) { |
46 |
✓✓ |
644 |
for (unsigned i = 0; i < rules_.size(); ++i) { |
47 |
✓✓ |
560 |
if (rules_[i].uri_spec.IsPrefixMatching(uri)) |
48 |
|
112 |
return rules_[i].handler; |
49 |
|
|
} |
50 |
|
84 |
return NULL; |
51 |
|
|
} |