Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(748)

Unified Diff: components/cronet/ios/test/test_server.cc

Issue 2146643002: [Cronet] Integrate CrNet functionality into Cronet on iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove cronet_test_bundle_data target and use data bundled with net_test_support. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/cronet/ios/test/test_server.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/ios/test/test_server.cc
diff --git a/components/cronet/ios/test/test_server.cc b/components/cronet/ios/test/test_server.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f4d8d137648e03684570b6cdd83414369913e1c8
--- /dev/null
+++ b/components/cronet/ios/test/test_server.cc
@@ -0,0 +1,63 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/cronet/ios/test/test_server.h"
+
+#include <utility>
+
+#include "base/bind.h"
+#include "base/memory/ptr_util.h"
+#include "base/strings/string_util.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "net/test/embedded_test_server/http_request.h"
+#include "net/test/embedded_test_server/http_response.h"
+
+namespace {
+
+const char kEchoHeaderPath[] = "/EchoHeader?";
+
+std::unique_ptr<net::EmbeddedTestServer> g_test_server;
+
+std::unique_ptr<net::test_server::HttpResponse> EchoHeaderInRequest(
+ const net::test_server::HttpRequest& request) {
+ std::string header_name;
+ std::string header_value;
+ if (base::StartsWith(request.relative_url, kEchoHeaderPath,
+ base::CompareCase::INSENSITIVE_ASCII)) {
+ header_name = request.relative_url.substr(strlen(kEchoHeaderPath));
+ }
+ auto it = request.headers.find(header_name);
+ if (it != request.headers.end())
+ header_value = it->second;
+ std::unique_ptr<net::test_server::BasicHttpResponse> http_response(
+ new net::test_server::BasicHttpResponse());
+ http_response->set_content(header_value);
+ return std::move(http_response);
+}
+
+} // namespace
+
+namespace cronet {
+
+/* static */
+bool TestServer::Start() {
+ DCHECK(!g_test_server.get());
+ g_test_server = base::MakeUnique<net::EmbeddedTestServer>(
+ net::EmbeddedTestServer::TYPE_HTTPS);
+ g_test_server->RegisterRequestHandler(base::Bind(&EchoHeaderInRequest));
+ CHECK(g_test_server->Start());
+ return true;
+}
+
+void TestServer::Shutdown() {
+ DCHECK(g_test_server.get());
+ g_test_server.reset();
+}
+
+std::string TestServer::GetEchoHeaderURL(const std::string& header_name) {
+ DCHECK(g_test_server);
+ return g_test_server->GetURL(kEchoHeaderPath + header_name).spec();
+}
+
+} // namespace cronet
« no previous file with comments | « components/cronet/ios/test/test_server.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698