OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "native_test_server.h" | 5 #include "native_test_server.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 if (request.relative_url == kEchoBodyPath) { | 96 if (request.relative_url == kEchoBodyPath) { |
97 if (request.has_content) { | 97 if (request.has_content) { |
98 response->set_content(request.content); | 98 response->set_content(request.content); |
99 } else { | 99 } else { |
100 response->set_content("Request has no body. :("); | 100 response->set_content("Request has no body. :("); |
101 } | 101 } |
102 return response.Pass(); | 102 return response.Pass(); |
103 } | 103 } |
104 | 104 |
105 if (base::StartsWithASCII(request.relative_url, kEchoHeaderPath, true)) { | 105 if (base::StartsWith(request.relative_url, kEchoHeaderPath, |
| 106 base::CompareCase::SENSITIVE)) { |
106 GURL url = g_test_server->GetURL(request.relative_url); | 107 GURL url = g_test_server->GetURL(request.relative_url); |
107 auto it = request.headers.find(url.query()); | 108 auto it = request.headers.find(url.query()); |
108 if (it != request.headers.end()) { | 109 if (it != request.headers.end()) { |
109 response->set_content(it->second); | 110 response->set_content(it->second); |
110 } else { | 111 } else { |
111 response->set_content("Header not found. :("); | 112 response->set_content("Header not found. :("); |
112 } | 113 } |
113 return response.Pass(); | 114 return response.Pass(); |
114 } | 115 } |
115 | 116 |
(...skipping 18 matching lines...) Expand all Loading... |
134 } | 135 } |
135 | 136 |
136 scoped_ptr<net::test_server::HttpResponse> SdchRequestHandler( | 137 scoped_ptr<net::test_server::HttpResponse> SdchRequestHandler( |
137 const net::test_server::HttpRequest& request) { | 138 const net::test_server::HttpRequest& request) { |
138 DCHECK(g_test_server); | 139 DCHECK(g_test_server); |
139 base::FilePath dir_path; | 140 base::FilePath dir_path; |
140 bool get_data_dir = base::android::GetDataDirectory(&dir_path); | 141 bool get_data_dir = base::android::GetDataDirectory(&dir_path); |
141 DCHECK(get_data_dir); | 142 DCHECK(get_data_dir); |
142 dir_path = dir_path.Append(FILE_PATH_LITERAL("test")); | 143 dir_path = dir_path.Append(FILE_PATH_LITERAL("test")); |
143 | 144 |
144 if (base::StartsWithASCII(request.relative_url, kSdchPath, true)) { | 145 if (base::StartsWith(request.relative_url, kSdchPath, |
| 146 base::CompareCase::SENSITIVE)) { |
145 base::FilePath file_path = dir_path.Append("sdch/index"); | 147 base::FilePath file_path = dir_path.Append("sdch/index"); |
146 scoped_ptr<CustomHttpResponse> response = | 148 scoped_ptr<CustomHttpResponse> response = |
147 ConstructResponseBasedOnFile(file_path).Pass(); | 149 ConstructResponseBasedOnFile(file_path).Pass(); |
148 // Check for query params to see which dictionary to advertise. | 150 // Check for query params to see which dictionary to advertise. |
149 // For instance, ?q=dictionaryA will make the server advertise dictionaryA. | 151 // For instance, ?q=dictionaryA will make the server advertise dictionaryA. |
150 GURL url = g_test_server->GetURL(request.relative_url); | 152 GURL url = g_test_server->GetURL(request.relative_url); |
151 std::string dictionary; | 153 std::string dictionary; |
152 if (!net::GetValueForKeyInQuery(url, "q", &dictionary)) { | 154 if (!net::GetValueForKeyInQuery(url, "q", &dictionary)) { |
153 CHECK(false) << "dictionary is not found in query params of " | 155 CHECK(false) << "dictionary is not found in query params of " |
154 << request.relative_url; | 156 << request.relative_url; |
155 } | 157 } |
156 auto accept_encoding_header = request.headers.find("Accept-Encoding"); | 158 auto accept_encoding_header = request.headers.find("Accept-Encoding"); |
157 if (accept_encoding_header != request.headers.end()) { | 159 if (accept_encoding_header != request.headers.end()) { |
158 if (accept_encoding_header->second.find("sdch") != std::string::npos) | 160 if (accept_encoding_header->second.find("sdch") != std::string::npos) |
159 response->AddHeader(base::StringPrintf( | 161 response->AddHeader(base::StringPrintf( |
160 "Get-Dictionary: %s%s", kSdchDictPath, dictionary.c_str())); | 162 "Get-Dictionary: %s%s", kSdchDictPath, dictionary.c_str())); |
161 } | 163 } |
162 return response.Pass(); | 164 return response.Pass(); |
163 } | 165 } |
164 | 166 |
165 if (base::StartsWithASCII(request.relative_url, kSdchTestPath, true)) { | 167 if (base::StartsWith(request.relative_url, kSdchTestPath, |
| 168 base::CompareCase::SENSITIVE)) { |
166 auto avail_dictionary_header = request.headers.find("Avail-Dictionary"); | 169 auto avail_dictionary_header = request.headers.find("Avail-Dictionary"); |
167 if (avail_dictionary_header != request.headers.end()) { | 170 if (avail_dictionary_header != request.headers.end()) { |
168 base::FilePath file_path = dir_path.Append( | 171 base::FilePath file_path = dir_path.Append( |
169 "sdch/" + avail_dictionary_header->second + "_encoded"); | 172 "sdch/" + avail_dictionary_header->second + "_encoded"); |
170 return ConstructResponseBasedOnFile(file_path).Pass(); | 173 return ConstructResponseBasedOnFile(file_path).Pass(); |
171 } | 174 } |
172 scoped_ptr<net::test_server::BasicHttpResponse> response( | 175 scoped_ptr<net::test_server::BasicHttpResponse> response( |
173 new net::test_server::BasicHttpResponse()); | 176 new net::test_server::BasicHttpResponse()); |
174 response->set_content_type("text/plain"); | 177 response->set_content_type("text/plain"); |
175 response->set_content("Sdch is not used.\n"); | 178 response->set_content("Sdch is not used.\n"); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 #else | 315 #else |
313 return JNI_FALSE; | 316 return JNI_FALSE; |
314 #endif | 317 #endif |
315 } | 318 } |
316 | 319 |
317 bool RegisterNativeTestServer(JNIEnv* env) { | 320 bool RegisterNativeTestServer(JNIEnv* env) { |
318 return RegisterNativesImpl(env); | 321 return RegisterNativesImpl(env); |
319 } | 322 } |
320 | 323 |
321 } // namespace cronet | 324 } // namespace cronet |
OLD | NEW |