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