blob: 952d71e85b3fc5e0453fd0d5a2713169f3e97ca7 (
plain) (
blame)
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
* Utility class to parse the url-path part of an HTTP URL.
* Used by status module.
*/
#pragma once
#include <vespa/vespalib/util/printable.h>
#include <vespa/vespalib/stllike/string.h>
#include <map>
#include <sstream>
namespace storage::framework {
class HttpUrlPath : public vespalib::Printable {
vespalib::string _path;
std::map<vespalib::string, vespalib::string> _attributes;
vespalib::string _serverSpec; // "host:port"
void init(const vespalib::string &urlpath);
public:
HttpUrlPath(const vespalib::string& urlpath);
HttpUrlPath(const vespalib::string& urlpath, const vespalib::string& serverSpec);
HttpUrlPath(vespalib::string path,
std::map<vespalib::string, vespalib::string> attributes,
vespalib::string serverSpec);
~HttpUrlPath();
const vespalib::string& getPath() const { return _path; }
const std::map<vespalib::string, vespalib::string>& getAttributes() const
{ return _attributes; }
bool hasAttribute(const vespalib::string& id) const;
vespalib::string getAttribute(const vespalib::string& id,
const vespalib::string& defaultValue = "") const;
const vespalib::string& getServerSpec() const {
return _serverSpec;
}
template<typename T>
T get(const vespalib::string& id, const T& defaultValue = T()) const;
void print(std::ostream& out, bool verbose, const std::string& indent) const override;
};
template<typename T>
T HttpUrlPath::get(const vespalib::string& id, const T& defaultValue) const
{
std::map<vespalib::string, vespalib::string>::const_iterator it = _attributes.find(id);
if (it == _attributes.end()) return defaultValue;
T val;
std::istringstream ist(it->second);
ist >> val;
return val;
}
}
|