summaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2019-01-09 15:52:02 +0000
committerHåvard Pettersen <havardpe@oath.com>2019-01-09 15:52:02 +0000
commit4543ea32f9efaf603b5b0a269404a95c5fd83a01 (patch)
tree10e151bb30167a3704e69dd77cb94994a734421a /staging_vespalib
parentea89f88cd0673f533fa314f6f9e7a34d84988eca (diff)
wire and verify path and parameters
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/src/tests/state_server/state_server_test.cpp36
-rw-r--r--staging_vespalib/src/vespa/vespalib/net/http_server.cpp2
2 files changed, 36 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..dcc8f664c7a 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,40 @@ 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 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> &params) const override
+ {
+ 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"));
+ 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"));
+ 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 {