diff options
author | Tor Brede Vekterli <vekterli@oath.com> | 2019-01-10 13:38:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-10 13:38:25 +0100 |
commit | 988e36ba7ab840e21e19e593e628f5721bb30cbb (patch) | |
tree | 6e6bd2c68cf69597b0b3bf357d57c73a6b1fec3e /staging_vespalib | |
parent | c194ae3b6f72538b0709dd4a51cb08306c33e836 (diff) | |
parent | 2fdcca86e36498a9451fddb3b3e0ad55ef02f3d7 (diff) |
Merge pull request #8081 from vespa-engine/havardpe/url-dequote-and-parse-query
Havardpe/url dequote and parse query
Diffstat (limited to 'staging_vespalib')
-rw-r--r-- | staging_vespalib/src/tests/state_server/state_server_test.cpp | 46 | ||||
-rw-r--r-- | staging_vespalib/src/vespa/vespalib/net/http_server.cpp | 2 |
2 files changed, 46 insertions, 2 deletions
diff --git a/staging_vespalib/src/tests/state_server/state_server_test.cpp b/staging_vespalib/src/tests/state_server/state_server_test.cpp index b688887c3fb..d4f665029cc 100644 --- a/staging_vespalib/src/tests/state_server/state_server_test.cpp +++ b/staging_vespalib/src/tests/state_server/state_server_test.cpp @@ -40,7 +40,7 @@ vespalib::string run_cmd(const vespalib::string &cmd) { } vespalib::string getPage(int port, const vespalib::string &path, const vespalib::string &extra_params = "") { - return run_cmd(make_string("curl -s %s http://localhost:%d%s", extra_params.c_str(), port, path.c_str())); + return run_cmd(make_string("curl -s %s 'http://localhost:%d%s'", extra_params.c_str(), port, path.c_str())); } vespalib::string getFull(int port, const vespalib::string &path) { return getPage(port, path, "-D -"); } @@ -123,6 +123,50 @@ TEST_FF("require that host is passed correctly", EchoHost(), HttpServer(0)) { EXPECT_EQUAL(default_result, run_cmd(make_string("curl -s http://localhost:%d/my/path -H \"Host:\"", f2.port()))); } +struct SamplingHandler : JsonGetHandler { + mutable std::mutex my_lock; + mutable vespalib::string my_host; + mutable vespalib::string my_path; + mutable std::map<vespalib::string,vespalib::string> my_params; + vespalib::string get(const vespalib::string &host, const vespalib::string &path, + const std::map<vespalib::string,vespalib::string> ¶ms) const override + { + { + auto guard = std::lock_guard(my_lock); + my_host = host; + my_path = path; + my_params = params; + } + return "[]"; + } +}; + +TEST_FF("require that request parameters can be inspected", SamplingHandler(), HttpServer(0)) +{ + auto token = f2.repo().bind("/foo", f1); + EXPECT_EQUAL("[]", getPage(f2.port(), "/foo?a=b&x=y&z")); + { + auto guard = std::lock_guard(f1.my_lock); + EXPECT_EQUAL(f1.my_path, "/foo"); + EXPECT_EQUAL(f1.my_params.size(), 3u); + EXPECT_EQUAL(f1.my_params["a"], "b"); + EXPECT_EQUAL(f1.my_params["x"], "y"); + EXPECT_EQUAL(f1.my_params["z"], ""); + EXPECT_EQUAL(f1.my_params.size(), 3u); // "z" was present + } +} + +TEST_FF("require that request path is dequoted", SamplingHandler(), HttpServer(0)) +{ + auto token = f2.repo().bind("/[foo]", f1); + EXPECT_EQUAL("[]", getPage(f2.port(), "/%5bfoo%5D")); + { + auto guard = std::lock_guard(f1.my_lock); + EXPECT_EQUAL(f1.my_path, "/[foo]"); + EXPECT_EQUAL(f1.my_params.size(), 0u); + } +} + //----------------------------------------------------------------------------- TEST_FFFF("require that the state server wires the appropriate url prefixes", diff --git a/staging_vespalib/src/vespa/vespalib/net/http_server.cpp b/staging_vespalib/src/vespa/vespalib/net/http_server.cpp index 99a66fccde5..2a3bb5b3e0e 100644 --- a/staging_vespalib/src/vespa/vespalib/net/http_server.cpp +++ b/staging_vespalib/src/vespa/vespalib/net/http_server.cpp @@ -8,7 +8,7 @@ namespace vespalib { void HttpServer::get(Portal::GetRequest req) { - vespalib::string json_result = _handler_repo.get(req.get_host(), req.get_uri(), {}); + vespalib::string json_result = _handler_repo.get(req.get_host(), req.get_path(), req.export_params()); if (json_result.empty()) { req.respond_with_error(404, "Not Found"); } else { |