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

Side by Side Diff: components/cronet/android/test/quic_test_server.cc

Issue 1777083002: Make QuicSimpleServerStream supports multipart response body (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@quicsmaller
Patch Set: Rebased Created 4 years, 9 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "quic_test_server.h" 5 #include "quic_test_server.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h"
8 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
9 #include "base/android/path_utils.h" 10 #include "base/android/path_utils.h"
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/strings/string_number_conversions.h"
13 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
14 #include "components/cronet/android/test/cronet_test_util.h" 16 #include "components/cronet/android/test/cronet_test_util.h"
15 #include "jni/QuicTestServer_jni.h" 17 #include "jni/QuicTestServer_jni.h"
16 #include "net/base/ip_endpoint.h" 18 #include "net/base/ip_endpoint.h"
17 #include "net/base/test_data_directory.h" 19 #include "net/base/test_data_directory.h"
18 #include "net/quic/crypto/proof_source_chromium.h" 20 #include "net/quic/crypto/proof_source_chromium.h"
19 #include "net/tools/quic/quic_in_memory_cache.h" 21 #include "net/tools/quic/quic_in_memory_cache.h"
20 #include "net/tools/quic/quic_simple_server.h" 22 #include "net/tools/quic/quic_simple_server.h"
21 23
22 namespace cronet { 24 namespace cronet {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 64 }
63 65
64 void ShutdownOnServerThread() { 66 void ShutdownOnServerThread() {
65 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread()); 67 DCHECK(g_quic_server_thread->task_runner()->BelongsToCurrentThread());
66 g_quic_server->Shutdown(); 68 g_quic_server->Shutdown();
67 delete g_quic_server; 69 delete g_quic_server;
68 } 70 }
69 71
70 } // namespace 72 } // namespace
71 73
74 void AddResponse(JNIEnv* env,
75 const JavaParamRef<jclass>& /*jcaller*/,
76 const JavaParamRef<jstring>& jpath,
77 const JavaParamRef<jobjectArray>& jbody_chunks,
78 const JavaParamRef<jobjectArray>& jtrailers) {
79 std::string host(kFakeQuicDomain);
80 host.append(":");
81 host.append(base::IntToString(kServerPort));
82 std::string path;
83 base::android::ConvertJavaStringToUTF8(env, jpath, &path);
84 std::vector<std::string> body_chunks;
85 base::android::AppendJavaStringArrayToStringVector(env, jbody_chunks,
86 &body_chunks);
87 std::vector<std::string> trailers;
88 base::android::AppendJavaStringArrayToStringVector(env, jtrailers, &trailers);
89 net::SpdyHeaderBlock trailers_block;
90 for (int i = 0; i < trailers.size() / 2; i++) {
91 trailers_block.ReplaceOrAppendHeader(trailers[i * 2], trailers[i * 2 + 1]);
92 }
93
94 net::QuicInMemoryCache::GetInstance()->AddBidirectionalResponse(
95 host, path, 200, body_chunks, trailers_block);
96 }
97
72 // Quic server is currently hardcoded to run on port 6121 of the localhost on 98 // Quic server is currently hardcoded to run on port 6121 of the localhost on
73 // the device. 99 // the device.
74 void StartQuicTestServer(JNIEnv* env, 100 void StartQuicTestServer(JNIEnv* env,
75 const JavaParamRef<jclass>& /*jcaller*/, 101 const JavaParamRef<jclass>& /*jcaller*/,
76 const JavaParamRef<jstring>& jtest_files_root) { 102 const JavaParamRef<jstring>& jtest_files_root) {
77 DCHECK(!g_quic_server_thread); 103 DCHECK(!g_quic_server_thread);
78 g_quic_server_thread = new base::Thread("quic server thread"); 104 g_quic_server_thread = new base::Thread("quic server thread");
79 base::Thread::Options thread_options; 105 base::Thread::Options thread_options;
80 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; 106 thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
81 bool started = g_quic_server_thread->StartWithOptions(thread_options); 107 bool started = g_quic_server_thread->StartWithOptions(thread_options);
(...skipping 20 matching lines...) Expand all
102 128
103 int GetServerPort(JNIEnv* env, const JavaParamRef<jclass>& /*jcaller*/) { 129 int GetServerPort(JNIEnv* env, const JavaParamRef<jclass>& /*jcaller*/) {
104 return kServerPort; 130 return kServerPort;
105 } 131 }
106 132
107 bool RegisterQuicTestServer(JNIEnv* env) { 133 bool RegisterQuicTestServer(JNIEnv* env) {
108 return RegisterNativesImpl(env); 134 return RegisterNativesImpl(env);
109 } 135 }
110 136
111 } // namespace cronet 137 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698