Chromium Code Reviews| Index: chrome/test/webdriver/dispatch.cc |
| diff --git a/chrome/test/webdriver/dispatch.cc b/chrome/test/webdriver/dispatch.cc |
| index f1bfb77720770121e6e970108ce5f51897ac3eec..65f3a7a01cf1781c8c4bd82c4938c30f3cdbb05d 100644 |
| --- a/chrome/test/webdriver/dispatch.cc |
| +++ b/chrome/test/webdriver/dispatch.cc |
| @@ -9,7 +9,9 @@ |
| #include <vector> |
| #include "base/format_macros.h" |
| +#include "base/json/json_reader.h" |
| #include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| #include "base/message_loop_proxy.h" |
| #include "base/string_split.h" |
| #include "base/string_util.h" |
| @@ -20,6 +22,7 @@ |
| #include "chrome/test/webdriver/commands/command.h" |
| #include "chrome/test/webdriver/session_manager.h" |
| #include "chrome/test/webdriver/utility_functions.h" |
| +#include "chrome/test/webdriver/webdriver_logging.h" |
|
Huyen
2011/06/08 19:55:52
Oh, did you forget to add webdriver_logging to thi
|
| namespace webdriver { |
| @@ -59,13 +62,33 @@ void Shutdown(struct mg_connection* connection, |
| shutdown_event->Signal(); |
| } |
| -void SendStatus(struct mg_connection* connection, |
| +void SendOkWithBody(struct mg_connection* connection, |
| + const std::string& content) { |
|
Huyen
2011/06/08 19:17:54
line up indentation of parameters.
kkania
2011/06/08 21:10:49
Done.
|
| + const char* response_fmt = "HTTP/1.1 200 OK\r\n" |
| + "Content-Length:%d\r\n\r\n" |
| + "%s"; |
| + std::string response = base::StringPrintf( |
| + response_fmt, content.length(), content.c_str()); |
| + mg_write(connection, response.data(), response.length()); |
| +} |
| + |
| +void SendHealthz(struct mg_connection* connection, |
| const struct mg_request_info* request_info, |
|
Huyen
2011/06/08 19:17:54
line up indentation of parameters.
kkania
2011/06/08 21:10:49
Done.
|
| void* user_data) { |
| - std::string response = "HTTP/1.1 200 OK\r\n" |
| - "Content-Length:2\r\n\r\n" |
| - "ok"; |
| - mg_write(connection, response.data(), response.length()); |
| + SendOkWithBody(connection, "ok"); |
| +} |
| + |
| +void SendLog(struct mg_connection* connection, |
| + const struct mg_request_info* request_info, |
|
Huyen
2011/06/08 19:17:54
line up indentation of parameters.
kkania
2011/06/08 21:10:49
Done.
|
| + void* user_data) { |
| + std::string content, log; |
| + if (GetLogContents(&log)) { |
|
Huyen
2011/06/08 19:17:54
Does GetLogContents() get all the previous logs? I
kkania
2011/06/08 21:10:49
If I send a message over ~32MB, it fails quickly.
|
| + // KIWI Another \n before END? |
|
Huyen
2011/06/08 19:17:54
Remove KIWI?
kkania
2011/06/08 21:10:49
Done.
|
| + content = "START ChromeDriver log:\n" + log + "END ChromeDriver log"; |
| + } else { |
| + content = "No ChromeDriver log found"; |
| + } |
| + SendOkWithBody(connection, content); |
| } |
| void SendNoContentResponse(struct mg_connection* connection, |
| @@ -225,18 +248,24 @@ bool ParseRequestInfo(const struct mg_request_info* const request_info, |
| base::SplitString(uri, '/', path_segments); |
| if (*method == "POST" && request_info->post_data_len > 0) { |
| - VLOG(1) << "...parsing request body"; |
| std::string json(request_info->post_data, request_info->post_data_len); |
| - std::string error; |
| - if (!ParseJSONDictionary(json, parameters, &error)) { |
| + std::string error_msg; |
| + scoped_ptr<Value> params(base::JSONReader::ReadAndReturnError( |
| + json, true, NULL, &error_msg)); |
| + if (!params.get()) { |
| + response->SetError(new Error( |
| + kBadRequest, |
| + "Failed to parse command data: " + error_msg + "\n Data: " + json)); |
| + return false; |
| + } |
| + if (!params->IsType(Value::TYPE_DICTIONARY)) { |
| response->SetError(new Error( |
| kBadRequest, |
| - "Failed to parse command data: " + error + "\n Data: " + json)); |
| + "Data passed in URL must be a dictionary. Data: " + json)); |
| return false; |
| } |
| + *parameters = static_cast<DictionaryValue*>(params.release()); |
| } |
| - VLOG(1) << "Parsed " << method << " " << uri |
| - << std::string(request_info->post_data, request_info->post_data_len); |
| return true; |
| } |
| @@ -283,8 +312,12 @@ void Dispatcher::AddShutdown(const std::string& pattern, |
| shutdown_event); |
| } |
| -void Dispatcher::AddStatus(const std::string& pattern) { |
| - mg_set_uri_callback(context_, (root_ + pattern).c_str(), &SendStatus, NULL); |
| +void Dispatcher::AddHealthz(const std::string& pattern) { |
| + mg_set_uri_callback(context_, (root_ + pattern).c_str(), &SendHealthz, NULL); |
| +} |
| + |
| +void Dispatcher::AddLog(const std::string& pattern) { |
| + mg_set_uri_callback(context_, (root_ + pattern).c_str(), &SendLog, NULL); |
| } |
| void Dispatcher::SetNotImplemented(const std::string& pattern) { |