OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/test/embedded_test_server/default_handlers.h" | |
6 | |
7 #include <stdlib.h> | |
8 #include <ctime> | |
9 #include <map> | |
10 #include <sstream> | |
11 #include <string> | |
12 | |
13 #include "base/base64.h" | |
14 #include "base/files/file_path.h" | |
15 #include "base/files/file_util.h" | |
16 #include "base/format_macros.h" | |
17 #include "base/md5.h" | |
18 #include "base/path_service.h" | |
19 #include "base/strings/string_split.h" | |
20 #include "base/strings/string_util.h" | |
21 #include "base/strings/stringprintf.h" | |
22 #include "base/thread_task_runner_handle.h" | |
23 #include "base/time/time.h" | |
24 #include "net/base/escape.h" | |
25 #include "net/base/url_util.h" | |
26 #include "net/test/embedded_test_server/http_request.h" | |
27 #include "net/test/embedded_test_server/http_response.h" | |
28 #include "net/test/embedded_test_server/request_handler_util.h" | |
29 | |
30 namespace net { | |
31 namespace test_server { | |
32 namespace { | |
33 | |
34 #define PREFIXED_HANDLER(prefix, handler) \ | |
Bence
2015/10/27 14:47:36
And #undef PREFIXED_HANDLER shortly after last use
Bence
2015/10/27 14:47:36
Move this down to around line 548, like right befo
svaldez
2015/10/27 15:00:50
Done.
svaldez
2015/10/27 15:00:50
Done.
| |
35 base::Bind(&HandlePrefixedRequest, prefix, base::Bind(handler)) | |
36 | |
37 const UnescapeRule::Type kUnescapeAll = | |
38 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS | | |
39 UnescapeRule::SPOOFING_AND_CONTROL_CHARS | | |
40 UnescapeRule::REPLACE_PLUS_WITH_SPACE; | |
41 | |
42 const char kDefaultRealm[] = "testrealm"; | |
43 const char kDefaultPassword[] = "password"; | |
44 | |
45 scoped_ptr<HttpResponse> HandleDefaultConnect(const HttpRequest& request) { | |
46 if (request.method != METHOD_CONNECT) | |
47 return nullptr; | |
48 | |
49 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
50 http_response->set_code(HTTP_BAD_REQUEST); | |
51 http_response->set_content( | |
52 "Your client has issued a malformed or illegal request."); | |
53 http_response->set_content_type("text/html"); | |
54 return http_response.Pass(); | |
Bence
2015/10/27 14:47:36
Please consider removing Pass() from every return
svaldez
2015/10/27 15:00:50
There currently needs to be an explicit Pass() sin
Bence
2015/10/27 15:13:19
Sorry, I didn't realize that.
| |
55 } | |
56 | |
57 scoped_ptr<HttpResponse> HandleCacheTime(const HttpRequest& request) { | |
58 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
59 http_response->set_code(HTTP_OK); | |
60 http_response->set_content( | |
61 "<html><head><title>Cache: max-age=60</title></head></html>"); | |
62 http_response->set_content_type("text/html"); | |
63 http_response->AddCustomHeader("Cache-Control", "max-age=60"); | |
64 return http_response.Pass(); | |
65 } | |
66 | |
67 scoped_ptr<HttpResponse> HandleEchoHeader(std::string url, | |
68 std::string cache_control, | |
69 const HttpRequest& request) { | |
70 if (!ShouldHandle(request, url)) | |
71 return nullptr; | |
72 | |
73 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
74 http_response->set_code(HTTP_OK); | |
75 | |
76 GURL request_gurl = request.GetURL(); | |
77 if (request_gurl.has_query()) { | |
78 std::string header_name = request_gurl.query(); | |
79 http_response->AddCustomHeader("Vary", header_name); | |
80 if (request.headers.find(header_name) != request.headers.end()) | |
81 http_response->set_content(request.headers.at(header_name)); | |
82 else | |
83 http_response->set_content("None"); | |
84 } | |
85 | |
86 http_response->set_content_type("text/plain"); | |
87 http_response->AddCustomHeader("Cache-Control", cache_control); | |
88 return http_response.Pass(); | |
89 } | |
90 | |
91 scoped_ptr<HttpResponse> HandleEcho(const HttpRequest& request) { | |
92 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
93 http_response->set_code(HTTP_OK); | |
94 | |
95 GURL request_gurl = request.GetURL(); | |
96 if (request_gurl.has_query()) { | |
97 RequestQuery query = ParseQuery(request_gurl); | |
98 if (query.find("status") != query.end()) | |
99 http_response->set_code(static_cast<HttpStatusCode>( | |
100 std::atoi(query["status"].front().c_str()))); | |
101 } | |
102 | |
103 http_response->set_content_type("text/html"); | |
104 if (request.method != METHOD_POST && request.method != METHOD_PUT) | |
105 http_response->set_content("Echo"); | |
106 else | |
107 http_response->set_content(request.content); | |
108 return http_response.Pass(); | |
109 } | |
110 | |
111 scoped_ptr<HttpResponse> HandleEchoTitle(const HttpRequest& request) { | |
112 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
113 http_response->set_code(HTTP_OK); | |
114 http_response->set_content_type("text/html"); | |
115 http_response->set_content("<html><head><title>" + request.content + | |
116 "</title></head></html>"); | |
117 return http_response.Pass(); | |
118 } | |
119 | |
120 scoped_ptr<HttpResponse> HandleEchoAll(const HttpRequest& request) { | |
121 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
122 http_response->set_code(HTTP_OK); | |
123 | |
124 std::string body; | |
125 body += | |
126 "<html><head><style>" | |
127 "pre { border: 1px solid black; margin: 5px; padding: 5px }" | |
128 "</style></head><body>" | |
129 "<div style=\"float: right\">" | |
130 "<a href=\"/echo\">back to referring page</a></div>" | |
131 "<h1>Request Body:</h1><pre>"; | |
132 | |
133 if (request.has_content) { | |
134 std::vector<std::string> qs = base::SplitString( | |
135 request.content, "&", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | |
136 for (size_t i = 0; i < qs.size(); ++i) { | |
137 body += qs[i] + "\n"; | |
138 } | |
139 } | |
140 | |
141 body += | |
142 "</pre>" | |
143 "<h1>Request Headers:</h1><pre>" + | |
144 request.all_headers + | |
145 "</pre>" | |
146 "</body></html>"; | |
147 | |
148 http_response->set_content_type("text/html"); | |
149 http_response->set_content(body); | |
150 return http_response.Pass(); | |
151 } | |
152 | |
153 scoped_ptr<HttpResponse> HandleSetCookie(const HttpRequest& request) { | |
154 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
155 http_response->set_code(HTTP_OK); | |
156 http_response->set_content_type("text/html"); | |
157 std::string content; | |
158 GURL request_gurl = request.GetURL(); | |
159 if (request_gurl.has_query()) { | |
160 std::vector<std::string> cookies = base::SplitString( | |
161 request_gurl.query(), "&", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | |
162 for (size_t i = 0; i < cookies.size(); ++i) { | |
163 http_response->AddCustomHeader("Set-Cookie", cookies[i]); | |
164 content += cookies[i]; | |
165 } | |
166 } | |
167 | |
168 http_response->set_content(content); | |
169 return http_response.Pass(); | |
170 } | |
171 | |
172 scoped_ptr<HttpResponse> HandleSetManyCookies(const HttpRequest& request) { | |
173 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
174 http_response->set_code(HTTP_OK); | |
175 http_response->set_content_type("text/html"); | |
176 std::string content; | |
177 | |
178 GURL request_gurl = request.GetURL(); | |
179 size_t num = 0; | |
180 if (request_gurl.has_query()) { | |
181 num = std::atoi(request_gurl.query().c_str()); | |
182 } | |
183 | |
184 for (size_t i = 0; i < num; ++i) { | |
185 http_response->AddCustomHeader("Set-Cookie", "a="); | |
186 } | |
187 | |
188 http_response->set_content( | |
189 base::StringPrintf("%" PRIuS " cookies were sent", num)); | |
190 return http_response.Pass(); | |
191 } | |
192 | |
193 scoped_ptr<HttpResponse> HandleExpectAndSetCookie(const HttpRequest& request) { | |
194 std::vector<std::string> sentCookies; | |
195 if (request.headers.find("Cookie") != request.headers.end()) { | |
196 std::vector<std::string> cookies = | |
197 base::SplitString(request.headers.at("Cookie"), ";", | |
198 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | |
199 for (size_t i = 0; i < cookies.size(); ++i) { | |
200 sentCookies.push_back(cookies[i]); | |
201 } | |
202 } | |
203 bool gotExpected = true; | |
204 | |
205 GURL request_gurl = request.GetURL(); | |
206 RequestQuery qs = ParseQuery(request_gurl); | |
207 if (qs.find("expect") != qs.end()) { | |
208 std::vector<std::string> expected = qs.at("expect"); | |
209 for (size_t i = 0; i < expected.size(); ++i) { | |
210 bool found = false; | |
211 for (size_t j = 0; j < sentCookies.size(); ++j) { | |
212 if (expected[i] == sentCookies[j]) | |
213 found = true; | |
214 } | |
215 gotExpected &= found; | |
216 } | |
217 } | |
218 | |
219 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
220 http_response->set_code(HTTP_OK); | |
221 http_response->set_content_type("text/html"); | |
222 if (gotExpected) { | |
223 std::vector<std::string> setCookies = qs.at("set"); | |
224 for (size_t i = 0; i < setCookies.size(); ++i) { | |
225 http_response->AddCustomHeader( | |
226 "Set-Cookie", net::UnescapeURLComponent(setCookies[i], kUnescapeAll)); | |
227 } | |
228 } | |
229 | |
230 std::string content; | |
231 if (qs.find("data") != qs.end()) { | |
232 std::vector<std::string> data = qs.at("data"); | |
233 for (size_t i = 0; i < data.size(); ++i) { | |
234 content += data[i]; | |
235 } | |
236 } | |
237 | |
238 http_response->set_content(content); | |
239 return http_response.Pass(); | |
240 } | |
241 | |
242 scoped_ptr<HttpResponse> HandleSetHeader(const HttpRequest& request) { | |
243 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
244 http_response->set_code(HTTP_OK); | |
245 http_response->set_content_type("text/html"); | |
246 | |
247 std::string content; | |
248 | |
249 GURL request_gurl = request.GetURL(); | |
250 if (request_gurl.has_query()) { | |
251 RequestQuery headers = ParseQuery(request_gurl); | |
252 for (auto header : headers) { | |
253 std::string key = header.first.substr(0, header.first.find(": ")); | |
254 std::string value = header.first.substr(header.first.find(": ") + 2); | |
255 http_response->AddCustomHeader(key, value); | |
256 content += header.first; | |
257 } | |
258 } | |
259 | |
260 http_response->set_content(content); | |
261 return http_response.Pass(); | |
262 } | |
263 | |
264 scoped_ptr<HttpResponse> HandleNoContent(const HttpRequest& request) { | |
265 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
266 http_response->set_code(HTTP_NO_CONTENT); | |
267 return http_response.Pass(); | |
268 } | |
269 | |
270 scoped_ptr<HttpResponse> HandleCloseSocket(const HttpRequest& request) { | |
271 scoped_ptr<RawHttpResponse> http_response(new RawHttpResponse("", "")); | |
272 return http_response.Pass(); | |
273 } | |
274 | |
275 scoped_ptr<HttpResponse> HandleAuthBasic(const HttpRequest& request) { | |
276 GURL request_gurl = request.GetURL(); | |
277 RequestQuery query = ParseQuery(request_gurl); | |
278 | |
279 std::string expectedPassword = "secret"; | |
280 if (query.find(kDefaultPassword) != query.end()) | |
281 expectedPassword = query.at(kDefaultPassword).front(); | |
282 std::string realm = kDefaultRealm; | |
283 if (query.find("realm") != query.end()) | |
284 realm = query.at("realm").front(); | |
285 | |
286 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
287 bool authed = false; | |
288 std::string error; | |
289 std::string auth; | |
290 std::string username; | |
291 std::string userpass; | |
292 std::string password; | |
293 std::string b64str; | |
294 if (request.headers.find("Authorization") == request.headers.end()) { | |
295 error = "Missing Authorization Header"; | |
296 } else { | |
297 auth = request.headers.at("Authorization"); | |
298 if (auth.find("Basic ") == std::string::npos) { | |
299 error = "Invalid Authorization Header"; | |
300 } else { | |
301 b64str = auth.substr(std::string("Basic ").size()); | |
302 base::Base64Decode(b64str, &userpass); | |
303 if (userpass.find(":") != std::string::npos) { | |
304 username = userpass.substr(0, userpass.find(":")); | |
305 password = userpass.substr(userpass.find(":") + 1); | |
306 if (password == expectedPassword) | |
307 authed = true; | |
308 else | |
309 error = "Invalid Credentials"; | |
310 } else | |
311 error = "Invalid Credentials"; | |
312 } | |
313 } | |
314 | |
315 if (!authed) { | |
316 http_response->set_code(HTTP_UNAUTHORIZED); | |
317 http_response->set_content_type("text/html"); | |
318 http_response->AddCustomHeader("WWW-Authenticate", | |
319 "Basic realm=\"" + realm + "\""); | |
320 if (query.find("set-cookie-if-challenged") != query.end()) | |
321 http_response->AddCustomHeader("Set-Cookie", "got_challenged=true"); | |
322 http_response->set_content(base::StringPrintf( | |
323 "<html><head><title>Denied: %s</title></head>" | |
324 "<body>auth=%s<p>b64str=%s<p>username: %s<p>userpass: %s<p>" | |
325 "password: %s<p>You sent:<br>%s<p></body></html>", | |
326 error.c_str(), auth.c_str(), b64str.c_str(), username.c_str(), | |
327 userpass.c_str(), password.c_str(), request.all_headers.c_str())); | |
328 return http_response.Pass(); | |
329 } | |
330 | |
331 if (request.headers.find("If-None-Match") != request.headers.end() && | |
332 request.headers.at("If-None-Match") == "abc") { | |
333 http_response->set_code(HTTP_NOT_MODIFIED); | |
334 return http_response.Pass(); | |
335 } | |
336 | |
337 base::FilePath file_path = | |
338 base::FilePath().AppendASCII(request.relative_url.substr(1)); | |
339 if (file_path.FinalExtension() == FILE_PATH_LITERAL("gif")) { | |
340 base::FilePath server_root; | |
341 PathService::Get(base::DIR_SOURCE_ROOT, &server_root); | |
342 base::FilePath gif_path = | |
343 server_root.AppendASCII("chrome/test/data/google/logo.gif"); | |
344 std::string gif_data; | |
345 base::ReadFileToString(gif_path, &gif_data); | |
346 http_response->set_content_type("image/gif"); | |
347 http_response->set_content(gif_data); | |
348 } else { | |
349 http_response->set_content_type("text/html"); | |
350 http_response->set_content( | |
351 base::StringPrintf("<html><head><title>%s/%s</title></head>" | |
352 "<body>auth=%s<p>You sent:<br>%s<p></body></html>", | |
353 username.c_str(), password.c_str(), auth.c_str(), | |
354 request.all_headers.c_str())); | |
355 } | |
356 | |
357 http_response->set_code(HTTP_OK); | |
358 http_response->AddCustomHeader("Cache-Control", "max-age=60000"); | |
359 http_response->AddCustomHeader("Etag", "abc"); | |
360 return http_response.Pass(); | |
361 } | |
362 | |
363 scoped_ptr<HttpResponse> HandleAuthDigest(const HttpRequest& request) { | |
364 std::string nonce = base::MD5String( | |
365 base::StringPrintf("privatekey%s", request.relative_url.c_str())); | |
366 std::string opaque = base::MD5String("opaque"); | |
367 std::string password = "secret"; | |
368 std::string realm = kDefaultRealm; | |
369 | |
370 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
371 bool authed = false; | |
372 std::string error; | |
373 std::string auth; | |
374 std::string digestStr = "Digest"; | |
375 std::string username; | |
376 if (request.headers.find("Authorization") == request.headers.end()) { | |
377 error = "no auth"; | |
378 } else if (request.headers.at("Authorization").substr(0, digestStr.size()) != | |
379 digestStr) { | |
380 error = "not digest"; | |
381 } else { | |
382 auth = request.headers.at("Authorization"); | |
383 | |
384 std::map<std::string, std::string> authPairs; | |
385 std::vector<std::string> authVector = base::SplitString( | |
386 auth, ", ", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | |
387 for (auto authPair : authVector) { | |
388 std::string key = authPair.substr(0, authPair.find("=")); | |
389 std::string value = authPair.substr(authPair.find("=") + 1); | |
390 if (value.substr(0, 1) == "\"" && value.substr(value.size() - 1) == "\"") | |
391 value = value.substr(1, value.size() - 2); | |
392 authPairs[key] = value; | |
393 } | |
394 | |
395 if (authPairs["nonce"] != nonce) { | |
396 error = "wrong nonce"; | |
397 } else if (authPairs["opaque"] != opaque) { | |
398 error = "wrong opaque"; | |
399 } else { | |
400 username = authPairs["username"]; | |
401 | |
402 std::string hash1 = base::MD5String( | |
403 base::StringPrintf("%s:%s:%s", authPairs["username"].c_str(), | |
404 realm.c_str(), password.c_str())); | |
405 std::string hash2 = base::MD5String(base::StringPrintf( | |
406 "%s:%s", request.method_string.c_str(), authPairs["uri"].c_str())); | |
407 | |
408 std::string response; | |
409 if (authPairs.find("qop") != authPairs.end() && | |
410 authPairs.find("nc") != authPairs.end() && | |
411 authPairs.find("cnonce") != authPairs.end()) { | |
412 response = base::MD5String(base::StringPrintf( | |
413 "%s:%s:%s:%s:%s:%s", hash1.c_str(), nonce.c_str(), | |
414 authPairs["nc"].c_str(), authPairs["cnonce"].c_str(), | |
415 authPairs["qop"].c_str(), hash2.c_str())); | |
416 } else { | |
417 response = base::MD5String(base::StringPrintf( | |
418 "%s:%s:%s", hash1.c_str(), nonce.c_str(), hash2.c_str())); | |
419 } | |
420 | |
421 if (authPairs["response"] == response) | |
422 authed = true; | |
423 else | |
424 error = "wrong password"; | |
425 } | |
426 } | |
427 | |
428 if (!authed) { | |
429 http_response->set_code(HTTP_UNAUTHORIZED); | |
430 http_response->set_content_type("text/html"); | |
431 std::string authHeader = base::StringPrintf( | |
432 "Digest realm=\"%s\", " | |
433 "domain=\"/\", qop=\"auth\", algorithm=MD5, nonce=\"%s\", " | |
434 "opaque=\"%s\"", | |
435 realm.c_str(), nonce.c_str(), opaque.c_str()); | |
436 http_response->AddCustomHeader("WWW-Authenticate", authHeader); | |
437 http_response->set_content(base::StringPrintf( | |
438 "<html><head><title>Denied: %s</title></head>" | |
439 "<body>auth=%s<p>" | |
440 "You sent:<br>%s<p>We are replying:<br>%s<p></body></html>", | |
441 error.c_str(), auth.c_str(), request.all_headers.c_str(), | |
442 authHeader.c_str())); | |
443 return http_response.Pass(); | |
444 } | |
445 | |
446 http_response->set_content_type("text/html"); | |
447 http_response->set_content( | |
448 base::StringPrintf("<html><head><title>%s/%s</title></head>" | |
449 "<body>auth=%s<p></body></html>", | |
450 username.c_str(), password.c_str(), auth.c_str())); | |
451 | |
452 return http_response.Pass(); | |
453 } | |
454 | |
455 scoped_ptr<HttpResponse> HandleServerRedirect(const HttpRequest& request) { | |
456 GURL request_gurl = request.GetURL(); | |
457 std::string dest = | |
458 net::UnescapeURLComponent(request_gurl.query(), kUnescapeAll); | |
459 | |
460 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
461 http_response->set_code(HTTP_MOVED_PERMANENTLY); | |
462 http_response->AddCustomHeader("Location", dest); | |
463 http_response->set_content_type("text/html"); | |
464 http_response->set_content(base::StringPrintf( | |
465 "<html><head></head><body>Redirecting to %s</body></html>", | |
466 dest.c_str())); | |
467 return http_response.Pass(); | |
468 } | |
469 | |
470 scoped_ptr<HttpResponse> HandleCrossSiteRedirect(EmbeddedTestServer* server, | |
471 const HttpRequest& request) { | |
472 if (!ShouldHandle(request, "/cross-site")) | |
473 return nullptr; | |
474 | |
475 std::string destAll = net::UnescapeURLComponent( | |
476 request.relative_url.substr(std::string("/cross-site").size() + 1), | |
477 kUnescapeAll); | |
478 | |
479 std::string dest = base::StringPrintf( | |
480 "//%s:%hu/%s", destAll.substr(0, destAll.find("/")).c_str(), | |
481 server->port(), destAll.substr(destAll.find("/") + 1).c_str()); | |
482 | |
483 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
484 http_response->set_code(HTTP_MOVED_PERMANENTLY); | |
485 http_response->AddCustomHeader("Location", dest); | |
486 http_response->set_content_type("text/html"); | |
487 http_response->set_content(base::StringPrintf( | |
488 "<html><head></head><body>Redirecting to %s</body></html>", | |
489 dest.c_str())); | |
490 return http_response.Pass(); | |
491 } | |
492 | |
493 scoped_ptr<HttpResponse> HandleClientRedirect(const HttpRequest& request) { | |
494 GURL request_gurl = request.GetURL(); | |
495 std::string dest = | |
496 net::UnescapeURLComponent(request_gurl.query(), kUnescapeAll); | |
497 | |
498 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
499 http_response->set_code(HTTP_OK); | |
500 http_response->set_content_type("text/html"); | |
501 http_response->set_content(base::StringPrintf( | |
502 "<html><head><meta http-equiv=\"refresh\" content=\"0;url=%s\"></head>" | |
503 "<body>Redirecting to %s</body></html>", | |
504 dest.c_str(), dest.c_str())); | |
505 return http_response.Pass(); | |
506 } | |
507 | |
508 scoped_ptr<HttpResponse> HandleDefaultResponse(const HttpRequest& request) { | |
509 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse); | |
510 http_response->set_code(HTTP_OK); | |
511 http_response->set_content_type("text/html"); | |
512 http_response->set_content("Default response given for path: " + | |
513 request.relative_url); | |
514 return http_response.Pass(); | |
515 } | |
516 | |
517 class DelayedHttpResponse : public BasicHttpResponse { | |
518 public: | |
519 DelayedHttpResponse(double delay) : delay_(delay) {} | |
520 | |
521 void SendResponse(const SendBytesCallback& send, | |
522 const SendCompleteCallback& done) override { | |
523 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
524 FROM_HERE, base::Bind(send, ToResponseString(), done), | |
525 base::TimeDelta::FromSecondsD(delay_)); | |
526 } | |
527 | |
528 private: | |
529 double delay_; | |
530 }; | |
531 | |
532 scoped_ptr<HttpResponse> HandleSlowServer(const HttpRequest& request) { | |
533 double delay = 1.0f; | |
534 | |
535 GURL request_gurl = request.GetURL(); | |
536 if (request_gurl.has_query()) { | |
537 delay = std::atof(request_gurl.query().c_str()); | |
538 } | |
539 | |
540 scoped_ptr<BasicHttpResponse> http_response(new DelayedHttpResponse(delay)); | |
541 http_response->set_code(HTTP_OK); | |
542 http_response->set_content_type("text/plain"); | |
543 http_response->set_content(base::StringPrintf("waited %.1f seconds", delay)); | |
544 return http_response.Pass(); | |
545 } | |
546 } | |
Bence
2015/10/27 14:47:36
Add newline above this line. Add two spaces and /
svaldez
2015/10/27 15:00:50
Done.
| |
547 | |
548 void RegisterDefaultHandlers(EmbeddedTestServer* server) { | |
549 server->RegisterDefaultHandler(base::Bind(&HandleDefaultConnect)); | |
550 | |
551 server->RegisterDefaultHandler( | |
552 PREFIXED_HANDLER("/cachetime", &HandleCacheTime)); | |
553 server->RegisterDefaultHandler( | |
554 base::Bind(&HandleEchoHeader, "/echoheader", "no-cache")); | |
555 server->RegisterDefaultHandler( | |
556 base::Bind(&HandleEchoHeader, "/echoheadercache", "max-age=60000")); | |
557 server->RegisterDefaultHandler(PREFIXED_HANDLER("/echo", &HandleEcho)); | |
558 server->RegisterDefaultHandler( | |
559 PREFIXED_HANDLER("/echotitle", &HandleEchoTitle)); | |
560 server->RegisterDefaultHandler(PREFIXED_HANDLER("/echoall", &HandleEchoAll)); | |
561 server->RegisterDefaultHandler( | |
562 PREFIXED_HANDLER("/set-cookie", &HandleSetCookie)); | |
563 server->RegisterDefaultHandler( | |
564 PREFIXED_HANDLER("/set-many-cookies", &HandleSetManyCookies)); | |
565 server->RegisterDefaultHandler( | |
566 PREFIXED_HANDLER("/expect-and-set-cookie", &HandleExpectAndSetCookie)); | |
567 server->RegisterDefaultHandler( | |
568 PREFIXED_HANDLER("/set-header", &HandleSetHeader)); | |
569 server->RegisterDefaultHandler( | |
570 PREFIXED_HANDLER("/nocontent", &HandleNoContent)); | |
571 server->RegisterDefaultHandler( | |
572 PREFIXED_HANDLER("/close-socket", &HandleCloseSocket)); | |
573 server->RegisterDefaultHandler( | |
574 PREFIXED_HANDLER("/auth-basic", &HandleAuthBasic)); | |
575 server->RegisterDefaultHandler( | |
576 PREFIXED_HANDLER("/auth-digest", &HandleAuthDigest)); | |
577 server->RegisterDefaultHandler( | |
578 PREFIXED_HANDLER("/server-redirect", &HandleServerRedirect)); | |
579 server->RegisterDefaultHandler(base::Bind(&HandleCrossSiteRedirect, server)); | |
580 server->RegisterDefaultHandler( | |
581 PREFIXED_HANDLER("/client-redirect", &HandleClientRedirect)); | |
582 server->RegisterDefaultHandler( | |
583 PREFIXED_HANDLER("/defaultresponse", &HandleDefaultResponse)); | |
584 server->RegisterDefaultHandler(PREFIXED_HANDLER("/slow", &HandleSlowServer)); | |
585 | |
586 // TODO(svaldez): HandleDownload | |
587 // TODO(svaldez): HandleDownloadFinish | |
588 // TODO(svaldez): HandleZipFile | |
589 // TODO(svaldez): HandleRangeReset | |
590 // TODO(svaldez): HandleSSLManySmallRecords | |
591 // TODO(svaldez): HandleChunkedServer | |
592 // TODO(svaldez): HandleGetSSLSessionCache | |
593 // TODO(svaldez): HandleGetChannelID | |
594 // TODO(svaldez): HandleGetClientCert | |
595 // TODO(svaldez): HandleClientCipherList | |
596 // TODO(svaldez): HandleEchoMultipartPost | |
597 } | |
598 | |
599 } // namespace test_server | |
600 } // namespace net | |
OLD | NEW |