OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/test/webdriver/dispatch.h" | 5 #include "chrome/test/webdriver/dispatch.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 void Shutdown(struct mg_connection* connection, | 53 void Shutdown(struct mg_connection* connection, |
54 const struct mg_request_info* request_info, | 54 const struct mg_request_info* request_info, |
55 void* user_data) { | 55 void* user_data) { |
56 base::WaitableEvent* shutdown_event = | 56 base::WaitableEvent* shutdown_event = |
57 reinterpret_cast<base::WaitableEvent*>(user_data); | 57 reinterpret_cast<base::WaitableEvent*>(user_data); |
58 mg_printf(connection, "HTTP/1.1 200 OK\r\n\r\n"); | 58 mg_printf(connection, "HTTP/1.1 200 OK\r\n\r\n"); |
59 shutdown_event->Signal(); | 59 shutdown_event->Signal(); |
60 } | 60 } |
61 | 61 |
| 62 void SendNoContentResponse(struct mg_connection* connection, |
| 63 const struct mg_request_info* request_info, |
| 64 void* user_data) { |
| 65 std::string response = "HTTP/1.1 204 No Content\r\n" |
| 66 "Content-Length:0\r\n" |
| 67 "\r\n"; |
| 68 mg_write(connection, response.data(), response.length()); |
| 69 } |
| 70 |
62 void SendNotImplementedError(struct mg_connection* connection, | 71 void SendNotImplementedError(struct mg_connection* connection, |
63 const struct mg_request_info* request_info, | 72 const struct mg_request_info* request_info, |
64 void* user_data) { | 73 void* user_data) { |
65 // Send a well-formed WebDriver JSON error response to ensure clients | 74 // Send a well-formed WebDriver JSON error response to ensure clients |
66 // handle it correctly. | 75 // handle it correctly. |
67 std::string body = base::StringPrintf( | 76 std::string body = base::StringPrintf( |
68 "{\"status\":%d,\"value\":{\"message\":" | 77 "{\"status\":%d,\"value\":{\"message\":" |
69 "\"Command has not been implemented yet: %s %s\"}}", | 78 "\"Command has not been implemented yet: %s %s\"}}", |
70 kUnknownCommand, request_info->request_method, request_info->uri); | 79 kUnknownCommand, request_info->request_method, request_info->uri); |
71 | 80 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 response->SetValue(methods); | 247 response->SetValue(methods); |
239 return; | 248 return; |
240 } | 249 } |
241 | 250 |
242 DispatchCommand(command.get(), method, response); | 251 DispatchCommand(command.get(), method, response); |
243 } | 252 } |
244 | 253 |
245 } // namespace internal | 254 } // namespace internal |
246 | 255 |
247 Dispatcher::Dispatcher(struct mg_context* context, const std::string& root) | 256 Dispatcher::Dispatcher(struct mg_context* context, const std::string& root) |
248 : context_(context), root_(root) {} | 257 : context_(context), root_(root) { |
| 258 // Overwrite mongoose's default handler for /favicon.ico to always return a |
| 259 // 204 response so we don't spam the logs with 404s. |
| 260 mg_set_uri_callback(context_, "/favicon.ico", &SendNoContentResponse, NULL); |
| 261 } |
249 | 262 |
250 Dispatcher::~Dispatcher() {} | 263 Dispatcher::~Dispatcher() {} |
251 | 264 |
252 void Dispatcher::AddShutdown(const std::string& pattern, | 265 void Dispatcher::AddShutdown(const std::string& pattern, |
253 base::WaitableEvent* shutdown_event) { | 266 base::WaitableEvent* shutdown_event) { |
254 mg_set_uri_callback(context_, (root_ + pattern).c_str(), &Shutdown, | 267 mg_set_uri_callback(context_, (root_ + pattern).c_str(), &Shutdown, |
255 shutdown_event); | 268 shutdown_event); |
256 } | 269 } |
257 | 270 |
258 void Dispatcher::SetNotImplemented(const std::string& pattern) { | 271 void Dispatcher::SetNotImplemented(const std::string& pattern) { |
259 mg_set_uri_callback(context_, (root_ + pattern).c_str(), | 272 mg_set_uri_callback(context_, (root_ + pattern).c_str(), |
260 &SendNotImplementedError, NULL); | 273 &SendNotImplementedError, NULL); |
261 } | 274 } |
262 | 275 |
263 } // namespace webdriver | 276 } // namespace webdriver |
OLD | NEW |