aboutsummaryrefslogtreecommitdiffstats
path: root/storageframework
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2019-01-14 11:14:57 +0000
committerHåvard Pettersen <havardpe@oath.com>2019-01-14 11:14:57 +0000
commit7f11bbcde650ab299fb319212133c42bf91a4ec0 (patch)
treebd3b6673c37d890d2c5a30dd05609c0f2e5e88c2 /storageframework
parent8b57fffd5dd15bf5da117191cf40d443a967b5c0 (diff)
improve path/query handling
- return attributes by value to avoid referencing deconstructed objects. - use path/query form portal request to avoid dequoting issues - log raw uri instead of dequoted non-parsed uri
Diffstat (limited to 'storageframework')
-rw-r--r--storageframework/src/vespa/storageframework/generic/status/httpurlpath.cpp47
-rw-r--r--storageframework/src/vespa/storageframework/generic/status/httpurlpath.h10
2 files changed, 40 insertions, 17 deletions
diff --git a/storageframework/src/vespa/storageframework/generic/status/httpurlpath.cpp b/storageframework/src/vespa/storageframework/generic/status/httpurlpath.cpp
index e28c3b75372..337709cc591 100644
--- a/storageframework/src/vespa/storageframework/generic/status/httpurlpath.cpp
+++ b/storageframework/src/vespa/storageframework/generic/status/httpurlpath.cpp
@@ -6,35 +6,42 @@
namespace storage::framework {
HttpUrlPath::HttpUrlPath(const vespalib::string& urlpath)
- : _urlPath(urlpath),
- _path(),
+ : _path(),
_attributes(),
_serverSpec()
{
- init();
+ init(urlpath);
}
HttpUrlPath::HttpUrlPath(const vespalib::string& urlpath,
const vespalib::string& serverSpec)
- : _urlPath(urlpath),
- _path(),
+ : _path(),
_attributes(),
_serverSpec(serverSpec)
{
- init();
+ init(urlpath);
+}
+
+HttpUrlPath::HttpUrlPath(vespalib::string path,
+ std::map<vespalib::string, vespalib::string> attributes,
+ vespalib::string serverSpec)
+ : _path(std::move(path)),
+ _attributes(std::move(attributes)),
+ _serverSpec(std::move(serverSpec))
+{
}
HttpUrlPath::~HttpUrlPath() {}
void
-HttpUrlPath::init()
+HttpUrlPath::init(const vespalib::string &urlpath)
{
- vespalib::string::size_type pos = _urlPath.find('?');
+ vespalib::string::size_type pos = urlpath.find('?');
if (pos == vespalib::string::npos) {
- _path = _urlPath;
+ _path = urlpath;
} else {
- _path = _urlPath.substr(0, pos);
- vespalib::string sub(_urlPath.substr(pos+1));
+ _path = urlpath.substr(0, pos);
+ vespalib::string sub(urlpath.substr(pos+1));
vespalib::StringTokenizer tokenizer(sub, "&", "");
for (uint32_t i=0, n=tokenizer.size(); i<n; ++i) {
const vespalib::string& s(tokenizer[i]);
@@ -54,7 +61,7 @@ HttpUrlPath::hasAttribute(const vespalib::string& id) const
return (_attributes.find(id) != _attributes.end());
}
-const vespalib::string&
+vespalib::string
HttpUrlPath::getAttribute(const vespalib::string& id,
const vespalib::string& defaultValue) const
{
@@ -66,7 +73,21 @@ HttpUrlPath::getAttribute(const vespalib::string& id,
void
HttpUrlPath::print(std::ostream& out, bool, const std::string&) const
{
- out << _urlPath;
+ out << _path;
+ if (!_attributes.empty()) {
+ out << "?";
+ size_t cnt = 0;
+ for (const auto attr: _attributes) {
+ if (cnt++ > 0) {
+ out << "&";
+ }
+ out << attr.first;
+ if (!attr.second.empty()) {
+ out << "=";
+ out << attr.second;
+ }
+ }
+ }
}
}
diff --git a/storageframework/src/vespa/storageframework/generic/status/httpurlpath.h b/storageframework/src/vespa/storageframework/generic/status/httpurlpath.h
index 0f6ebe20235..2b22c6a1063 100644
--- a/storageframework/src/vespa/storageframework/generic/status/httpurlpath.h
+++ b/storageframework/src/vespa/storageframework/generic/status/httpurlpath.h
@@ -14,16 +14,18 @@
namespace storage::framework {
class HttpUrlPath : public vespalib::Printable {
- vespalib::string _urlPath;
vespalib::string _path;
std::map<vespalib::string, vespalib::string> _attributes;
vespalib::string _serverSpec; // "host:port"
- void init();
+ 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; }
@@ -31,8 +33,8 @@ public:
{ return _attributes; }
bool hasAttribute(const vespalib::string& id) const;
- const vespalib::string& getAttribute(const vespalib::string& id,
- const vespalib::string& defaultValue = "") const;
+ vespalib::string getAttribute(const vespalib::string& id,
+ const vespalib::string& defaultValue = "") const;
const vespalib::string& getServerSpec() const {
return _serverSpec;