From 7f11bbcde650ab299fb319212133c42bf91a4ec0 Mon Sep 17 00:00:00 2001 From: HÃ¥vard Pettersen Date: Mon, 14 Jan 2019 11:14:57 +0000 Subject: 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 --- .../generic/status/httpurlpath.cpp | 47 ++++++++++++++++------ .../storageframework/generic/status/httpurlpath.h | 10 +++-- 2 files changed, 40 insertions(+), 17 deletions(-) (limited to 'storageframework') 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 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 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 _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 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; -- cgit v1.2.3