diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2016-07-05 22:57:59 +0200 |
---|---|---|
committer | Ivo van Dongen <info@ivovandongen.nl> | 2016-07-07 10:08:46 +0200 |
commit | c4c6b1b63a1613f78f28a55e2142708b54ad03f7 (patch) | |
tree | f4a7bee9511894ee5f4fb04cd01e25f0a26e9772 | |
parent | 97cd15932adf0168b4e026a340e51c392ae819bb (diff) | |
download | qtlocation-mapboxgl-c4c6b1b63a1613f78f28a55e2142708b54ad03f7.tar.gz |
[android] #5456 - implemented a couple more cases
-rw-r--r-- | test/src/mbgl/test/server.cpp | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/test/src/mbgl/test/server.cpp b/test/src/mbgl/test/server.cpp index 38fa031901..cc6f01a315 100644 --- a/test/src/mbgl/test/server.cpp +++ b/test/src/mbgl/test/server.cpp @@ -14,13 +14,22 @@ namespace mbgl { namespace test { +std::string timestampToISO(const time_t rawtime){ + struct tm * dt; + char buffer [30]; + dt = localtime(&rawtime); + //Tue, 05 Jul 2016 19:52:50 GMT + strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T %Z", dt); + return std::string(buffer); +} + std::string dumpHeaders(const httplib::MultiMap& headers) { std::string s; char buf[BUFSIZ]; for (auto it = headers.begin(); it != headers.end(); ++it) { const auto& x = *it; - snprintf(buf, sizeof(buf), "%s: %s\n", x.first.c_str(), x.second.c_str()); + snprintf(buf, sizeof(buf), "|%s|: |%s|\n", x.first.c_str(), x.second.c_str()); s += buf; } @@ -34,21 +43,24 @@ Server::Server(bool) { #pragma GCC diagnostic ignored "-Wunused-parameter" svr->get("/test", [](const auto& req, auto& res) { - std::cout << "test\n"; + //XXX Remove + std::cout << "test " << req.url << "\n"; + for (auto it = req.params.begin(); it != req.params.end(); ++it) { + const auto& x = *it; + std::cout << "Param: " << x.first << " - " << x.second << " / " << req.has_param(x.first.c_str()) << "\n"; + } + if(req.has_param("modified")) { - //res.setHeader('Last-Modified', (new Date(req.query.modified * 1000)).toUTCString()); - std::cout << "Modified " << req.params.find("modified")->second; + res.set_header("Last-Modified", timestampToISO(std::stoi(req.params.at("modified"))).c_str()); + std::cout << "Modified " << timestampToISO(std::stoi(req.params.at("modified"))); } if (req.has_param("expires")) { - //res.setHeader('Expires', (new Date(req.query.expires * 1000)).toUTCString()); - std::cout << "Exipres " << req.params.find("expires")->second; + res.set_header("Expires", timestampToISO(std::stoi(req.params.at("expires"))).c_str()); } - if (req.has_param("etag")) { - std::cout << "etag " << req.params.find("etag")->second; + if (req.has_param("etag")) { res.set_header("ETag", req.params.find("etag")->second.c_str()); } if (req.has_param("cachecontrol")) { - std::cout << "cachecontrol " << req.params.find("cachecontrol")->second; res.set_header("Cache-Control", req.params.find("cachecontrol")->second.c_str()); } res.set_content("Hello World!", "text/plain"); @@ -66,9 +78,7 @@ Server::Server(bool) { }); svr->get("/revalidate-same", [](const auto& req, auto& res) { - std::cout << "revalidate same\n"; - std::cout << dumpHeaders(req.headers) << "\n\n"; - if (req.has_header("if-non-match") && req.headers.find("if-none-match")->second == "snowfall") { + if (req.has_header("If-None-Match") && req.headers.find("If-None-Match")->second == "snowfall") { // Second request can be cached for 30 seconds. res.set_header("Cache-Control", "max-age=30"); res.status = 304; |