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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « components/cronet/ios/test/test_server.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/cronet/ios/test/test_server.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h"
11 #include "base/strings/string_util.h"
12 #include "net/test/embedded_test_server/embedded_test_server.h"
13 #include "net/test/embedded_test_server/http_request.h"
14 #include "net/test/embedded_test_server/http_response.h"
15
16 namespace {
17
18 const char kEchoHeaderPath[] = "/EchoHeader?";
19
20 std::unique_ptr<net::EmbeddedTestServer> g_test_server;
21
22 std::unique_ptr<net::test_server::HttpResponse> EchoHeaderInRequest(
23 const net::test_server::HttpRequest& request) {
24 std::string header_name;
25 std::string header_value;
26 if (base::StartsWith(request.relative_url, kEchoHeaderPath,
27 base::CompareCase::INSENSITIVE_ASCII)) {
28 header_name = request.relative_url.substr(strlen(kEchoHeaderPath));
29 }
30 auto it = request.headers.find(header_name);
31 if (it != request.headers.end())
32 header_value = it->second;
33 std::unique_ptr<net::test_server::BasicHttpResponse> http_response(
34 new net::test_server::BasicHttpResponse());
35 http_response->set_content(header_value);
36 return std::move(http_response);
37 }
38
39 } // namespace
40
41 namespace cronet {
42
43 /* static */
44 bool TestServer::Start() {
45 DCHECK(!g_test_server.get());
46 g_test_server = base::MakeUnique<net::EmbeddedTestServer>(
47 net::EmbeddedTestServer::TYPE_HTTPS);
48 g_test_server->RegisterRequestHandler(base::Bind(&EchoHeaderInRequest));
49 CHECK(g_test_server->Start());
50 return true;
51 }
52
53 void TestServer::Shutdown() {
54 DCHECK(g_test_server.get());
55 g_test_server.reset();
56 }
57
58 std::string TestServer::GetEchoHeaderURL(const std::string& header_name) {
59 DCHECK(g_test_server);
60 return g_test_server->GetURL(kEchoHeaderPath + header_name).spec();
61 }
62
63 } // namespace cronet
OLDNEW
« 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